Sorting Race

The same row of bars is sorted five different ways at once. Count the comparisons and moves to see which method is fastest.

  • Bubble Cmp 0 ・ Swaps 0
  • Insertion Cmp 0 ・ Swaps 0
  • Selection Cmp 0 ・ Swaps 0
  • Quick Cmp 0 ・ Swaps 0
  • Merge Cmp 0 ・ Writes 0

Step 0

A simplified teaching model: 16 bars, each comparison or move counted once.

How to play

Pick a starting order with the buttons above, then press "Start". All five methods run at the same speed, and each comparison or swap is one step. "Step once" lets you go at your own pace. Methods are ranked in the order they finish. Try "Nearly sorted" and "Reversed" and watch the ranking change.

Learn more

Bubble compares neighbours and swaps them. Insertion slides each bar into its place. Selection carries the smallest remaining bar to the front. Quick splits the bars around a pivot bar, smaller ones on the left. Merge sorts halves and then combines them. For nearly sorted bars, insertion is fast; for reversed bars, bubble and insertion struggle while quick and merge do well. Merge counts "writes" instead of swaps. The counts here are for 16 bars; real programs with long lists show far bigger gaps. A simplified teaching model.