This page animates five classic comparison-based sorts on the same initial permutation of the integers 1…n: bubble sort (adjacent swaps), insertion sort (backward swaps of the next key), bottom-up merge sort (iterative passes with explicit merge steps), quicksort with Lomuto partitioning and an explicit stack, and heapsort (binary max-heap build + sift-down extracts). One global “micro-step” advances every algorithm together each frame batch: you see parallel motion patterns, not a wall-clock race (different algorithms require different total step counts). Bars are colored by index so you can track elements as they move; highlighted bars mark the current comparison or swap.
Who it's for: Intro CS courses and self-learners comparing O(n²) vs O(n log n) families visually; anyone who finished a textbook pseudocode pass and wants a side-by-side mental model.
Key terms
Bubble sort
Insertion sort
Merge sort
Quicksort
Heapsort
Lomuto partition
Binary heap
Stability (concept)
How it works
Five classic comparison sorts run on the same shuffled permutation: bubble, insertion, bottom-up merge, Lomuto quicksort, and heapsort. One synchronized micro-step per frame batch highlights how each algorithm moves elements.
Frequently asked questions
Why do the rows finish at different times?
Each algorithm needs a different number of elementary compare/swap steps for the same input. The simulator still advances them in lockstep per step, so faster-finishing rows simply idle at the sorted state while slower ones catch up.
Is merge sort here stable?
The teaching merge uses ≤ when keys tie so equal values prefer the left run—this is the usual stable tie-break. The other algorithms shown are not stable in general.
Why might quicksort look “busier” than heapsort?
Partitioning scans a whole subarray each pass and Lomuto does many swaps near the pivot; heapsort concentrates work in tree-style sift operations. Both are O(n log n) typical time, but the constant factors and memory access patterns differ.