//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Solution to Quiz 5: Heap Usage //CS 284 //Programmed by Jonathan Voris //4/20/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1) No, the data structure is not a heap for the following reasons: -The heap is not correctly ordered. Every node is larger than its parent, except for 32 and 23. Swap these to correct this. -The heap is not complete. 19 does not have a right child, yet there are nodes two levels deeper than 19. Solve this by moving the last element, 28, up under 19, or simply adding a new node beneath 19. 2) The following three steps occur as a result of a call to removeMin on the corrected heap from question 1: -7 is removed and replaced with the last element in the heap, 70 (or 28 if it was not moved in question 1), to preserve completeness. -70 is larger than its children. Swap it with the smaller of its children, which is 15. -70 is still out of order because it is larger than its children. Swap it with the smaller of the two, 18. The heap is now preoperly ordered.