Labs / Computer Science
Sorting Algorithms
Forty bars, four classic ways to sort them. The highlighted pair is the one move the algorithm is making right now — press Play to let it run, or tap the canvas to step through by hand. Every algorithm gets the same shuffled deck until you reshuffle, so the compare and swap counters are a fair race.
compares 0swaps 0
What to try
- Run Bubble to the end and note the counters. Now run Quick on the same deck. How big is the gap?
- Step through Insertion by hand for ten moves. Can you predict each next move before it happens?
- Selection makes very few swaps but never fewer comparisons. Watch it — why is that?
- Shuffle until you get a deck that is almost sorted already. Which algorithm benefits the most?