Array Insert
Make room by shifting everything after the slot one place right, then write.
Result · step 2 of 6Array: Insert 7 at index 2
Move 8 from index 4 to index 5.
What you will see
Cells slide right one at a time, opening a gap; the new value drops in.
Cost
| Best | O(1) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
Best case is insertion at the end.
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Each cell is announced as index, value and state; each step's accessibility text states the decision and its effect.
Reduced motion: Swaps and shifts become value crossfades with an outline flash; pointers appear at their destination.
Before this
Related
Taught by the same lesson
Array covers these too, in the same run.