Big-O Racing
Six sorting algorithms get the same shuffled list and the same budget of operations per frame. Every comparison or write costs one step, so the race order is the cost order. Try sorted input and watch Quick Sort fall apart.
Press Start race. Each lane shows its own copy of the list being sorted.
How the gap grows
Total steps for each algorithm as the list doubles from 8 to 1,024 items, on the input type chosen above. Both axes are logarithmic, so a steeper line means faster growth.
Guess the cost
Now spot it in real code. How does the work grow as the list gets longer? Pick one, then race the code to check.
Red: this code, measured. Dashed: the four classes. Each line shows growth since n = 8.
| n | steps | vs. half |
|---|
Drag the list size
Same n for every class. Bars are drawn to scale, so the small ones vanish as n grows. That vanishing is the point.
Count the steps, line by line
How many times does each line run? Add the lines up, keep the fastest-growing term, and drop the constants. Counts below are at n = 100; change n with the slider above.
| # | Line | Runs | At this n |
|---|---|---|---|