GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 1.17

Leaves and binary branching nodes

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

GATE 1995, Q1.17 1 mark · MCQ
Report issue

Tree Properties & Traversals

Question 1.17, GATE 1995: A nonempty rooted binary tree has n leaves. How many nodes have two children?
Tap to enlarge
Your answer
Answer & solution

Answer: B: n−1 (no official key was published)

Let n0,n1,n2 count nodes with zero, one and two children. The tree has n0+n1+n2−1 edges because it is connected and acyclic. Counting edges by parents gives n1+2n2. Equating the two expressions yields n2=n0−1=n−1. Unary nodes cancel and therefore do not alter the relationship. Here degree two means two children, the rooted-tree convention; interpreting it as undirected graph degree would be a different question.

Original paper, page 2