Skip to content
Sortingadvanced

Heap Sort

Builds a binary max-heap in place, then repeatedly swaps the largest element to the end and sifts the root back down. Guaranteed O(n log n) with O(1) extra space, at the cost of poor cache locality and instability.

Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(1)
Stable
No