Quick Sort vs Merge Sort
Quick Sort and Merge Sort are both sorting. Play them side by side below, then see exactly where they diverge.
Either player can stop before each decision and ask what happens next: turn on Predict mode in its top bar.
Quick Sort
Full topicPick a pivot, push everything smaller left, and the pivot is home for good.
CHOOSE PIVOT -> PARTITION (smaller left, larger right) -> pivot lands in its final place -> RECURSE.
Merge Sort
Full topicMerge two sorted runs by always taking the smaller front value.
MERGE neighbouring runs -> the smaller head is written down -> runs double in width each pass.
How they differ
Both split the array and sort the parts. They do the real work at opposite ends. Quick sort works before it recurses, partitioning around a pivot, so it sorts in place with O(log n) of recursion but falls to O(n^2) when the pivots split badly. Merge sort works after, merging two sorted halves, so it is O(n log n) in every case and stable, at the price of O(n) extra space.
The run shown here takes 29 steps for Quick Sort and 36 steps for Merge Sort. That count moves with the input - use the example tabs above either player to see it change.
| Cost | Quick Sort | Merge Sort |
|---|---|---|
| best | O(n log n) | O(n log n) |
| average | O(n log n) | O(n log n) |
| worst | O(n^2) | O(n log n) |
| space | O(log n) | O(n) |
| Property | Quick Sort | Merge Sort |
|---|---|---|
| comparison based | ✓ | ✓ |
| stable | × | ✓ |
| in place | ✓ | × |
| adaptive | × | × |
| online | × | × |