The GATE Grind

GATE 2021 CS (CS2) – Question 12

Programming and Data Structures · Binary Heaps · 1 mark · Multiple choice

A binary min-heap of n elements is stored in an array. Find the worst-case complexity of an optimal algorithm to find its maximum.

  1. Θ(1)
  2. Θ(log n)
  3. Θ(n)
  4. Θ(n log n)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) Θ(n)

Explanation

The maximum must be among the leaves, whose count is about n/2. A min-heap imposes no ordering between leaves, so locating their maximum needs a linear number of comparisons in the worst case. Scanning the leaves attains that bound. Thus Θ(n), C.

More Binary Heaps questions

All Binary Heaps questions →