In a min-heap with n elements with the smallest element at the root, the 7th smallest element can be found in time:
(A)theta(nlogn)
theta(n)
(C)theta(logn)
theta(1)
Answer:(C)
Explanation:
For clarity, assume that there are no duplicates in Min-Heap and accessing heap elements below root is allowed.
The 7th smallest element must be in first 7 levels. Total number of nodes in any Binary Heap in first 7 levels is at most 1 + 2 + 4 + 8 + 16 + 32 + 64 which is a constant. Therefore we can always find 7th smallest element in
Quiz of this Question
Please comment below if you find anything wrong in the above post