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?
- A. 8
- B. 4
- C. 7
- 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.
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: 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…
- A rooted tree has these parent→child edges: 60→27, 28→77, 77→32, 60→64, 32→60, 32→86, 86→30, 77→76. The root is at depth 0. How many nodes…
- A rooted tree has these parent→child edges: 92→67, 4→89, 92→4, 78→54, 71→70, 54→57, 71→96, 70→10, 93→92, 22→78, 93→71, 70→22. The root is…
- A rooted tree has these parent→child edges: 42→51, 39→96, 32→33, 39→91, 96→32, 90→12, 90→73, 33→46, 28→80, 42→26, 32→90, 12→27, 73→28…
- A rooted tree has these parent→child edges: 23→29, 11→4, 9→55, 86→3, 21→36, 9→16, 16→39, 39→21, 9→86, 21→15, 36→33, 15→23, 9→8, 29→11. The…
- A rooted tree has these parent→child edges: 10→26, 60→44, 10→42, 26→60, 45→92, 60→40, 49→85, 10→20, 43→15, 26→72, 43→14, 60→43, 10→45…