Question: Write a program to implement MaxHeap (build) and then use Heap sort to sort them in C++ pseudocode attached: 1. Find L=21,R=L+1MAXHeAPIFY(A,i,n) 2. If Both

1. Find L=21,R=L+1MAXHeAPIFY(A,i,n) 2. If Both L and R exists, then lLEFT(i) compare A[L] and A[R] and find rRIGHT(i) the largest of the two if ln and A[l]>A[i] 3. Now check if A[ largest] >A[i] then largest l then swap A[i] with A[ largest] else largest i and then if rn and A[r]>A[ largest ] i= largest and use Recursion to then largest r MaxHeapify(i) if largest =i then exchange A[i]A[ largest ] MAX-HEAPIFY (A, largest, n) HEAPSORT(A,n) BUILD-MAX-HEAP (A,n) for in downto 2 do exchange A[1]A[i] MAXHEAPIFY(A,1,i1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
