Skip to content
Official PYQ · 1998

GATE CS 1998 Q2.11 — Trees

Explain with AI

A complete nn-ary tree is one in which every node has 00 or nn sons. If xx is the number of internal nodes of a complete nn-ary tree, the number of leaves in it is given by

Choose one option
View worked solution

Answer: A

To find the number of leaves LL in a complete nn-ary tree with xx internal nodes, we can use the relationship between the total number of nodes, internal nodes, and edges.

Method 1: Using Node and Edge Relations

  1. Let NN be the total number of nodes in the tree. Since every node is either an internal node or a leaf, we have: N=x+LN = x + L
  2. In a complete nn-ary tree, every internal node has exactly nn children. Therefore, the total number of children in the tree is n⋅xn \cdot x.
  3. Since every node in the tree except the root is a child of some node, the total number of nodes is also given by: N=n⋅x+1N = n \cdot x + 1

Equating the two expressions for NN:

x+L=n⋅x+1x + L = n \cdot x + 1

Solving for LL:

L=n⋅x−x+1=x(n−1)+1L = n \cdot x - x + 1 = x(n - 1) + 1

Method 2: Verification with an Example

Let n=2n = 2 (a complete binary tree) and x=1x = 1 (only the root is an internal node, having 22 children).

  • The number of leaves LL is 22.
  • Substituting n=2n = 2 and x=1x = 1 into the options:
    • Option A: 1⋅(2−1)+1=21 \cdot (2 - 1) + 1 = 2 (Correct)
    • Option B: 1⋅2−1=11 \cdot 2 - 1 = 1
    • Option C: 1⋅2+1=31 \cdot 2 + 1 = 3
    • Option D: 1⋅(2+1)=31 \cdot (2 + 1) = 3

Thus, the correct option is A.

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

Published
Report a correction
Keep exploringMore Trees questions