Six bars. Sort them.
How are you feeling?
What "fast" really means for a sorter
- Predict. How many comparisons will this sorter make? Or which sorter is fastest here?
- Run. The bars move and a counter ticks up once for every comparison.
- Reveal. The real counts appear — you see for yourself which sorter won, and why.
- Race them. Run the same sorter on a tidy, a reversed, and a random list, and watch the count change.
Meet the crew — the five sorters
Bubbly runs Bubble sort — compares each pair of neighbours and swaps the ones out of order, bubbling the biggest to the end. Fast when the list is nearly tidy; slow when it is a mess.
Inserta runs Insertion sort — builds the sorted list one item at a time, slipping each new item into its place. Great on almost-sorted lists.
Scanna runs Selection sort — scans the whole rest of the list every time to pick the smallest. She never notices the list is already sorted — she always does the same amount of work.
Quicka runs Quick sort — picks a pivot and splits the list into "smaller" and "bigger", then repeats on each half. Usually quick — hence the name.
Merga runs Merge sort — keeps splitting the list in half until each piece is one item, then merges the pieces back in order. Stays fast even on big, messy lists.
😄 Brain break
Where this idea comes from
Bubble sort
Sorting by machine is older than computers. In 1890 Herman Hollerith’s punched-card machines counted the United States census: each person was a card, and as a card was read, a lid opened on a sorting box to show which pile it belonged in. That was a different kind of sorting — dropping cards into piles, not swapping neighbours.
One thing to hold: Six cards with numbers on them, laid in a row. Swap any two neighbours that are the wrong way round, walk the row again, and count every pair you check.
Why it matters: In 1956 Edward Friend wrote about sorting by swapping neighbours. By the 1960s it was called bubble sort, because big values rise to the end like bubbles. Donald Knuth, in the 1998 edition of his great book on sorting, wrote that it “seems to have nothing to recommend it, except a catchy name and the fact that it leads to some interesting theoretical problems.”
What we don’t know: Nobody is sure who first called it bubble sort. Kenneth Iverson used the name in 1962, but in 1963 the Algorithms section of the journal Communications of the ACM printed the same idea as “Shuttle Sort”. People still argue about whether it should be taught at all.
Dates:
- 1890 Hollerith’s machines count and sort the US census cards.
- 1956 Friend writes about sorting by exchanging neighbours.
- 1962 The name bubble sort is in print.
- 1981 Sorting Out Sorting races sorting methods on film.
- 1998 Knuth’s verdict: nothing to recommend it but a catchy name.
What next? Pick a door
- More like this TokenTales What word will the model say next? EventForge When this happens, what should the app do? PingForge Where does your data travel?
- A bit harder PairForge What will this program print? BehaviorForge Which search explores the fewest cells? VoxelEngine How is this voxel world built?
- Something different TrailForge What comes first in a survival plan? TerraVoyage Which continent do the clues point to? ChoirQuest Which part fits your voice today?