Array
Contiguous storage with constant-time indexed access
Positions are addresses
An array stores same-shaped elements next to one another. Because every element has the same size, index i can be converted directly into an address. Reading or replacing an element therefore takes O(1) time, no matter how long the array is.
Contiguity makes insertion and deletion more expensive. Inserting in the middle shifts the suffix one position right; deleting shifts it left to close the gap. Select an index below, then compare access, insertion, deletion, and appending.
Select a cell by index, then use an operation above.
Dynamic arrays trade rare copies for fast appends
Languages usually expose a resizable array. When its backing storage is full, it allocates a larger block, copies the existing values, and appends into the new space. One growth costs O(n), but doubling capacity makes growth progressively rarer.
Length 3 / capacity 4
append 0 times · total copies 0 · amortized 0.0 operations/append (about O(1))
What happens when capacity is full? Keep pressing append.
Across a long sequence of appends, each old value is copied only a small number of times. Charging those occasional copies to all successful appends gives an amortized cost of O(1) per append.
Next, compare this contiguous layout with a linked list, where nodes can move independently but indexed access is no longer constant time.