Merge Sort vs Quick Sort

Across our 3 test inputs, Merge Sort needed 59 comparisons in total versus 106 for Quick Sort. Merge Sort is stable; Quick Sort is not.

Head-to-head on identical inputs (comparisons)

InputMerge SortQuick Sort
Random order2522
Nearly sorted1939
Reversed1545

Complexity

Merge SortQuick Sort
Average timeO(n log n)O(n log n)
Worst timeO(n log n)O(n²)
SpaceO(n)O(log n)
StableYesNo

When to use Merge Sort

When stable sorting is strictly required and O(n) extra space is acceptable. Highly predictable performance (always O(n log n)).

When to use Quick Sort

General-purpose sorting. Fast in practice due to excellent cache locality. Default algorithm used in many language libraries (often hybridised as Introsort).