Data Structures & AlgorithmsModerateGATE CS · Product-company placement

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

  1. A. 35
  2. B. 34
  3. C. 22
  4. D. 42

Correct answer: A. 35

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic