Question: After heapsort heapifies, it then begins removing things from the top of the heap and placing them at the end of the array. How will your answer from the above question look after four iterations?
Answer: From the previous question, we have the following heap.
57 50 53 26 35 15 22 21 25 14 11 2After one removal we have removed the 57 to the bottom.
53 50 22 26 35 15 2 21 25 14 11 57The next removal results in
50 35 22 26 14 15 2 21 25 11 53 57Then we have
35 26 22 25 14 15 2 21 11 50 53 57And finally we get
26 25 22 21 14 15 2 11 35 50 53 57