GATE / CS ARCHIVE

GATE CSE 1997 / QUESTION 16(b)

Count the penultimate tree level

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 1997 paper

GATE 1997, Q16(b) 2 marks · Descriptive
Report issue

Binary Search & Balanced Trees

Question 16(b), GATE 1997: A size-balanced binary tree has, at every node, left and right subtree sizes differing by at most one. Node distance is the number of edges from the root, and tree height h is the greatest root-to-leaf distance. For h≥1, how many nodes are at distance h−1 from the root?
Question 16(b), GATE 1997: A size-balanced binary tree has, at every node, left and right subtree sizes differing by at most one. Node distance is the number of edges from the root, and tree height h is the greatest root-to-leaf distance. For h≥1, how many nodes are at distance h−1 from the root?
Tap to enlarge
Answer & solution

Answer: Exactly 2^(h−1). (no official key was published)

The level at distance h−1 is full, so it contains 2h−1 nodes. To justify fullness rather than assume it, first use the proved size bound: a size-balanced tree of height h has N≥2h nodes.

For any node whose subtree has s nodes, its child sizes sum to s−1 and differ by at most one. Hence each child has at least floor((s−1)/2) nodes. Starting from N≥2h, induction on depth shows that every node at depth d≤h−1 has subtree size at least 2h−d−1. Indeed, a parent lower bound 2h−d−1 gives each child at least 2h−d−1−1.

In particular, at every depth d<h−1 this lower bound is at least 3. Such a subtree has both children nonempty. Beginning with one root, the node count therefore doubles at each step until depth h−1, giving exactly 2h−1 nodes there. The last level h may be only partly occupied, so this does not assert that the entire tree is perfect.

For h=1 the requested level is the root itself and the formula gives 1. For h=2 a smallest example has four nodes: its depth-1 level still has both children, while only one node need occur at depth 2. The paper explicitly states h≥1.

Original paper, page 8