Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Bellman–Ford is run from source C on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→F (4), Q→A (4), A→K (3), C→K (8), F→Q (8), K→F (3), C→A (4), Q→K (1), K→C (5), F→C (8), K→A (6). One pass relaxes every arc once, in the listed order. Passes are repeated until a complete pass changes no distance. Counting the final pass that changes nothing, how many passes run in total?

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

Correct answer: C. 3

The last pass changes no distance, so it is counted; the passes before it changed something, 2 of them. The bound n − 1 = 4 counts only the passes needed in the worst case.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic