Heap sort builds a binary heap from the array, then repeatedly extracts the maximum to produce sorted order. It runs in O(n log n) and is in-place.
The idea
A max-heap keeps the largest element at the root. Build the heap (O(n)), then swap the root to the end, shrink the heap, and re-heapify (sift down) — n times.
Example
heapq
():
heapq.heapify(arr)
[heapq.heappop(arr)
_ ((arr))]
heap_sort([, , , , ])
