recategorized by
3,688 views
11 votes
11 votes

What is the complexity of finding $50^{th}$ smallest element in an already constructed binary min-heap?

  1. $\Theta(1)$
  2. $\Theta (\log n)$
  3. $\Theta (n)$
  4. $\Theta (n \log n)$
recategorized by

5 Answers

1 votes
1 votes

Finding minimum element in a min heap takes O(1) time. To find the 50th smallest element in a min heap needs to delete first 49 smaller elements and then finding the next smaller element, i.e. 50th smallest element. 

Deleting smallest element (root element in a min heap) takes O(logn) time. Total time to delete 49 smaller elements is O(49*logn) = O(logn). Next finding the next min element takes O(1) time. 

Next inserting all the 49 deleted elements need to be inserted back into the heap. That takes O(49*logn). The total time complexity thus becomes O(logn).

Related questions

1 votes
1 votes
1 answer
1
8 votes
8 votes
3 answers
2
Kapil asked Sep 4, 2016
3,960 views
In a min-heap with n elements1). The 7th smallest element can be found in time, if duplicates are allowed ?2). The 7th distinct smallest element can be found in time, I...
1 votes
1 votes
1 answer
4
gmrishikumar asked Dec 1, 2018
2,297 views
What is the time complexity to find the Kth largest element in a Min-Heap? Or equivalently, What is the time complexity to find Kth smallest element in Max-Heap?