GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 34

GATE CSE 2016 Set 2 Q34

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

GATE 2016 Set 2, Q34 2 marks · NAT
Report issue

Heaps & Priority Queues

Question 34, GATE 2016: A complete binary min-heap contains each integer 1,…,1023 exactly once. Root depth is 0. What is the greatest possible depth of key 9?
Tap to enlarge
Answer & solution

Official answer: 8.0 : 8.0

Our answer: 8

A node at depth d has d strictly smaller ancestors in a heap of distinct keys. Key9 has only eight smaller values, so d≤8, also below the full tree’s maximum depth 9. Place1..9 along a root-to-depth 8 chain and assign remaining keys in a parent-before-child order; all heap inequalities can be satisfied. Thus depth 8 is attainable.

There are 1023=210−1 nodes, so levels 0 through 9 exist. Depth 9 would require nine ancestors smaller than 9, but only eight values qualify. A heap is not a BST: siblings need not be numerically ordered, so the remaining values can be assigned without imposing a search-tree constraint on the chosen chain.

Original paper, page 34 · Answer key