For HEAPSORT codes below
Heapsort(A)
{
Build-MAX-Heap(A);
for (i = A.length downto 2)
{
Swap(A[1], A[i]);
A.heap_size= A.heap_size – 1;
MAX-Heapify(A, 1);
}
}
(a) What is the number of required swap operations when heapsortthe array A = {5, 13, 2, 25, 7, 17, 20, 8, 4}? Explain yourreason.
(b) If we replace MAX-Heapify(A, 1) with Build-MAX-Heap(A), whatis the number of required swap operations when heapsort the arrayA? Explain your reason.
(c) (Does the asymptotic upper bound of Heapsort increase fromO(nlgn) to O( 2 )? Why? (Hint: compare the number ofswap operations before and after the change for the worstcase).
Expert Answer
An answer will be send to you shortly. .
PayPal Gateway not configured
PayPal Gateway not configured