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)
| Input | Quick Sort | Heap Sort |
|---|---|---|
| Random order | 22 | 36 |
| Nearly sorted | 39 | 41 |
| Reversed | 45 | 35 |
Complexity
| Quick Sort | Heap Sort | |
|---|---|---|
| Average time | O(n log n) | O(n log n) |
| Worst time | O(n²) | O(n log n) |
| Space | O(log n) | O(1) |
| Stable | No | No |
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.