Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bellman-Ford algorithm 2005160104. Page 2 Bellman-Ford algorithm Computes single-source shortest path in a weighted digraph. The faster Dijkstras algorithm.

Similar presentations


Presentation on theme: "Bellman-Ford algorithm 2005160104. Page 2 Bellman-Ford algorithm Computes single-source shortest path in a weighted digraph. The faster Dijkstras algorithm."— Presentation transcript:

1 Bellman-Ford algorithm

2 Page 2 Bellman-Ford algorithm Computes single-source shortest path in a weighted digraph. The faster Dijkstras algorithm also solves the problem. Used primarily for graphs with negative edge weights. Negative Cycle.

3 Page 3 Bellman-Ford algorithm procedure BellmanFord(list vertices, list edges, vertex source) for each vertex v in vertices: if v is source then v.distance := 0 else v.distance := infinity v.predecessor := null for i from 1 to size(vertices)-1: for each edge uv in edges: u := uv.source v := uv.destination if u.distance + uv.weight < v.distance: v.distance := u.distance + uv.weight v.predecessor := u for each edge uv in edges: u := uv.source v := uv.destination if u.distance + uv.weight < v.distance: error "Graph contains a negative-weight cycle"

4 Page 4 Bellman-Ford algorithm S D 15

5 Page 5 Bellman-Ford algorithm

6 Page 6 Bellman-Ford algorithm Demonstration


Download ppt "Bellman-Ford algorithm 2005160104. Page 2 Bellman-Ford algorithm Computes single-source shortest path in a weighted digraph. The faster Dijkstras algorithm."

Similar presentations


Ads by Google