Graph Theory37 sections · 1633 units
Open in Course

Detecting Negative Cycles

(The $n$-th iteration)

After n1n-1 iterations, all shortest paths are finalized if no negative cycle exists. Any simple path has been fully explored. Run one more iteration (the nn-th round). If any distance improves, a negative cycle exists. Why?

Because improving a distance in the nn-th round means there is a path with nn or more edges that is better than the path with n1n-1 edges.

A path with nn edges in a graph with nn nodes must contain a cycle. If this path is shorter, the cycle must have negative total weight. You can traverse this cycle repeatedly to make the path arbitrarily short.