In a binary max heap containing numbers, the smallest element can be found in time
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
- ACorrect answer
- B
- C
- D
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.