Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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?
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 since we multiply n-1 by log n?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started