Answered step by step
Verified Expert Solution
Link Copied!

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?
since we multiply n-1 by log n?
image text in transcribed
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

Step: 1

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions