Data Structures & AlgorithmsModerateGATE CS · ICPC regional

An undirected connected graph on vertices 0 to 4 has these weighted edges: 0-1 (w=12), 0-2 (w=10), 0-3 (w=11), 1-2 (w=12), 1-4 (w=4), 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 4?

  1. A. 4
  2. B. 15
  3. C. 16
  4. D. 2

Correct answer: B. 15

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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic