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

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

  1. A. 3
  2. B. 0
  3. C. 2
  4. D. 6

Correct answer: C. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic