Data Structures & AlgorithmsModerateICPC regional · GATE CS
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 shortest paths (fewest edges) are there from vertex 4 to vertex 1?
- 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-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…
- Count the spanning trees of the simple graph on vertices 0 to 4 with edges 0-4, 1-2, 1-3, 2-3, 2-4. How many spanning trees does it have?
- Count the spanning trees of the simple graph on vertices 0 to 4 with edges 0-1, 0-2, 0-3, 0-4, 1-2, 1-3, 2-3, 2-4, 3-4. How many spanning…
- Count the spanning trees of the simple graph on vertices 0 to 4 with edges 0-1, 0-2, 1-2, 1-3, 1-4, 2-3, 2-4, 3-4. How many spanning trees…
- Count the spanning trees of the simple graph on vertices 0 to 5 with edges 0-1, 1-2, 1-3, 1-5, 2-3, 2-4, 2-5, 3-5, 4-5. How many spanning…