Data Structures & AlgorithmsModerateGATE CS · Product-company placement

A rooted tree has 6 nodes with 1 child, 6 nodes with 2 children, 3 nodes with 3 children, and every other node is a leaf. How many leaves does it have?

  1. A. 12
  2. B. 13
  3. C. 16
  4. D. 19

Correct answer: B. 13

Edges = nodes − 1 counted two ways: Σ i·nᵢ = (n₀ + Σ nᵢ) − 1, so n₀ = 1 + Σ (i − 1)·nᵢ = 13. Nodes with one child add nothing.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic