GATE / CS ARCHIVE

SIMILAR QUESTIONS / DISCRETE MATHEMATICS

Count leaves and internal vertices in full m-ary trees

3 questions solved the same way, newest first. Back to Discrete Mathematics

2 marks · MCQ
Report issue

Leaves in a full ternary tree

Trees & Connectivity

Question 2.9, GATE 2002: A rooted tree has n nodes, each with either zero or three children. How many leaves does it have?
(A) n/2; (B) (n−1)/3; (C) (n−1)/2; (D) (2n+1)/3.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: Count edges in two ways.

Step 2: Every vertex except the root has exactly one parent edge, so there are n−1 edges. Every internal node has three children, so there are 3I edges. Equating gives I=(n−1)/3. Subtracting internal nodes from all nodes gives leaves L=n−(n−1)/3=(2n+1)/3. For the smallest nontrivial case n=4, this correctly returns three leaves.

Conclusion: Let I be the internal-node count and L the leaves. Each internal node supplies 3 child edges, while a tree has n−1 edges, so 3I=n−1. Hence L=n−I=(2n+1)/3, D, for n admitting such a tree.

Original paper, page 4

2 marks · MCQ
Report issue

Leaves in a full n-ary tree

Trees & Connectivity

Question 2.11, GATE 1998: Every node has either 0 or n children. If x nodes are internal, how many leaves are there?
Tap to enlarge
Your answer
Answer & solution

Answer: A: x (n−1)+1 (no official key was published)

Each internal node contributes exactly n child edges, so the tree has nx edges. If it has L leaves, its total vertices are x+L, and any tree has one fewer edge than vertices: nx=x+L−1. Rearranging yields L=x (n−1)+1, A. The explicit 0-or-n condition is essential; it prevents one-child or partially populated internal nodes from invalidating the count. For x=0 it correctly gives a single root leaf.

Original paper, page 4

5 marks · Descriptive
Report issue

Leaves in a full binary tree

Trees & Connectivity

Question 16, GATE 1993: Prove by mathematical induction that a binary tree in which every non-leaf node has two descendants has one more leaf than non-leaf node. Interpret descendants here as immediate children, i.e. a finite nonempty full binary tree.
Tap to enlarge
Answer & solution

Answer: L=I+1 for every finite nonempty full binary tree. (no official key was published)

Let I be the number of internal (non-leaf) nodes and L the number of leaves. We prove L=I+1 by strong induction on I for finite nonempty full binary trees.

Base case I=0: there is only the root, and it is a leaf. Thus L=1=I+1. The empty tree is excluded: it would have L=I=0 and would not satisfy the stated formula.

Inductive hypothesis: for every full binary tree with fewer than k internal nodes, the number of leaves is one more than the number of internal nodes. Consider a tree with k>=1 internal nodes. Its root is internal and, by the full-tree condition, has exactly two children. The subtrees rooted at these children are nonempty full binary trees; call their internal and leaf counts I1,L1 and I2,L2. Each Ii<k, and k=1+I1+I2. The induction hypothesis applies to both subtrees: L1=I1+1 and L2=I2+1. Their leaves are disjoint and are exactly the leaves of the original tree, since the root is not a leaf. Hence L=L1+L2=I1+I2+2=k+1. This completes the induction.

An equivalent structural induction starts with one leaf and replaces any leaf by an internal node with two new leaf children. Every such operation increases I by one and increases L by one (remove one leaf, add two), preserving L−I=1. As an independent check, a tree with I+L vertices has I+L−1 edges; counting edges by parents gives 2I, so 2I=I+L−1. The immediate-child interpretation matters: general binary trees permitting a single child need not obey the formula.

Original paper, page 12