GATE / CS ARCHIVE

GATE CSE 2015 SET 2 / QUESTION 22

GATE CSE 2015 Set 2 Q22

Data Structures · Heaps & Priority Queues · Full GATE CSE 2015 Set 2 paper

GATE 2015 Set 2, Q22 1 mark · MCQ
Report issue

Heaps & Priority Queues

Question 22, GATE 2015: A complete binary tree has both root subtrees already max-heaps. What lower bound describes operations to turn it into a heap? AΩ(logn), BΩ(n), CΩ(nlogn), DΩ(n²). The intended interpretation is worst-case repair work, not a lower bound for every instance.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: A for worst-case heap repair

Sift the root down, swapping with the larger child until order is restored. The path can have Θ(log n) levels, and a smallest root with heap-ordered descendants realizes that worst case. Thus the intended worst-case lower bound is Ω(log n), A. It is not a per-instance lower bound: a root already exceeding its children needs only constant checking.

Only the root can violate heap order because its subtrees already satisfy it. Compare the root with its larger child and swap downward as needed; each swap moves the offending value one level. A complete n-node tree has height Θ(logn), and placing a sufficiently small value at the root can force a descent to a leaf. That is the intended worst-case lower bound matched by sift-down. If the root already dominates its children, constant work is enough, so the statement cannot mean every instance requires logarithmic work.

Original paper, page 33 · Answer key