Professional Documents
Culture Documents
Bellman Ford Algorithm
Bellman Ford Algorithm
Bellman Ford Algorithm
• The Bellman-Ford algorithm solves the single-source shortest-paths problem in the general
case in which edge weights may be negative. Bellman-Ford algorithm returns a boolean
value indicating whether or not there is a negative-weight cycle that is reachable from the
source. If there is such a cycle ,the algorithm indicates that no solution exists. If there is no
such cycle, the algorithm produces the shortest paths and their weights.
• The algorithm was first proposed by Alfonso Shimbel (1955), but is instead named
after Richard Bellman and Lester Ford, Jr., who published it in 1958 and 1956.
Which type of Algorithm?
Initializat 0 ∞ ∞ ∞ ∞ ∞ ∞
ion
1 0 6 5 5 ∞ ∞ ∞
2 0 3 3 5 5 4 ∞
3 0 1 3 5 2 4 7
4 0 1 3 5 0 4 5
5 0 1 3 5 0 4 3
6 0 1 3 5 0 4 3
TIME COMPLEXITY
• All the loops included in the algorithm:
• The initialization loop runs |V| times.
• The outer for loop runs |V| – 1 times.
• The inner loop runs |E| times for each iteration of the outer loop.
• The last loop runs for |E| times.