Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 56→99, 87→4, 99→31, 75→56, 87→83, 56→66, 87→13, 4→92, 87→75, 92→5. 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. 5
  2. B. 3
  3. C. 10
  4. D. 4

Correct answer: D. 4

Height counts edges from the root down to the deepest leaf, here 4. 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