Question: 2. a) Illustrate how BUILD-MAX-HEAP (A) works on the array A = {2, 9, 6, 8, 11, 4, 5, 3, 1, 7}. Each step

2. a) Illustrate how BUILD-MAX-HEAP (A) works on the array A = {2, 9, 6, 8, 11, 4, 5, 3, 1, 7}. Each step is the result of one call to the MAX-HEAPIFY function. Show both the array view and the tree view for each step. BUILD-MAX-HEAP(A) = 1 A.heap-size A.length 2 for iA.length/2] downto 1 MAX-HEAPIFY (A, i) 3 MAX-HEAPIFY (A,i) 1 1 = LEFT (i) 2 r = RIGHT(i) 3 if 4 5 6 7 96 A.heap-size and A[!] > A[i] largest = 1 else largest = i if rA.heap-size and A[r]> A[largest] largest = r 8 if largest i 10 exchange A[i] with A[largest] MAX-HEAPIFY (A,largest)
Step by Step Solution
There are 3 Steps involved in it
To illustrate how BUILDMAXHEAP works on the array A 2 9 6 8 11 4 5 3 1 7 we will show each step of t... View full answer
Get step-by-step solutions from verified subject matter experts
