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?
- A. 6
- B. 5
- C. 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.
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: 31→61, 9→42, 59→31, 30→86, 86→59, 82→9, 84→44, 30→2, 30→79, 77→17, 59→77, 59→82, 17→84, 61→72…
- A rooted tree has these parent→child edges: 7→80, 70→81, 53→7, 93→59, 93→53, 80→21, 15→17, 17→96, 15→70, 96→93, 70→5, 59→18. The root is…
- Distinct keys are inserted one by one, in the order 73 43 77 38 56 92, into an empty binary search tree (a smaller key goes to the left, a…
- Distinct keys are inserted one by one, in the order 86 89 26 11 73, into an empty binary search tree (a smaller key goes to the left, a…
- Distinct keys are inserted one by one, in the order 40 38 28 68 61, into an empty binary search tree (a smaller key goes to the left, a…
- Distinct keys are inserted one by one, in the order 31 45 91 79 26 76 52 36 87, into an empty binary search tree (a smaller key goes to…