0% found this document useful (0 votes)
261 views

Bellman Ford Algorithm

The Bellman-Ford algorithm solves the single-source shortest paths problem for graphs with negative edge weights. It either finds the shortest paths from the source node to all other nodes, or detects if a negative weight cycle is reachable from the source. The algorithm works by progressively relaxing edges to refine the distance estimates over multiple iterations, until it converges on the actual shortest paths after at most V-1 iterations, where V is the number of vertices. It returns true only if there are no negative weight cycles reachable from the source.

Uploaded by

dinuniroxx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
261 views

Bellman Ford Algorithm

The Bellman-Ford algorithm solves the single-source shortest paths problem for graphs with negative edge weights. It either finds the shortest paths from the source node to all other nodes, or detects if a negative weight cycle is reachable from the source. The algorithm works by progressively relaxing edges to refine the distance estimates over multiple iterations, until it converges on the actual shortest paths after at most V-1 iterations, where V is the number of vertices. It returns true only if there are no negative weight cycles reachable from the source.

Uploaded by

dinuniroxx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Bellman-Ford Algorithm

Dr.Jeevani Goonetillake UCSC

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 BellmanFord algorithm returns a boolean value indicating whether or not there is a negativeweight cycle that is reachable from the source.

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.

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.

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 FALSE return TRUE

Bellman-Ford Algorithm
5 6 s 0 7 8 2 y 9 z

-2
-4 -3

x 7

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).

Bellman-Ford Algorithm
5 -2
-4 s 0 7

t 6
6

8
2 y 7 9

-3

Bellman-Ford Algorithm
5 -2
-4 s 0 7

t 6
6

x 4

8
2 y 7 9

-3

z 2

Bellman-Ford Algorithm
5 -2
-4 s 0 7

t 6
2

x 4

8
2 y 7 9

-3

z 2

Bellman-Ford Algorithm

t 6 s 0 7
2

-2 -4

x 4

8
2 y 7 9

-3

z -2

Bellman-Ford Algorithm
Running Time is O(VE)

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.

You might also like