GATE / CS ARCHIVE

GATE CSE 2011 / QUESTION 23

Recognizing a max-heap

Data Structures · Heaps & Priority Queues · Full GATE CSE 2011 paper

GATE 2011, Q23 1 mark · MCQ
Report issue

Heaps & Priority Queues

Question 23, GATE 2011: Which drawn binary tree is a max-heap? Below each node is specified as value:(left child,right child), with '-' for a missing child.

(A) 10:(8,6), 8:(4,-), 6:(5,2), 5:(1,-); remaining nodes are leaves
(B) 10:(8,6), 8:(4,5), 6:(1,2); remaining nodes are leaves
(C) 10:(5,6), 5:(4,8), 6:(2,1); remaining nodes are leaves
(D) 5:(2,8), 2:(1,4), 8:(6,10); remaining nodes are leaves
Tap to enlarge
Your answer
Answer & solution

Official answer: B

A binary max-heap must have complete-tree shape as well as parent≥child values. B is complete and satisfies 10≥8, 6; 8≥4, 5; 6≥1, 2. A satisfies value order but not completeness. C has child8 greater than parent5; D also violates value order. Thus B.

Completeness requires every level except possibly the last to be full and the last level to be filled from left to right. In A, node 8 lacks a right child while positions to its right are occupied, and a deeper node exists despite that gap. In B every displayed level is full, and every parent dominates its two children. C fails at 5→8; D fails already at 5→8 and also at 2→4 and 8→10. Checking only the root maximum is insufficient.

Original paper, page 6 · Answer key