Insertion Sort
Take the next value and slide it left past larger values into the sorted prefix.
Decision · step 3 of 27Insertion Sort: Seven values
5 is larger than 1, so 1 slides left.
What you will see
The sorted prefix grows from the left; the new value shifts left one slot at a time until it fits.
Cost
| Best | O(n) |
|---|---|
| Average | O(n^2) |
| Worst | O(n^2) |
| Space | O(1) |
Fast on nearly sorted input; the standard choice for tiny arrays.
Properties
- ✓ comparison based
- ✓ stable
- ✓ in place
- ✓ adaptive
- ✓ online
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, compare two runs.
Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.
Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.