Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Iaroslav L
Python array from array module is not static

Iaroslav L

Oct 22, 2024

In the Array introduction section we have the following piece of code, saying that staticArray has fixed size:

from array import array # Static Array (Using the array module for strictly typed arrays; # however, lists are more commonly used and can be considered dynamic.) staticArray = array('i', [0]*5) # Array of integers with a fixed size of 5 staticArray[0] = 1

That's actually not true. Because it's still possible to append an item there:

staticArray.append(10) print(staticArray) # output: array('i', [1, 0, 0, 0, 0, 10])

0

0

Comments
Comments
Muhammad Alfian Rasyidin
Muhammad Alfian Rasyidin9 months ago

It seems to be a natural behavior of arrays in specific programming languages.

I believe, if we are careful to avoid appending to the variable that we want to treat as static, it could result in better performance since the array wouldn’t need to be resized.

On this page

What Is an Array?

Key Points

Why Do We Need Arrays?

Memory Representation of an Array

How Arrays Are Stored in Memory

Memory Layout Example

Static vs. Dynamic Arrays

  1. Static Arrays
  1. Dynamic Arrays
  1. Static Vs. Dynamic Arrays Comparision

Which One Should You Use?

Basic Concepts and Operations in Arrays

  1. Accessing Elements
  1. Inserting Elements
  1. Deleting Elements
  1. Searching for an Element
  1. Updating an Element

Key Considerations for Arrays in Coding Interviews

  1. Validate Assumptions
  1. Handle Boundaries
  1. Efficiency Considerations
  1. Loops & Naming
  1. Algorithm Choice
  1. Testing & Edge Cases
  1. Handling Special Values
  1. Modifying While Iterating
  1. Array Methods