December 2, 2026

Visual Math: Sorting on a Color Wheel

Sorting algorithms title card: Quick sort on a color wheel beside a screenshot of the interactive app

A sorted color wheel is a rainbow, so any mistake shows at once. The free Sorting on a Circle app places 16 to 256 bars around a ring, each colored and sized by its value, then runs bubble, insertion, quick or heap sort while counters track comparisons and swaps.

Open the app in its own tab, or use its Full screen button.

Four algorithms, one ring

Bubble and insertion sort move values a step at a time, so the ring changes everywhere at once and slowly. Quick sort picks a pivot, splits the ring around it and works on each piece separately, so finished arcs of the rainbow appear in a jump. Heap sort builds a heap first and then peels off the largest values one at a time.

Sorting app at the start: 96 shuffled colored bars of random lengths arranged in a circle around a dark center
Ninety-six shuffled values before a sort starts.

Where quick sort comes from

MathWorld credits C. A. R. Hoare with inventing quicksort, with publications in 1961 and 1962. With a random pivot the expected number of comparisons is about 2(n+1)Hₙ − 4n, where Hₙ is the nth harmonic number, which grows roughly like 2n ln n. The worst case is n² comparisons, reached when every split is lopsided; the page notes that an already sorted list does this if the first or last element is always the pivot.

The app avoids that trap by swapping the middle element into the pivot slot before partitioning, so a sorted ring does not trigger the worst case.

Sorting app mid-run with quick sort: part of the circle is already a smooth color gradient and part is still shuffled
Quick sort part way through: sorted arcs next to unsorted ones.

Watching the counts

Running the same shuffle through different algorithms makes the cost difference concrete. In the companion reel, quick sort puts a 72-bar ring in order with 245 swaps, a figure counted directly from the reel’s script. The app reports comparisons as well as swaps, and the gap between bubble sort and quick sort widens quickly as the item slider goes up.

Sorting app mid-run with bubble sort: a white highlight on two bars and counters showing comparisons and swaps
Bubble sort part way through, with live counters.

The sound option plays a short tone for each step, higher for larger values. The logistic map post covers a different case where tiny differences in a start change everything that follows.

Sources

Swap counts are from the reel script (seed 7, 72 items); the middle-pivot choice is from the app code.

517 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *