SortingAnimated
Heap Sort
Build a max-heap, then repeatedly extract the maximum.
Time
O(n log n)
Extra space
O(1)
Use it for
Guaranteed O(n log n) with no extra memory.
How it works
- Rearrange the list into a max-heap (every parent ≥ its children).
- The largest value is at the root: swap it with the last item and shrink the heap.
- Sift the new root down to restore the heap.
- Repeat. O(n log n), in place, not stable.
Watch it run
Loading animation…