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?
- A. 4
- B. 5
- C. 2
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A rooted tree has these parent→child edges: 63→96, 16→83, 53→7, 48→51, 26→53, 16→84, 96→48, 7→16, 51→98, 26→63. The root is at depth 0…
- A rooted tree has these parent→child edges: 24→82, 24→60, 22→26, 82→59, 65→24, 71→23, 26→71, 65→22, 26→47, 75→65. The root is at depth 0…
- A rooted tree has these parent→child edges: 6→95, 80→51, 95→50, 8→56, 51→10, 6→3, 95→80, 8→6, 6→47. The root is at depth 0. What is the…
- A rooted tree has these parent→child edges: 59→82, 98→34, 2→77, 2→55, 20→2, 77→57, 55→98, 20→43, 55→59. The root is at depth 0. What is…
- A rooted tree has these parent→child edges: 68→74, 58→43, 68→48, 48→90, 68→42, 42→61, 43→34, 74→58. The root is at depth 0. What is the…
- A rooted tree has these parent→child edges: 77→73, 73→6, 70→16, 73→65, 6→80, 65→70, 70→45, 16→82. The root is at depth 0. What is the…