Let be a binary min-heap consisting of elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in ?
GATE CSE 2021Data Structures › Heaps & Priority QueuesVerified
GATE CSE 2021 PYQ: Let H H H be a binary min-heap consisting of n n n elements implemented as an array. What is the worst…
- A
- B
- CCorrect answer
- D
Answer
(C) Θ ( n ) \Theta (n) Θ ( n )
Approach
Use the structural property of a binary min-heap: every parent is ≤ its children, so the largest key can never sit at an internal node that has a child — it must be one of the leaves. Since leaf keys are not stored in sorted order, the only reliable strategy is to examine all leaves, and that linear scan is also a matching lower bound.
Because a min-heap's maximum is guaranteed to be a leaf and the leaves are mutually unordered, an optimal search examines every leaf once: ⌈n/2⌉ comparisons, i.e. Θ(n). Option C.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.