Skip to main content

GATE CSE 2006Data Structures › Heaps & Priority QueuesVerified

GATE CSE 2006 PYQ: In a binary max heap containing n n n numbers, the smallest element can be found in time

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

  1. A
    O(n)O(n)
    Correct answer
  2. B
    O(log⁡n)O(\log n)
  3. C
    O(log⁡log⁡n)O(\log \log n)
  4. D
    O(1)O(1)

Answer

(A) O ( n ) O(n) O ( n )

Approach

Use the heap-order property and the complete-tree shape. In a max-heap, every internal node is at least as large as its descendants, so the global minimum must appear at a leaf. Count the leaves and scan them; a heap has Θ(n) leaves, giving O(n) time.

In a binary max-heap, the minimum must be a leaf. Since a complete binary tree with n nodes has about n/2 leaves, finding the minimum requires examining the leaves in the worst case, so the tight bound is O(n).

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.