Mathematics · Study 052
Sort Race
Bubble, insertion, Shell and quicksort race to order the same 64 shuffled bars. Watch how differently each algorithm moves data.
What you're looking at
All four panels start from an identical shuffle and perform two swaps per frame, so the race is fair in terms of work done. Bubble sort drags large values to the right one step at a time. Insertion sort grows a sorted region from the left. Shell sort makes long jumps first, then tidies. Quicksort splits the list around a pivot and recurses.
The idea behind it
The swap counter tells the story. The two simple methods need on the order of n squared operations, about a thousand swaps for 64 items. Quicksort and Shell sort finish in a small fraction of that. The gap widens fast: at a million items it is the difference between seconds and days.
Try this
Watch the counters. Restart deals a new shuffle to all four at once.