Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 42→51, 39→96, 32→33, 39→91, 96→32, 90→12, 90→73, 33→46, 28→80, 42→26, 32→90, 12→27, 73→28, 91→42. The root is at depth 0. What is the height of the tree, meaning the number of edges on its longest root-to-leaf path?

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

Correct answer: C. 6

Height counts edges from the root down to the deepest leaf, here 6. Counting nodes on that path gives one more, and the number of leaves is a different quantity.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic