Algorithm
Heap Sort Algorithm:
- Start with an unsorted array.
- Build a Max Heap from the array:
- Ensure the heap property is satisfied at every node.
- Start from the last non-leaf node and heapify all parent nodes.
- Extract the root (largest element) of the heap and place it at the end of the array.
- Restore the heap property for the remaining unsorted portion of the array.
- Repeat the process until the entire array is sorted.
Example:

Fig. 1: Iteration by Iteration Visualization of Heap Sort
Note: Heap Sort efficiently uses a binary heap to sort elements, making it suitable for in-place sorting.