Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE

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

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 9

Correct answer: A. 3

Run Dijkstra from A: A=0, B=8, C=6, D=3, E=4, F=4. The fewest-edge path (BFS) is not necessarily the lightest.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic