Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita
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, 91→42. 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. 7
- B. 5
- C. 6
- D. 14
Correct answer: C. 6
Height counts edges from the root down to the deepest leaf, here 6. 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: 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…
- 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…
- 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…