Data Structures & AlgorithmsModerateCodeforces Div2 B · TCS CodeVita
A rooted tree has these parent→child edges: 24→10, 89→82, 17→89, 17→93, 89→66, 82→24, 93→25. The root is at depth 0. How many nodes lie at depth exactly 2?
- A. 3
- B. 2
- C. 1
- D. 6
Correct answer: A. 3
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: 17→9, 19→88, 90→17, 19→40, 40→25, 19→90. The root is at depth 0. What is the height of the…
- A rooted tree has these parent→child edges: 46→68, 40→41, 76→83, 83→95, 83→49, 40→22, 95→46, 68→40. The root is at depth 0. How many nodes…
- A rooted tree has these parent→child edges: 49→3, 95→70, 70→63, 93→64, 49→81, 19→25, 49→95, 95→19, 49→93, 64→37. The root is at depth 0…
- A rooted tree has these parent→child edges: 63→96, 16→83, 53→7, 48→51, 26→53, 16→84, 96→48, 7→16, 51→98, 26→63. The root is at depth 0…
- A rooted tree has these parent→child edges: 24→82, 24→60, 22→26, 82→59, 65→24, 71→23, 26→71, 65→22, 26→47, 75→65. The root is at depth 0…
- A rooted tree has these parent→child edges: 6→95, 80→51, 95→50, 8→56, 51→10, 6→3, 95→80, 8→6, 6→47. The root is at depth 0. What is the…