Course Solutions Uncategorized (Solved) : Heapsort Codes Heapsort Build Max Heap Length Downto 2 Swap 1 Heapsize Heapsize 1 Max Heap Q31188603 . . . .

(Solved) : Heapsort Codes Heapsort Build Max Heap Length Downto 2 Swap 1 Heapsize Heapsize 1 Max Heap Q31188603 . . . .

 

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. .

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

(Answered) : What business concept would be appropriate for a sole proprietorship, a corporation, and a limited liability company, respective(Answered) : What business concept would be appropriate for a sole proprietorship, a corporation, and a limited liability company, respective

What business concept would be appropriate for a sole proprietorship, a corporation, and a limited liability company, respectively? If you were opening your dream business, what structure would you select?