Sorting hard time O(n log n) space O(1)
Heap Sort
Treat the array as a binary heap (children of i live at 2i+1 and 2i+2). Build a max-heap so the biggest value is at the front, swap it to the end, shrink the heap, and sift the new root down. Repeat.
Heap sort: first arrange the array into a max-heap.
1 / 37
Practice
Machine twin: /dsa-viz-v2/heap-sort.json — the full deterministic run as structured data.