Question: why we didnt multiply n-1 by constant time? since we multiply n-1 by log n? Let us count operations line by line. 1. Construct the

why we didnt multiply n-1 by constant time?
since we multiply n-1 by log n?
why we didnt multiply n-1 by constant time? since we multiply n-1

Let us count operations line by line. 1. Construct the heap in linear time. "In particular, the BuildHeap procedure actually runs in (n) time". 2. Execute the loop and perform a logarithmic time operation n-1 times. 3. Other operations take constant time. Hence, your running time is HEAPSORT(A) | BUILD-MAX-HEAP(A) (n) n+ (n 1) logn + O(1) 2 for i + length[A] downto 2 3 = n + n logn - logn + O(1) do exchange A[1] A[i] 4 heap-size[A] + heap-size[A] - 1 = (n log n). 5 MAX-HEAPIFY(A, 1) (Ign) n-1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!