Quick Sort is easy to summarize: choose a pivot, partition, and repeat. It is much harder to reason about while indices and subranges are moving. This visualizer turns those hidden state changes into a timeline you can inspect.
What the visualization shows
This implementation uses Lomuto partitioning with the rightmost item as the pivot. The red i pointer marks the boundary of the smaller-than-pivot region, while the blue j pointer scans the active range. When a[j] < pivot, that value moves into the smaller region and i advances. Once the scan reaches hi, the pivot swaps into i and reaches its final position.
Pending [lo, hi] ranges appear on an explicit stack, so the recursive work is visible instead of being hand-waved. Every frame keeps the array, active range, pivot, pointers, swap count, stack, caption, and current source line synchronized. You can compare the same execution against TypeScript, Python, Go, and Rust implementations.
Try these inputs
- An already sorted array shows how a rightmost pivot can create severely unbalanced partitions.
- A reverse-sorted array exposes the same worst-case shape through a different sequence of swaps.
- Duplicate-heavy input reveals that the strict
< pivotcomparison leaves equal values on the other side of the boundary. - A mixed input makes the typical divide-and-conquer behavior easier to see.
What to look for
Quick Sort runs in O(n log n) time on average, but this pivot strategy can degrade to O(n^2). Pause at each pivot placement, compare the sizes of the two resulting ranges, and watch the pending stack grow or shrink. Then change the input and replay the exact same checkpoints. The goal is not only to see a sorted result, but to understand how partition balance determines the work required.
Top comments (0)