BEGINNER · 10 MIN · FREE LESSON
Arrays & dynamic arrays
Explore arrays & dynamic arrays through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore arrays & dynamic arrays through a visual, step-by-step model.
Loading interactive lesson…
The dynamic array starts with one empty slot.
Doubling capacity copies old values only at geometric thresholds. The total copying across n appends is less than 2n.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
A shelf gains a larger replacement whenever all its slots are occupied.
Space to grow, one doubling at a time. Track the pointer, capacity or index variables as each operation executes.
Predict the next comparison, end operation or capacity decision. Inputs and full/empty cases are validated before a trace begins.
One append can copy n values, but geometric resizing makes the total copying across n appends linear, giving O(1) amortized append. Visualization snapshots are separate from the data structure’s logical operation costs.
Select one of four complete reference snippets. Their data representation may differ by language, but each preserves the stated invariant.
Use dynamic arrays for indexed access and append-heavy sequences. Index lookup is O(1); inserting in the middle still shifts values.
Amortized O(1) is not a worst-case guarantee for each append. Spare allocated slots are not logical elements.
Test the operation invariant and complexity below; then load a boundary case and explain each counter change.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.