The visualiser above animates ten sorting algorithms on an array of bars, where each bar's height is its value. Sorting means rearranging those bars from shortest to tallest, and the point of watching is to see how each algorithm gets there — because they all reach the same result by strikingly different routes.
If you have never used it before, this order works best:
The Compare All button opens the full complexity table for all ten algorithms side by side, and the sound toggle maps each value to a pitch — which makes the difference between a gradually-ordering hum and Quick Sort's sudden sweeps surprisingly easy to hear.
Every bar is colour-coded by what the algorithm is doing to it at that instant. Learning these five colours is most of what you need to read any of the animations:
Three counters run along the top of the visualiser, and they are not equally meaningful.
How many times the algorithm has asked "is this value bigger than that one?". This is the headline measure of work for comparison-based sorting, and it is what Big-O notation is counting. An O(n²) algorithm on 50 elements makes roughly 1,250 comparisons; an O(n log n) algorithm makes roughly 280. Run both and watch the counters diverge.
How many times two values have actually been exchanged — in other words, how many writes the algorithm performed. This matters separately from comparisons, because on real hardware writes can be far more expensive than reads. Selection Sort is the clearest illustration: it makes as many comparisons as Bubble Sort but only about n swaps, which is exactly why it is preferred when writing is the costly operation.
Wall-clock milliseconds since you pressed Sort — and the one number you should not use to judge an algorithm. It includes all the artificial animation delay that makes the visualisation watchable, so it mostly measures your speed slider. If you want to compare two algorithms fairly, shuffle once and compare their comparison and swap counts on the same array. Those counts are exact and delay-free.
Time and space complexity for every algorithm in the visualiser. Stable means equal elements keep their original relative order — which matters whenever you sort the same data by one field after another.
| Algorithm | Best | Average | Worst | Space | Stable | Method |
|---|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Yes | Exchanging |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) | No | Selection |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Yes | Insertion |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes | Merging |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) | No | Partitioning |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | No | Selection |
| Shell Sort | O(n log n) | gap-dependent | O(n²) | O(1) | No | Insertion |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(k) | Yes | Counting |
| Radix Sort | O(nk) | O(nk) | O(nk) | O(n + k) | Yes | Digit buckets |
| Tim Sort | O(n) | O(n log n) | O(n log n) | O(n) | Yes | Insertion + merging |
Two honest caveats. Bubble Sort only achieves its O(n) best case because this implementation includes the early-exit check that stops once a full pass makes no swaps — the naive version is O(n²) even on sorted input. And Shell Sort has no single agreed average complexity: it depends entirely on the gap sequence used, so the table reports it as gap-dependent rather than inventing a precise-looking figure. Full derivations are in the documentation.
Working through the algorithms in this sequence means each one builds on the last rather than arriving out of nowhere:
Each algorithm has a written walkthrough with code on the blog, and the docs cover them in reference form.