Question: Given the following code: LEFT(i) return 2i RIGHT(i) return 2i + 1 MaxHeapify(A, i) l = LEFT(i); r = RIGHT(i); if l A[i] largest =
Given the following code:
LEFT(i)
return 2i
RIGHT(i)
return 2i + 1
MaxHeapify(A, i)
l = LEFT(i);
r = RIGHT(i);
if l <= A.heap-size and A[l] > A[i]
largest = l;
else
largest = i;
if l <= A.heap-size and A[r] > A[largest]
largest = r;
if largest != i
exchange A[i] with A[largest]
MaxHeapify(A, largest);
BuildMaxHeap(A)
A.heap-size = A.length
for i = floor(A.length/2) downto 1
MaxHeapify(A, i)
1. Run MaxHeapify(A, 3) on the array A={27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0}
2.
Which of the following array(s) is/are max heap?
A = {72, 40, 70, 35, 30, 55, 65, 39}
B = {59, 55, 40, 30, 50, 39, 35, 17}
C = {62, 59, 42, 32, 39, 44, 13, 29}
D = {78, 56, 20, 55, 57, 23, 15, 20}
E = {74, 69, 32, 55, 40, 30, 29, 50}
3. For an array of n records, what is the height of max heap tree?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
