Bellman-Ford
General information
Algorithmic problem: All pairs shortest paths
Prerequisites:
Type of algorithm: loop
Auxiliary data:
- A real-valued
matrix , where . The eventual contents of will be returned as the result of the algorithm. - A real-valued
matrix , where . This matrix represents the graph and the arc lengths and will not be changed throughout the algorithm.
Notation:
On this page,
Abstract view
Invariant: After
Variant:
Break condition:
Induction basis
Abstract view: For all
; if ; , if and .
Induction step
Abstract view: For all
(Note that
Implementation: Obvious.
Correctness: Follows from the fact that a shortest path cannot have more than
Complexity
Statement: The asymptotic complexity is
Proof: The main loop terminates after