AlgoScope

Shell Sort

AlgorithmintermediateSorting

Insertion sort with gaps n/2, n/4, ..., 1, so far-apart values move in big strides first.

Decision · step 2 of 29More Sorts: Shell sort with gaps 4, 2, 1
16051422832344515697ij23 > 16

Gap 4: compare index 0 (23) with index 4 (16), 4 apart. 23 > 16, so swap them and keep stepping back by 4.

Open in the player →or start at step 2

What you will see

Elements a gap apart swap into order; the gap halves each round until it is plain insertion sort.

How more sorts works →

Cost

BestO(n log n)
Averagedepends on gap sequence
WorstO(n^2)
SpaceO(1)

Worst case O(n^(3/2)) with Knuth gaps; exact average unknown for most sequences.

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.

Before this

Taught by the same lesson

More Sorts covers these too, in the same run.