Question: Present an algorithm that returns the largest k elements in a binary max-heap with n elements in 0(k lg k) time Note that, the complexity

 Present an algorithm that returns the largest k elements in a

Present an algorithm that returns the largest k elements in a binary max-heap with n elements in 0(k lg k) time Note that, the complexity of your algorithm should not depend on n. Hint 1: Let's consider who are the candidates for the ith largest element. It is easy to see that the root contains the only candidate for the 1st largest element, then who are the candidates for the 2nd largest element after the 1st largest element is determined? Who are the candidates for the 3rd largest element after the 2nd largest element is determined? And so on. Eventually, you will find that there are i candidates for the ith largest element after the (i1)th largest element is determined. Hint 2: How to use some data structure to maintain these candidates so that you can find the maximum among

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!