Skip to content
Official PYQ · 2010

GATE CS 2010 Q10 — Trees

Explain with AI

In a  binary tree with nn nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child?

Choose one option
View worked solution

Answer: A

Let D(u)D(u) denote the number of descendants of a node uu. By definition, a node is its own descendant, so we can express D(u)D(u) recursively as:

D(u)=1+D(uleft)+D(uright)D(u) = 1 + D(u_{\text{left}}) + D(u_{\text{right}})

where D(uleft)=0D(u_{\text{left}}) = 0 if the left child does not exist, and D(uright)=0D(u_{\text{right}}) = 0 if the right child does not exist.

We are given that for every node uu in the binary tree, D(u)D(u) must be an odd number. Let's analyze the three possible cases for any node uu:

  1. uu is a leaf node (0 children):
    D(u)=1+0+0=1D(u) = 1 + 0 + 0 = 1, which is odd. (Valid)
  2. uu has exactly two children:
    Since both children are nodes in the tree, their descendant counts D(uleft)D(u_{\text{left}}) and D(uright)D(u_{\text{right}}) must both be odd.
    D(u)=1+odd+odd=oddD(u) = 1 + \text{odd} + \text{odd} = \text{odd}, which is odd. (Valid)
  3. uu has exactly one child:
    Without loss of generality, let uu have only a left child. Since the left child is a node, its descendant count D(uleft)D(u_{\text{left}}) must be odd.
    D(u)=1+D(uleft)+0=1+odd=evenD(u) = 1 + D(u_{\text{left}}) + 0 = 1 + \text{odd} = \text{even}.
    This contradicts the given condition that D(u)D(u) must be odd for every node.

Thus, no node in the tree can have exactly one child. The number of such nodes is 00.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Trees questions