Download - Bellman Ford Algorithm
![Page 1: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/1.jpg)
Bellman-Ford Algorithm
Dr.Jeevani GoonetillakeUCSC
![Page 2: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/2.jpg)
Bellman-Ford Algorithm
• Solves the single-source shortest paths problem in the general case in which the edge weights may be negative.
• Given a weighted directed graph G = (V,E) with source s and weight function w, the Bellman-Ford algorithm returns a boolean value indicating whether or not there is a negative-weight cycle that is reachable from the source.
![Page 3: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/3.jpg)
Bellman-Ford Algorithm
• If there 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.
![Page 4: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/4.jpg)
Bellman-Ford Algorithm
• Uses relaxation progressively decreasing an estimate d[v] on the weight of a shortest path from the source s to each vertex v V until it achieves the actual shortest path.
• Returns true if and only if the graph contains no negative weight cycles that are reachable from the source.
![Page 5: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/5.jpg)
Bellman-Ford Algorithm
Bellman-Ford (G,w,s)INITIALIZE-SINGLE-SOURCE(G,s)for i 1 to |V[G]| - 1 do for each edge (u,v) E[G] do RELAX (u,v,w)for each edge (u,v) E[G] do if d[v] > d[u] + w(u,v) then return FALSEreturn TRUE
![Page 6: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/6.jpg)
Bellman-Ford Algorithm5
-3
6
9
7
8
-2
7
2
x∞
t∞
z∞
y∞
-4s0
Each pass relaxes the edges in the order (t,x) , (t,y), (t,z), (x,t), (y,x),(y,z),(z,x),(z,s),(s,t),(s,y).
![Page 7: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/7.jpg)
Bellman-Ford Algorithm
5
-3
6
9
7
8
-2
7
2
x∞
t6
z∞
y7
s0
-4
![Page 8: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/8.jpg)
Bellman-Ford Algorithm
5
-3
6
9
7
8
-2
7
2
x4
t6
z2
y7
s0
-4
![Page 9: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/9.jpg)
Bellman-Ford Algorithm
5
-3
6
9
7
8
-2
7
2
x4
t2
z2
y7
s0
-4
![Page 10: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/10.jpg)
Bellman-Ford Algorithm
-3
6
9
7
8
-2
7
2
x4
t2
z-2
y7
s0
-4
![Page 11: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/11.jpg)
Bellman-Ford Algorithm
• Running Time is O(VE)
![Page 12: Bellman Ford Algorithm](https://reader031.vdocument.in/reader031/viewer/2022012311/5450bec1b1af9f0d098b4e3e/html5/thumbnails/12.jpg)
Linear Programming
• In the general linear programming problem , we are given an m x n matrix A, an m-vector b, and an n-vector c.
• We wish to find a vector x of n elements that maximizes the objective function CT xi
subject to m constraints given by Ax ≤ b.