GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Apply binary level capacity bounds

5 questions solved the same way, newest first. Back to Data Structures

How these are solved

Sum capacities 1+2+...+2^h for a maximally filled tree and compare the chain bound h+1; invert when height is requested, respecting edge-height convention. BFS rank, maximum/minimum nodes, height bounds and complete heap height are not repeats.

1 mark · NAT
Report issue

Computing the height of a binary heap

Heaps & Priority Queues

Question 35, GATE 2025: Height is the largest number of edges on a root-to-leaf path. A Min-Heap stores 32 keys. Under the standard binary-heap convention, what is its height?
Tap to enlarge
Answer & solution

Official answer: 5

Approach: Use the complete-binary-tree shape of a binary heap; key order does not determine its height.
At depth d, a binary tree can contain at most 2d nodes. The completely filled levels from depth 0 through depth 4 contain 1+2+4+8+16=31 nodes. A 32nd node therefore cannot fit in those levels and must occupy depth 5.
A heap is complete: all levels except possibly the last are full, with the last filled from left to right. Hence 32 keys create one node at depth 5 and none deeper. The height, measured in edges, is 5.
Equivalently, an n-node complete binary tree has height floor(log₂ n), and floor(log₂32)=5. Counting occupied levels would give 6, but the question explicitly uses edges. The answer relies on the conventional binary meaning of Min-Heap; arbitrary heap-ordered trees need not have this shape.

Original paper, page 35 · Answer key

1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 6, GATE 2017: A binary search tree has 15 nodes. A one-node tree has height 0. Find minimum and maximum heights. A (4,15); B (3,14); C (4,14); D (3,15).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Height counts edges, so levels 0 through h hold at most 1+2+...+2h=2h+1−1 nodes.

2. For 15 nodes, 2h+1−1≥15 requires h≥3. A perfect four-level tree realizes height 3 and can be assigned sorted BST keys.

3. At the other extreme, a one-child chain uses one edge per additional node, giving 14 edges. No simple root-to-leaf path can exceed 14 edges with 15 nodes. Answer B.

Original paper, page 4 · Answer key

1 mark · NAT
Report issue

Tree Properties & Traversals

Question 11, GATE 2016: BFS starts at the root of a binary tree. Vertex t is at distance 4 from the root and is the nth visited vertex, counting the root first. Find the maximum n.
Tap to enlarge
Answer & solution

Official answer: 31.0 : 31.0

Our answer: 31

BFS visits all shallower levels first. A full binary tree has 1+2+4+8=15 nodes above level4 and at most 16 nodes on level4. Taking t last on that level gives position 31, attained by a perfect tree through level4.

The last possible position at depth d in a binary tree is Σ(k=0 to d)2k=2d+1−1. Nodes at greater depth cannot precede t in BFS. Sparse levels or placing t earlier can only reduce its ordinal, so a full tree and a last-on-level choice attain the bound.

Original paper, page 28 · Answer key

1 mark · MCQ
Report issue

Tree Properties & Traversals

Question 15, GATE 2015: Height means the length in edges of the longest root-to-leaf path. Find maximum and minimum node counts of a binary tree of height 5. A 63 and 6; B 64 and 5; C 32 and 6; D 31 and 5.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Levels run from depth 0 through 5. At most 2d nodes fit at depth d, so the maximum is the geometric sum 26−1=63. The minimum still requires one path containing five edges, hence six vertices. The number 32 counts only the possible last-level nodes, not the entire tree.

Solution: Height5 counts edges. The complete tree has 1+2+4+8+16+32=63 nodes; a single path needs 6. Thus maximum 63 and minimum 6, A.

Original paper, page 7 · Answer key

1 mark · MCQ
Report issue

Maximum nodes at a given edge height

Tree Properties & Traversals

Question 12, GATE 2007: The height of a binary tree is the maximum number of edges on a root-to-leaf path. What is the maximum number of nodes at height h?
Options:
(A) 2^h−1
(B) 2^(h−1)−1
(C) 2^(h+1)−1
(D) 2^(h+1)
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. With edge height, the root is at depth zero. Count all levels including both level zero and level h, rather than counting only h levels.

2. Derivation and interpretation. At depth i a binary tree has at most 2i nodes. For edge height h, depths 0 through h sum to 1+2+...+2h=2h+1−1, C, attained by a perfect binary tree.

Original paper, page 3