Question: Below are three different methods for building a max - heap. Suppose that A [ 1 , 2 , . . . , n ]

Below are three different methods for building a max-heap. Suppose that A[1,2,..., n] initially contains n elements, which are not necessarily in heap format. You may assume that the value of A.heapsize = n. For each method, justify whether the method correctly. builds a max-heap. If so, justify your answer. If not, provide an example showing it doesnt work. METHOD 1: Initial call: Make-Heap1(A, n) Make-Heap1(A, i) If i >1 Bubble-up(A,i) Make-Heap1(A,i 1) METHOD 2: Initial call: Make-Heap2(A, n) Make-Heap2(A, i) If i 1 Bubble-down(A,i) Make-Heap2(A,i 1) METHOD 3: Initial call: Make-Heap3(A,1) Make-Heap3(A, i) If i A.heapsize Bubble-up(A,i) Make-Heap3(A,i +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 Programming Questions!