Practice free →
HomeGATE CSEcomputerscienceAlgorithms › Why does Bellman-Ford run exactly V − 1 outer it…

Why does Bellman-Ford run exactly V − 1 outer iterations on a graph with V vertices?

AV − 1 is the lower bound for any shortest-path algorithm
Bthe priority queue holds V − 1 elements at most
Cany shortest path has at most V − 1 edges, so V − 1 passes suffice
DV − 1 matches the number of edges in a spanning tree
Answer & Solution
Correct answer: C. any shortest path has at most V − 1 edges, so V − 1 passes suffice
A simple shortest path can repeat no vertex, so it has at most V − 1 edges. After k passes of relax-every-edge, all shortest paths of ≤ k edges are correctly computed. By pass V − 1, every reachable vertex has its true shortest distance. A V-th pass that still relaxes means a negative cycle exists.
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions