next up previous
Next: Up: Previous:

Pseudocode

   Bellman-Ford(G, w, s)                   ANALYSIS
      Init-Single-Source(G, s)              O(V)
      for i = 1 to (|V| - 1)                O(VE)
         foreach (u,v) in E
            Relax(u, v, w)
      foreach edge (u,v) in E               O(E)
         if d(v) > d(u) + w(u,v)
         then return false
      return true
                                            -----
                                            O(VE)

Theorem 25.14

If Bellman-Ford returns true, then Gpred forms a shortest path tree, else there exists a negative weight cycle.


next up previous
Next: Up: Previous: