I hope this will solve the problem
Using build heap method, we will take the given binary tree in the form of array and then go directly to the last internal node (last internal will be at location floor(n/2)-1) and from last internal node onwards the parent will ask its children that “am i at correct position” if yes then one by one every parent will ask else if not then swapping will be done. Similarly, 2nd last internal node will do it and so on… till root node (first internal node).
Time complexity= $\Theta$(n)
i hope you got it. Thank you.
64.3k questions
77.9k answers
244k comments
80.0k users