Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
In the undirected connected graph on vertices 0 to 9 with edges 0-1, 0-4, 0-5, 1-2, 1-5, 1-6, 1-7, 2-3, 2-8, 3-7, 3-8, 3-9, 4-9, how many vertices are at distance exactly 3 from vertex 0? Distance means the fewest edges.
- A. 10
- B. 4
- C. 2
- D. 0
Correct answer: C. 2
A BFS from vertex 0 assigns each vertex its level. The question asks for one level only, not the cumulative count up to that level.
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
- In the undirected connected graph on vertices 0 to 9 with edges 0-1, 0-2, 0-3, 1-4, 2-4, 3-5, 3-6, 3-7, 3-8, 4-8, 5-8, 6-9, how many…
- A rooted tree on vertices 0 to 10 has parent[i] = [0, 0, 0, 1, 3, 5, 2, 5, 4, 8] for i = 1 to 10 (vertex 0 is the root). What is the sum…
- A rooted tree on vertices 0 to 10 has parent[i] = [0, 0, 0, 2, 0, 3, 3, 7, 6, 1] for i = 1 to 10 (vertex 0 is the root). What is the sum…
- A rooted tree on vertices 0 to 10 has parent[i] = [0, 0, 0, 2, 2, 1, 1, 1, 1, 5] for i = 1 to 10 (vertex 0 is the root). What is the sum…
- A rooted tree on vertices 0 to 10 has parent[i] = [0, 1, 1, 1, 1, 2, 1, 1, 8, 5] for i = 1 to 10 (vertex 0 is the root). What is the sum…
- A rooted tree on vertices 0 to 11 has parent[i] = [0, 1, 0, 2, 3, 0, 5, 7, 0, 8, 1] for i = 1 to 11 (vertex 0 is the root). What is the…