Skip to content
Official PYQ · 2003

GATE CS 2003 Q23 — Binary Heaps

Explain with AI

In a min-heap with nn elements with the smallest element at the root, the 7th7^{th} smallest element can be found in time

Choose one option
View worked solution

Answer: D

In a min-heap, the smallest element is always at the root (level 0). The second smallest element must be one of the children of the root (level 1).

More generally, the kthk^{\text{th}} smallest element in a min-heap must reside within the first kk levels of the heap. This is because any path from the root to a node is in non-decreasing order, so an element cannot be smaller than its ancestors.

For k=7k = 7:

  • The 7th7^{\text{th}} smallest element must be located within the top 77 levels of the min-heap.
  • The maximum number of nodes in the first 77 levels of a binary tree is 27−1=1272^7 - 1 = 127.
  • Since 127127 is a constant that does not depend on the total number of elements nn, we only need to search a constant number of elements to find the 7th7^{\text{th}} smallest element.

Therefore, the time complexity to find the 7th7^{\text{th}} smallest element is Θ(1)\Theta(1).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Heaps questions