GATE Computer ScienceHardGATE CS (PYQ pattern)

Bellman–Ford is run from A on a 6-vertex graph with directed edges relaxed in this fixed order in every pass: E→F 2, D→E 3, C→D 2, B→C 4, A→B 1, A→F 20. In how many passes does at least one distance label change?

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

Correct answer: C. 5

Each pass only extends the correct prefix of the chain A→B→C→D→E→F by one edge, because the edges appear in reverse path order: B, C, D, E and F are fixed in passes 1, 2, 3, 4 and 5 respectively. A sixth pass changes nothing, and V − 1 = 5 is the worst case, achieved here.

More Algorithms questions

Exams that ask this topic