Using Bottom-Up Heapify – O(n) Time and O(log n) Space
The idea is to heapify operations from the last internal node up to the root. Since leaf nodes already satisfy heap property, we only need to fix internal nodes. By heapifying in bottom-up order, every subtree becomes a valid Max Heap, resulting in the complete array forming a Max Heap efficiently.
Start from the last non-leaf node of the heap
Apply MaxHeapify on each internal node while moving towards the root
During heapify, compare node with its children and swap with the larger child if needed
Repeat recursively until Max Heap property is satisfied for all nodes