mljr.eu
Back

Sorting Visualizer

Pick an algorithm, shuffle the bars, and press Start — every comparison and swap is drawn as it happens.

How it works

All five algorithms here are written as generator functions that pause after every single comparison or swap — that pause is exactly what turns into one animation frame, so the visualization isn't a separate approximation of the algorithm, it's the actual algorithm running one step at a time.

Bubble, selection, and insertion sort all compare adjacent or nearby elements over and over — O(n²) work that shows up visually as a lot of small local flickering. Merge sort splits the array in half recursively, sorts each half, then merges them back together — the comparisons jump around between two separate sorted runs instead of crawling along the array. Quick sort picks a pivot and partitions everything else around it in place, so the pivot's final resting point is visible the moment the partition step finishes.

The comparison and swap counters below the bars make the O(n²) vs O(n log n) difference concrete instead of theoretical — run bubble sort and quick sort back to back on the same bar count and the counters alone tell most of the story.

highlighted pair: currently being compared or swapped