Data Structures & AlgorithmsModerateGATE CS · ICPC regional
An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=9), 0-2 (w=6), 0-4 (w=10), 1-2 (w=2), 1-3 (w=3), 1-4 (w=9), 2-3 (w=7), 2-4 (w=1), 3-4 (w=4). The length of a path is the sum of its edge weights. What is the length of the shortest path from vertex 0 to vertex 3?
- A. 12
- B. 3
- C. 2
- D. 11
Correct answer: D. 11
Shortest weighted paths need Dijkstra (or a careful search), not the path with the fewest edges. The path found by breadth-first search may use heavy edges, so summing along it overstates the true distance.
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 undirected connected graph on vertices 0 to 6 has these weighted edges: 0-1 (w=11), 0-2 (w=11), 0-4 (w=2), 0-5 (w=6), 1-2 (w=7), 1-3…
- An undirected connected graph on vertices 0 to 6 has these weighted edges: 0-1 (w=11), 0-5 (w=4), 1-2 (w=2), 1-3 (w=1), 1-6 (w=2), 2-4…
- An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=10), 0-2 (w=2), 1-2 (w=1), 1-3 (w=7), 2-3 (w=8), 3-4…
- An undirected connected graph on vertices 0 to 5 has these weighted edges: 0-1 (w=7), 0-4 (w=9), 0-5 (w=1), 1-2 (w=7), 1-3 (w=7), 2-3…
- An undirected connected graph on vertices 0 to 7 has these weighted edges: 0-1 (w=11), 0-3 (w=8), 0-4 (w=11), 0-7 (w=7), 1-2 (w=4), 1-3…
- An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=10), 0-2 (w=10), 0-4 (w=9), 1-2 (w=1), 1-3 (w=9), 1-4…