(Please see PDF link below)
def initSingleSource( V, E, src ): for v in V: v.d = ∞ src.d = 0 def ssspBellmanFord( V, E, w, src ): initSingleSource( V, E, src ) for i in 1 .. |V| - 1: for (u,v) in E: relaxEdge( u, v, w ) for (u,v) in E: if v.d > u.d + w( u, v ): return FALSE
def relaxEdge( u, v, w ): if v.d > u.d + w( u, v ): v.d = u.d + w( u, v ) v.parent = u def ssspDijkstra( V, E, w, src ): initSingleSource( V, E, src ) Q = new PriorityQueue( V ) while Q.notEmpty(): u = Q.popMin() for v in E.adj[ u ]: relaxEdge( u, v, w )