Skip to content
Official PYQ · 2006

GATE CS 2006 Q10 — Binary Heaps

Explain with AI

In a binary max heap containing nn numbers, the smallest element can be found in time 

Choose one option
View worked solution

Answer: A

In a binary max-heap of size nn, the properties of the heap structure dictate where elements are located:

  • The largest element is always at the root (index 11 in an array representation).
  • The smallest element must be one of the leaf nodes, as any path from the root to a leaf is non-increasing.

In a complete binary tree with nn elements, the leaf nodes are located at indices from ⌊n/2⌋+1\lfloor n/2 \rfloor + 1 to nn. The number of leaf nodes is ⌈n/2⌉\lceil n/2 \rceil, which is O(n)O(n).

Since the leaf nodes are not maintained in any sorted order relative to each other, we must perform a linear search across all the leaf nodes to find the minimum element. This search requires checking ⌈n/2⌉\lceil n/2 \rceil elements, which takes Θ(n)\Theta(n) time in the worst case.

Therefore, the smallest element can be found in O(n)O(n) time.

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

Published
Report a correction
Keep exploringMore Binary Heaps questions