Data Structures & AlgorithmsModerateGATE CS · Product-company placement

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

  1. A. 41
  2. B. 42
  3. C. 27
  4. D. 49

Correct answer: B. 42

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic