{ } LinearCore interactive
Array
Contiguous memory, O(1) random access.
array
length 5
[0]
[1]
[2]
[3]
[4]
Arrays give O(1) access by index — the address is pure math.
at
tap a cell to access · ✕ to deleteHow it works
An array stores elements in one continuous block of memory. Because every slot is the same size, the address of any index is pure arithmetic — base + i × size — giving constant-time access. The trade-off: inserting or deleting in the middle shifts everything after it.
Mental models
- Index access is math, not a search — base address plus offset.
- Cache-friendly: contiguous layout means the CPU prefetches neighbors.
- Dynamic arrays double capacity on overflow → amortized O(1) appends.
Common pitfalls
- Inserting at the front is O(n) — every element shifts right.
- Resizing copies the whole array; a single append can briefly be O(n).
Complexity
- Access
- O(1)
- Search
- O(n)
- Insert (end)
- O(1)*amortized for dynamic arrays
- Insert (middle)
- O(n)shifts elements
- Delete
- O(n)
- Space
- O(n)
Reach for it when
- You know the size up front or it grows mostly at the end.
- You need fast index lookups and tight memory locality.