The Bellman-Ford algorithm has the running time of O(mn) since there are O(n) iterations, and each iteration takes O(m) time. The correctness follows from the fact that in the kth iteration, the shortest-path estimate for each vertex equals the length of the shortest path from the source
to that vertex with at most k edges. Since a simple path in G contains at most n − 1 edges, the shortest-path estimates stabilize after n − 1 iterations unless there exists a negative cycle in the
graph.
The following figures show how the execution of the Bellman-Ford works on the graph in
Figure 15. The dark dotted edges record those that do cause some effect in the relaxation. Initially,