Question: Num #7 You have a correctly implemented Max-Heap class (indices starting at 1), which provides the two following helper functions (in addition to insert, remove,

Num #7

Num #7 You have a correctly implemented Max-Heap class (indices starting at

You have a correctly implemented Max-Heap class (indices starting at 1), which provides the two following helper functions (in addition to insert, remove, peek): (a) trickleUp (int i) (David's lecture) a.k.a. insert (int i) (Mark's lecture) takes the element at position i and b) trickleDown (int i) (David's lecture) a.k.a. heapify (int i) (Mark's lecture) takes the element at position keeps swapping it with its parent (and grandparent etc.) until it is no larger than the parent at the time. i and keeps swapping it with the larger of its children (and grandchildren etc.) until it is no smaller than both children Suppose that you get an instance whose array elements are not in correct heap order, i.e., the heap property does not hold yet. You want to establish the correct arrangement, by using the two helper functions given above. Which of the following two alternatives do this correctly? Explain why they are correct or incorrect. For incorrect ones, give an example of an initial heap which is not correctly processed, and explain what happens when the incorrect variant is executed on it Heap h; // Variant 1 for (int = 1; ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!