Playground / Insertion Sort

Insert each card into place

Insertion Sort

Interactive lab

Try it: Insertion Sort

How insertion sort grows a sorted prefix by taking the next value and shifting larger ones right until it fits.

How it works

  1. The first value alone is a sorted prefix.
  2. Take the next value and compare it with the prefix from right to left.
  3. Shift every larger value one place right, then drop the value into the gap.
  4. Few steps on nearly sorted input; stable.

Default run (28 steps): Insertion sort, ascending: [8, 3, 5, 1, 9, 2]. … Sorted ascending: [1, 2, 3, 5, 8, 9] — 12 comparisons, 9 shifts.

Simplified: Up to 12 numbers from 0 to 99. The comparison table runs all five algorithms on the same input. Python's own sort() uses Timsort.

Educational simulation

Loading the simulation…