Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 78→90, 92→39, 23→38, 24→53, 39→97, 38→24, 78→92, 23→45, 97→54, 24→78. 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. 8
  2. B. 4
  3. C. 7
  4. D. 6

Correct answer: C. 7

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