GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 13

Worst array index for a binary tree

Data Structures · Tree Properties & Traversals · Full GATE CSE 2006 paper

GATE 2006, Q13 1 mark · MCQ
Report issue

Tree Properties & Traversals

Question 13, GATE 2006: Store any n-node binary tree in a one-based array: root at X[1], left child of X[i] at X[2i], right child at X[2i+1]. What minimum array capacity guarantees room for every possible n-node tree?
Options:
(A) log₂n
(B) n
(C) 2n+1
(D) 2^n−1
Question 13, GATE 2006: Store any n-node binary tree in a one-based array: root at X[1], left child of X[i] at X[2i], right child at X[2i+1]. What minimum array capacity guarantees room for every possible n-node tree?
Options:
(A) log₂n
(B) n
(C) 2n+1
(D) 2^n−1
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. Following right children produces indices 1,3,7,...,2n−1 for an n-node chain. No n-node tree has depth beyond n−1, whose largest possible index is 2n−1.

2. Therefore an array indexed from 1 must provide that many positions, D. This counts logical one-based entries, not an extra unused C array index 0.

3. Teaching check: A chain of only right children is the worst case, not a balanced tree. Repeatedly applying i↦2i+1 from i=1 gives iₖ=2k+1−1 at depth k. The last of n nodes therefore occupies index 2n−1, although only n positions contain actual nodes.

Original paper, page 2