Data Structures & AlgorithmsHardGATE CS · ICPC regional

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 (w=1), 1-5 (w=6), 1-7 (w=11), 2-3 (w=6), 2-6 (w=9), 4-6 (w=9), 5-7 (w=3). 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 5?

  1. A. 10
  2. B. 6
  3. C. 2
  4. D. 17

Correct answer: A. 10

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