Overview
Heap Sort first arranges the array into a heap. It then swaps the root with the end of the unsorted region and restores the heap property until the array is sorted.
Sorts a list by building a heap and repeatedly removing the highest-priority item.
Compact metadata for implementation and discovery.
Heap Sort first arranges the array into a heap. It then swaps the root with the end of the unsorted region and restores the heap property until the array is sorted.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(1)
Show the heap tree and the sorted suffix growing from the end.
Heap sort trades some practical locality for an in-place worst-case O(n log n) guarantee.
What each reference supports for this entry.
Textbook support for Heap Sort invariants, recurrences, relaxation rules, or asymptotic analysis.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Sorting · Extended
Smoothsort is a heap-sort variant using Leonardo heaps to exploit existing order.
Compare with thisSorting · Foundation
Heap Sort avoids Quick Sort's worst-case partition behavior but is usually less cache-friendly.
Compare with thisHeap Sort repeatedly extracts the maximum or minimum from a heap.
Heap Sort avoids Quick Sort's worst-case partition behavior but is usually less cache-friendly.