Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 9→25, 58→82, 24→55, 77→41, 58→61, 24→63, 9→48, 61→9, 82→76, 48→77, 9→43, 43→33, 85→51, 25→24, 43→85. 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. 6
  2. B. 5
  3. C. 4
  4. D. 15

Correct answer: B. 5

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