GATE Computer ScienceHardGATE CS (PYQ pattern)

A directed graph has edges A→B 3, B→C −2, C→D 4, A→C 6, A→D 12, D→E 1, C→E 7, B→E 9. What is the length of the shortest walk from A to E that uses at most 3 edges?

  1. A. 6
  2. B. 8
  3. C. 12
  4. D. 10

Correct answer: B. 8

Bellman–Ford after k passes (each pass using the previous pass's labels) gives the best path with at most k edges: 12 for k = 2 (A→B→E), 8 for k = 3 (A→B→C→E). The overall shortest path A→B→C→D→E has length 6 but needs 4 edges.

More Algorithms questions

Exams that ask this topic