Heap Sort
An in-place max heap shown as both an array and a tree
Turn the array into a priority structure
Heap Sort interprets the array as a complete binary tree. In a max heap, every parent is at least as large as its children, so the root is the maximum. Floyd's build starts at the last internal node and sifts each subtree downward.
Extract the root into the sorted suffix
Swap the root with the last heap element, shrink the heap, then sift the new root down until the max-heap invariant is restored. The array and tree tracks share element IDs, so every structural change stays synchronized.
Run sift-down from node 4 while building the max heap.
Guaranteed bounds
Floyd heap construction is O(n). The following n - 1 extractions each cost at most O(log n), giving O(n log n) worst-case time and O(1) auxiliary space. Heap Sort is not stable.
Compare its tree-based selection with Quick Sort partitioning.