The GATE Grind

GATE 2016 CS (CS2) – Question 44

Programming and Data Structures · Binary Heaps · 2 marks · Numerical answer

A complete binary min-heap contains each integer 1 through 1023 once. Root depth is zero. Find the greatest depth of integer 9.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 8.0 to 8.0

Explanation

Every ancestor of 9 must have a smaller value. Only eight smaller integers exist, so its depth is at most eight. A chain labelled 1 through 9 can occupy depths zero through eight, with remaining positions filled by larger values in heap order. The complete tree is deep enough, so eight is attainable.

More Binary Heaps questions

All Binary Heaps questions →