Static vs Dynamic Arrays

Understanding how arrays are stored in memory and how they resize.

1. Contiguous Memory Allocation

Unlike other data structures, arrays are stored in a single, unbroken block of memory. This is why we can access any element in O(1) time using its physical address index.

Physical Memory Tape

RAM: 128 Bytes

Status

System Ready

Array Inspector

Mode
Base Pointer0x100
Size / Capacity0 / 4
Computer Science Tip

Static arrays are immutable in length. This allows for extremely fast access but requires you to know your max size upfront.

2. Performance & Operations

Interact with high-level array operations below. Notice the difference in "cost" between end operations (Push/Pop) and beginning operations (Shift/Unshift).

Interactive Simulation

Modifiers

Operations

Linear Search: O(n) average/worst case.

10
[0]
20
[1]
30
[2]
40
[3]
[4]
[5]
[6]
[7]
Internal Capacity4 / 8

Dynamic arrays often double capacity when full to maintain amortized O(1) insertions.

Detailed explanation about Static vs Dynamic Arrays.