Data Structures & AlgorithmsModerateCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 46→68, 40→41, 76→83, 83→95, 83→49, 40→22, 95→46, 68→40. The root is at depth 0. How many nodes lie at depth exactly 3?

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

Correct answer: C. 1

Count the nodes whose depth is exactly 3, by computing each node's depth from the root. Off-by-one on the depth, or counting cumulatively, gives the trap values.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic