Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

In the undirected graph with edges A–B:14, B–C:2, A–D:11, D–E:8, A–F:14, B–G:11, A–G:3, what is the shortest-path distance from A to B?

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

Correct answer: D. 14

Run Dijkstra from A: A=0, B=14, C=16, D=11, E=19, F=14, G=3. The fewest-edge path (BFS) is not necessarily the lightest.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic