Download presentation

Presentation is loading. Please wait.

Published byEric Burns Modified over 2 years ago

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

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google