Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 49→3, 95→70, 70→63, 93→64, 49→81, 19→25, 49→95, 95→19, 49→93, 64→37. 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. 4
  2. B. 5
  3. C. 2
  4. D. 3

Correct answer: D. 3

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