The simplest data structure: a contiguous block of memory with instant access to any element by index.
An array stores elements side-by-side in memory, so reading or writing any position by index is O(1). The tradeoff: inserting or deleting in the middle means shifting everything after it (O(n)), and a fixed-size array can't grow. Dynamic arrays (JavaScript arrays, Python lists, C++ vectors) solve growth by doubling capacity when full, which keeps appends O(1) on average.
Step through arrays live, one move at a time β this becomes a fully interactive visualizer.
Coming sooni maps directly to address base + i Γ elementSize.i shifts every later element β O(n) in the worst case.// A dynamic array doubles capacity when full.
// 8 appends into capacity-1 array: copies happen
// at sizes 1, 2, 4 (total 7 copies) β about one
// copy per element, so O(1) amortized per append.
const arr = [];
for (let i = 0; i < 8; i++) {
arr.push(i); // occasionally triggers a resize+copy
}A plain array has fixed size chosen at creation. A dynamic array wraps one and grows it automatically by allocating a larger block and copying β that's what JavaScript arrays, Python lists, and C++ vectors are.
Copies happen at sizes 1, 2, 4, 8, β¦ β the total work of all copies is less than 2n for n appends, so the average cost per append is constant even though individual appends occasionally cost O(n).
When you insert or delete frequently in the middle (consider a linked list or balanced tree), or when you need fast lookup by key rather than position (consider a hash table).
Share what clicked for you and see notes from other learners on this topic.
Coming soon