Math 2.0

Combinatorics Definition

Bellman–Ford algorithm

Builds on Directed graphPathCycleAlgorithm

Definition

Let G=(V,E)G = (V, E) be a finite directed graph with nn vertices, let w ⁣:E→ℝw \colon E \to \R be a weight function, and let s∈Vs \in V be a source vertex. The Bellman–Ford algorithm is the following algorithm.

  1. Set d(s)=0d(s) = 0 and d(v)=∞d(v) = \infty for every vertex v≠sv \ne s.
  2. Repeat n−1n - 1 times: for each edge (u,v)∈E(u, v) \in E, if d(u)+w(u,v)<d(v)d(u) + w(u, v) < d(v), set d(v)=d(u)+w(u,v)d(v) = d(u) + w(u, v); this step is called a relaxation of the edge.
  3. Then, for each edge (u,v)∈E(u, v) \in E, if d(u)+w(u,v)<d(v)d(u) + w(u, v) < d(v), report that a cycle of negative total weight is reachable from ss.

If no such cycle is reported, the output d(v)d(v) is the least total weight of a directed path from ss to vv. In that case d(v)=∞d(v) = \infty exactly when no path from ss to vv exists.

Remarks

Example: take V={s,a,b}V = \set{s, a, b} with w(s,a)=4w(s, a) = 4, w(s,b)=1w(s, b) = 1 and w(b,a)=−2w(b, a) = -2. After the first round, if the edges are scanned in the order (s,a),(s,b),(b,a)(s, a), (s, b), (b, a), one has d(s)=0d(s) = 0, d(b)=1d(b) = 1 and d(a)=−1d(a) = -1. The check in step 3 reports nothing, so the shortest distance from ss to aa is −1-1.

Non-example of the conclusion: if the edges a→ba \to b of weight 11 and b→ab \to a of weight −2-2 form a cycle reachable from ss, the cycle has weight −1-1. Going around it lowers the weight without bound, so no shortest walk exists, and step 3 reports the cycle.

The correctness rests on the fact that after kk rounds, d(v)d(v) is at most the least weight of a walk from ss to vv with at most kk edges. The running time is O(nm)O(nm), where m=∣E∣m = \abs{E}.

Reading path

To understand this page from the ground up, read these 5 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Algorithm concept
  2. Cycle concept
  3. Directed graph concept
  4. Path concept
  5. Bellman–Ford algorithm definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
About this page
TagYK3AHP1SSS
URIm2://YK3AHP1SSS
Kinddefinition
WritingW0 stub
MSC05C85, 90C35, 68W40
DefinesBellman–Ford algorithm
UsesDirected graph, Path, Cycle, Algorithm
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.