Hub

Sorting Race

    Lanes
    Starting order

    How to play

    1. Pick 2 to 4 sorts for the lanes. They all get the same bars.
    2. Press Race!. Every lane makes the same number of moves per second.
    3. Turn the sound on and listen: you can hear each one work.
    Do thisPhoneKeyboard
    Race / PauseRace! buttonR
    New barsNew barsN
    Sound on / offSound buttonM
    Number of lanes2 / 3 / 42 3 4
    Sorts, order, bars, speedMenus, buttons, slidersTab to them

    What's happening?

    • A computer sorts by comparing two things and maybe swapping them. That's all it can do.
    • Bubble, insertion and selection sort compare almost every pair. Double the bars and they get about 4 times slower.
    • Merge, quick and heap sort split the job up. Double the bars and they get only a bit over 2 times slower.
    • The start matters: insertion sort flies through nearly sorted bars, but crawls on reversed ones.
    • The sound's pitch follows the height of the bar being looked at.

    Try this: race bubble against merge with 20 bars, then with 120. How much bigger does the gap get? Then try insertion sort on "Nearly sorted".