Skip to content
BENIBIX Learn

Dynamic Array

Development🧮 Algorithms & Data StructuresData Structures

Also known as Resizable Array, Growable Array, ArrayList, Vector (C++)

An array that grows. When it is full, it moves to a bigger block.

Think of it like

It is like a family moving to a bigger house when the old one fills up. They pack, move, and have space to spare.

Example

Lucy appends 10,000 scores to a Python list. Now and then the list moves to a bigger block, but each append still feels instant.

Why it matters

It gives you fast reading by position and room to grow. That is why it is the default list in most languages.

Definition

A dynamic array is an array that grows when it runs out of room. Its items sit side by side in memory, so reading any one is fast. When it is full, it makes a bigger block and copies each item over. The copy is slow, but it does not happen often, so adding is fast on average. Python lists, Java's ArrayList and C++ vectors work this way.

Example code

python
scores = []
for s in [90, 75, 88]:
    scores.append(s)
print(scores[1])
# 75
append() grows the list. Reading by position stays fast.
Full at 4 slots, the array moves to 8 and keeps going.

Common mistake

Adding to the front of a big one. Every item has to shift over, which is slow.

Key takeaways

  1. 1
    Side by side. Fast to read any position.
  2. 2
    Grows by copying. Moves to a bigger block when full.
  3. 3
    Fast on average. The copy happens rarely.