Core idea
Heap Sort first arranges the array into a binary heap where the maximum value sits at the root.
It then swaps that root with the last unsorted element, shrinks the heap, and heapifies again.
It guarantees O(n log n) time and is a good way to understand the connection between arrays and tree-shaped data.