AlgoScope

Insertion Sort

AlgorithmbeginnerSorting

Take the next value and slide it left past larger values into the sorted prefix.

Decision · step 3 of 27Insertion Sort: Seven values
sorted 0-0105✓14223843576ji5 > 1

5 is larger than 1, so 1 slides left.

Open in the player →or start at step 3

What you will see

The sorted prefix grows from the left; the new value shifts left one slot at a time until it fits.

How insertion sort works →

Cost

BestO(n)
AverageO(n^2)
WorstO(n^2)
SpaceO(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.

Leads to

Topics that need this one first.

Taught by the same lesson

Insertion Sort covers these too, in the same run.