Friday, September 5, 2025
HomeData Modelling & AIData Structures | Heap | Question 8

Data Structures | Heap | Question 8

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)

(B)

theta(n)

(C)

theta(logn)

(D)

theta(1)

Answer: (D)
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 \\theta(1)   time. If Min-Heap is allowed to have duplicates, then time complexity becomes Θ(Log n). Also, if Min-Heap doesn\’t allow directly accessing elements below root and supports only extract-min() operation, then also time complexity becomes Θ(Log n).

Quiz of this Question
Please comment below if you find anything wrong in the above post

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS