Quick Sort vs Heap Sort

Across our 3 test inputs, Quick Sort needed 106 comparisons in total versus 112 for Heap Sort.

Head-to-head on identical inputs (comparisons)

InputQuick SortHeap Sort
Random order2236
Nearly sorted3941
Reversed4535

Complexity

Quick SortHeap Sort
Average timeO(n log n)O(n log n)
Worst timeO(n²)O(n log n)
SpaceO(log n)O(1)
StableNoNo

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).

When to use Heap Sort

When you need guaranteed O(n log n) with O(1) extra memory — e.g. embedded or real-time systems.