Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita
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 root is at depth 0. How many nodes lie at depth exactly 2?
- A. 4
- B. 1
- C. 7
- D. 2
Correct answer: D. 2
Count the nodes whose depth is exactly 2, 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
- 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…
- 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…