Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bellman-Ford algorithm

Similar presentations


Presentation on theme: "Bellman-Ford algorithm"— Presentation transcript:

1 Bellman-Ford algorithm
이동훈 1

2 Bellman-Ford algorithm
Computes single-source shortest path in a weighted digraph. The faster Dijkstra‘s algorithm also solves the problem. Used primarily for graphs with negative edge weights. Negative Cycle. 가중치와 짧은 경로를 가지고 계산. 다이젝스트라 알고리즘보다 문제를 빠르게 해결한다. 엣지의 가중치가 없는 그래프에서 주로 사용 사이클이 이루어지지 않는다.

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 error "Graph contains a negative-weight cycle" 1. 소스인 경우 거리를 0, 나머지는 무한대로 설정 2. 노드의 개수-1만큼 거리및가중치를 계산하여 최단거리를 찾는다. 3. negative-weight cycle 체크

4 Bellman-Ford algorithm
85 S 20 15

5 Bellman-Ford algorithm

6 Bellman-Ford algorithm
Demonstration


Download ppt "Bellman-Ford algorithm"

Similar presentations


Ads by Google