Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For HEAPSORT codes belowHeapsort (A){Build-MAX-Heap(A);for(i = A.length downto2){Swap(A[1], A[i]);A.heap_size= A.heap_size -1;MAX-Heapify(A, 1);}} What is the number of required swap operations when heapsort the array A

For HEAPSORT codes belowHeapsort

(A){Build-MAX-Heap(A);for(i = A.length downto2){Swap(A[1], A[i]);A.heap_size= A.heap_size -1;MAX-Heapify(A, 1);}}

What is the number of required swap operations when heapsort the array A = {5, 13, 2, 25, 7, 17, 20, 8, 4}? Explain your reason.

If we replace MAX-Heapify(A, 1) with Build-MAX-Heap(A), what is the number of required swap operations when heapsort the array A? Explain your reason.

(c) Does the asymptotic upper bound of Heapsort increase from O(nlgn) to O(n2)? Why?

 (Hint: compare the number of swap operations before and after the change for the worst case).

Step by Step Solution

3.30 Rating (162 Votes )

There are 3 Steps involved in it

Step: 1

a To find the number of required swap operations when heapsorting the array A 5 13 2 25 7 17 20 8 4 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting Information Systems

Authors: George H. Bodnar, William S. Hopwood

11th Edition

0132871939, 978-0132871938

More Books

Students also viewed these Algorithms questions