Data Structures & AlgorithmsHardICPC regional · GATE CS
An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-3, 0-4, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many different shortest paths (fewest edges) are there from vertex 2 to vertex 0?
- A. 2
- B. 3
- C. 15
- D. 1
Correct answer: B. 3
Count shortest paths with BFS: a vertex's count is the sum of the counts of its neighbours one level closer. Counting all simple paths, or just the BFS distance, does not answer the question.
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
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-2, 0-3, 0-4, 1-2, 1-4, 2-3, 2-4, 3-4. How many different…
- An unweighted undirected connected graph on vertices 0 to 6 has edges 0-1, 0-2, 0-3, 0-4, 1-3, 2-6, 3-4, 3-5, 3-6, 4-5, 4-6. How many…
- An unweighted undirected connected graph on vertices 0 to 7 has edges 0-1, 0-2, 0-4, 0-5, 1-5, 1-6, 2-3, 2-5, 2-7, 3-7, 4-6. How many…
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-2, 0-3, 0-4, 1-2, 1-3, 2-3, 2-4, 3-4. How many different…
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-2, 0-4, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many different…
- An unweighted undirected connected graph on vertices 0 to 4 has edges 0-1, 0-3, 0-4, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many different…