Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: In the tree with edges 1-2, 1-3, 2-4, 2-5, 3-6, 3-7, what is the number of leaves (nodes with degree 1)?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

Count vertices of degree one by building the degree table from the edge list. The root 1 has degree two, so it is not counted as a leaf even though it is the top of the tree.

More Coding Interview Problems questions

Exams that ask this topic