Skip to main content

GATE CSE 2025Data Structures › Heaps & Priority QueuesVerified

GATE CSE 2025 PYQ: The height of any rooted tree is defined as the maximum number of edges in the path from the root node to…

The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node.

Suppose a Min-Heap T\text{T} stores 32 keys. The height of T\text{T} is ___________. (Answer in integer)

    Answer

    5

    Approach

    A binary heap is always stored as a complete binary tree. For a complete binary tree with n nodes, the height in edges is floor(log2 n). With n = 32, this gives height 5.

    A min-heap with 32 keys is a complete binary tree. The first 5 levels (levels 0 through 4) can hold 1+2+4+8+16 = 31 nodes, and the 32nd key goes to the next level. Thus the longest root-to-leaf path has 5 edges, so the height is 5.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.