Calling RemoveMax the first time:
First we replace the
maximum 40 with the last element and delete the last element.
Then we siftdown our
new maximum which is 7. In sifting down if the largest of a node’s children is
greater than the mother node, we swap it with the node. As a result 7 will be
swapped with 38, then it will be swapped with 35 and after that it will be
swapped with 16.
Similarly we call RemoveMax for the second
time and after fully executing it the heap becomes the last figure.