GATE / CS ARCHIVE

GATE CSE 1999 / QUESTION 12(a)

Leaves equal full nodes plus one

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

GATE 1999, Q12(a) 3 marks · Descriptive
Report issue

Tree Properties & Traversals

Question 12(a), GATE 1999: In a nonempty binary tree, a full node has exactly two children. Prove by induction on height that the number of leaves equals the number of full nodes plus one.
Question 12(a), GATE 1999: In a nonempty binary tree, a full node has exactly two children. Prove by induction on height that the number of leaves equals the number of full nodes plus one.
Tap to enlarge
Shared context

In a nonempty binary tree, a full node has exactly two children. Prove by induction on height that the number of leaves equals the number of full nodes plus one.

Answer & solution

Answer: For every nonempty binary tree, L=F+1, including trees with one-child nodes. (no official key was published)

Use strong induction on the height h, taking a leaf to have height zero. Let L(T) and F(T) count leaves and full nodes in T.

Base h=0: T is a single leaf, so L=1 and F=0, giving L=F+1.

Induction hypothesis: the identity holds for every nonempty binary tree of height less than h. Consider a tree T of height h>0. Its root has one or two children.

If it has one child, the unique child subtree T₁ has smaller height. The root is neither full nor a leaf, so L(T)=L(T₁) and F(T)=F(T₁). By induction L(T)=F(T₁)+1=F(T)+1.

If it has two children with subtrees T₁,T₂, both have smaller height. Here L(T)=L(T₁)+L(T₂) and F(T)=1+F(T₁)+F(T₂), because the root itself is full. Substituting the two induction hypotheses gives L(T)=F(T₁)+1+F(T₂)+1=F(T)+1.

These cases exhaust all roots, proving the claim. The qualification “nonempty” matters: an empty tree has zero leaves and zero full nodes, so the formula would not hold there. It is unnecessary to assume every internal node is full.

Original paper, page 7