SimulatorEducationDeveloperEntertainment

Sorting Algorithm Visualizer

Watch eight classic sorting algorithms race in your browser. Compare bubble, selection, insertion, shell, quick, merge, heap and radix sort step by step, with live comparison and swap counters.

Algorithm

Quick: average O(n log n)

Array size80
Ops / frame40
Comparisons 0Swaps 0Writes 0

How the eight algorithms compare

AlgorithmAverageWorstSpaceStable?
BubbleO(n²)O(n²)O(1)Yes
SelectionO(n²)O(n²)O(1)No
InsertionO(n²)O(n²)O(1)Yes
ShellO(n^1.3)O(n²)O(1)No
QuickO(n log n)O(n²)O(log n)No
MergeO(n log n)O(n log n)O(n)Yes
HeapO(n log n)O(n log n)O(1)No
Radix LSDO(nk)O(nk)O(n+k)Yes

What the colours mean

  • Slate: idle bar, waiting to be touched.
  • Amber: being compared right now.
  • Magenta: just written / swapped.
  • Blue: current pivot (Quicksort).
  • Green: in its final sorted position.

Why the visual differences matter

The O() notation collapses a sorting algorithm into one symbol, but the animation reveals what is actually happening: bubble sort makes huge numbers of adjacent swaps, selection sort makes very few swaps but many comparisons, merge sort never swaps in place at all and writes a fresh copy of every element.

Try the same array size with bubble vs. quick — the comparison counters tell the story numerically, and the colour pattern tells it visually. Radix sort doesn't compare at all; it routes elements into buckets one digit at a time, which is why it can beat O(n log n) on integer keys.

When to use what

  • Tiny arrays (n < 32): insertion sort wins; constant factors crush asymptotic giants. Most production sorts use it for small partitions.
  • General-purpose: quicksort with a good pivot (median-of-three) for most data; std library defaults usually use a hybrid called Timsort or Introsort.
  • Guaranteed worst-case: heap or merge sort — quick can degrade to O(n²) on adversarial input.
  • Stable order required: merge or Timsort; preserves the relative order of equal keys.
  • Integer keys, bounded range: radix sort beats comparison-based methods.