vimwiki/tech/Bellman-Ford.wiki

29 lines
611 B
Plaintext

= Bellman Ford =
Bellman ford is an algorithm for finding the shortest path from some node to
all other nodes in a weighted graph
== PsuedoCode ==
Input: directed graph _G=(V,E)_;
Edge lengths contained in the set _E_ with no negative cycles; Edge is _e_;
_s_ contained in _V_;
Output: For all verticies _u_ reachable from _s_, `dist(u)` is set to the
distance from _s_ to _u_
{{{
for all u in V:
dist(u) = inf
prev(u) = null
dist(s) = 0
repeat |V| - 1 times:
for all e contained in E:
update(e)
update((u,v) in e):
dist(v) = min(dist(v), dist(u) + length of dist between u and v)
}}}