You are on page 1of 1

Bellman-Ford algorithm

BellmanFord(G,s):
1 for eachvertex v G.V - {s}
2
v.d =
3 v.pred = null
4 s.d = 0
5 for i from 1 to |G.V| - 1
6
foreach edge (u,v) G.E
7 if u.d + (u,v).w < v.d
8
v.d = u.d + (u,v).w
9 v.pred = u
10 for eachedge (u,v) G.E
11
ifu.d + (u,v).w < v.d
12 error"negative-weight cycle"

You might also like