Data Structures & AlgorithmsHardCodeforces Div2 B · TCS CodeVita
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 lie at depth exactly 3?
- A. 2
- B. 3
- C. 6
- D. 0
Correct answer: A. 2
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
- 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…
- 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…