GATE Computer ScienceVery hardGATE CSE

Bellman–Ford from source 0 on vertices 0..5 relaxes the directed edges (u→v, w) in this fixed order in every pass: 4→5 (1), 3→4 (1), 2→3 (1), 1→2 (1), 0→1 (1), 0→5 (10). In how many passes does at least one distance change?

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

Correct answer: D. 5

The path 0→1→2→3→4→5 is discovered one edge per pass against the edge order, and 0→5 only gives the initial value in pass 1; changes occur in 5 passes.

More Algorithms questions

Exams that ask this topic