Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita
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 at depth 0. How many nodes lie at depth exactly 3?
- A. 3
- B. 2
- C. 7
- D. 1
Correct answer: D. 1
Count the nodes whose depth is exactly 3, by computing each node's depth from the root. Off-by-one on the depth, or counting cumulatively, gives the trap values.
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
- 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…
- Distinct keys are inserted one by one, in the order 84 43 68 61 70 58 73 94, into an empty binary search tree (a smaller key goes to the…
- Distinct keys are inserted one by one, in the order 62 76 83 50 90 49 38, into an empty binary search tree (a smaller key goes to the…