GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 13

GATE CSE 2025 Set 2 Q13

Data Structures · Tree Properties & Traversals · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q13 1 mark · MCQ
Report issue

Tree Properties & Traversals

Question 13, GATE 2025: A nonempty binary tree has n nodes, and every node has either zero or exactly two children. How many nodes have two children?
Options: A. (n−2)/2; B. (n−1)/2; C. n/2; D. (n+1)/2.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Let i be the number of internal nodes and l the number of leaves, so n=i+l. Count the tree edges in two ways. Every non-root node has exactly one parent, giving n−1 edges in total. On the other hand, each internal node contributes two parent-to-child edges and each leaf contributes none, giving 2i edges. Therefore 2i=n−1 and i=(n−1)/2.

This also implies l=i+1=(n+1)/2, which explains why D is a plausible but incorrect distractor: it counts leaves. Such a tree has odd n, as n=2i+1. At the boundary n=1, the root is a leaf and the formula gives zero two-child nodes, as required. This is a full/proper binary tree property; it does not require the tree to be balanced or all leaves to be at the same depth. Answer: B.

Original paper, page 12 · Answer key