Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 63→96, 16→83, 53→7, 48→51, 26→53, 16→84, 96→48, 7→16, 51→98, 26→63. The root is at depth 0. How many nodes lie at depth exactly 4?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 10

Correct answer: A. 3

Count the nodes whose depth is exactly 4, 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