Papers
Topics
Authors
Recent
Search
2000 character limit reached

Bellman-Ford Algorithm Overview

Updated 4 July 2026
  • Bellman–Ford algorithm is a classical method for computing single-source shortest paths in weighted graphs, even with negative edge weights.
  • It iteratively relaxes edges over up to n-1 rounds to update distances and detect reachable negative cycles, ensuring correctness in the absence of negative cycles.
  • The algorithm serves as a baseline for various extensions including hop-bounded approaches, reweighting techniques, and generalized dynamic programming templates.

The Bellman–Ford algorithm is a classical algorithm for the single-source shortest-paths problem on a directed weighted graph G=(V,E)G=(V,E) with source ss, where edge weights may be negative and shortest paths are well-defined only if no negative cycle is reachable from the source. It repeatedly relaxes edges and computes exact distances in O(mn)O(mn) time, equivalently O(VE)O(VE), which has made it the canonical general-purpose baseline for negative-weight SSSP and the reference point for later attempts to improve worst-case complexity (Elmasry, 2024, Atalig et al., 6 Aug 2025).

1. Problem model and dynamic-programming formulation

In the standard formulation, Bellman–Ford maintains tentative distances from ss to every vertex. The textbook initialization is

d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,

and the primitive operation is edge relaxation: for an arc (u,v)(u,v),

if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).

A round-based dynamic-programming view writes di(v)d_i(v) for the length of a shortest path from ss to ss0 using at most ss1 edges, with

ss2

and, for ss3,

ss4

Computing one layer from the previous one takes ss5 time by scanning all edges, and repeating this process for successive hop budgets yields the classical ss6 running time (Elmasry, 2024, Kociumaka et al., 2022).

This recurrence expresses the Bellman optimality principle in its additive shortest-path form: a shortest path to ss7 with at most ss8 edges either already uses at most ss9 edges, or its last edge is some O(mn)O(mn)0 whose prefix to O(mn)O(mn)1 uses at most O(mn)O(mn)2 edges. The algorithm is therefore both a shortest-path method and a layered dynamic program over path length (Kociumaka et al., 2022).

2. Correctness, simple paths, and negative-cycle detection

Bellman–Ford’s correctness rests on the fact that, in a graph without reachable negative cycles, every shortest path can be taken to be simple and therefore has at most O(mn)O(mn)3 edges. After the O(mn)O(mn)4-th full pass over the edges, all vertices whose shortest paths use at most O(mn)O(mn)5 edges have correct labels. Consequently, after O(mn)O(mn)6 passes, all shortest-path distances are correct (1111.07325).

Negative-cycle detection is integrated into the standard algorithm by performing one additional full pass after the first O(mn)O(mn)7 passes. If any label can still be decreased, then some negative cycle is reachable from the source. This mechanism is the classical certificate that the shortest-path problem is undefined in the usual sense for that source-reachable region (1111.07325).

The same recurrence also explains why Bellman–Ford applies beyond the ordinary source-to-all setting. Restricting the outer loop to O(mn)O(mn)8 rounds computes shortest paths that use at most O(mn)O(mn)9 edges, which is the standard hop-bounded formulation. This observation underlies both lower-bound work and several later generalizations of the algorithmic template (Kociumaka et al., 2022).

3. Complexity, scan order, and non-adaptive relaxational models

The standard non-adaptive dense-graph implementation relaxes every edge in each of O(VE)O(VE)0 rounds, giving

O(VE)O(VE)1

relaxations on the complete digraph. Yen’s 1970 improvement partitions edges into forward and backward acyclic sets under a fixed vertex order and alternates topological sweeps, reducing the dense-graph count to

O(VE)O(VE)2

A randomized variant that keeps Yen’s two-DAG schedule but chooses the vertex numbering uniformly at random with the source first achieves at most

O(VE)O(VE)3

relaxations in expectation, with corresponding dense-graph expectation O(VE)O(VE)4 (Hu et al., 2024, Bannister et al., 2011).

Variant Bound in the dense regime Main point
Standard non-adaptive Bellman–Ford O(VE)O(VE)5 relaxations Full edge scan in each round
Yen’s improvement O(VE)O(VE)6 relaxations Forward/backward acyclic sweeps
Randomized Yen-style ordering expected O(VE)O(VE)7 relaxations Random permutation reduces alternations
Deterministic lower bound for non-adaptive schedules O(VE)O(VE)8 relaxations Yen is asymptotically optimal in this model

The dense-graph lower-bound story is now sharp for deterministic non-adaptive schedules: every deterministic non-adaptive relaxation-based algorithm on the complete digraph requires

O(VE)O(VE)9

relaxations, establishing Yen’s improvement as asymptotically optimal in that model (Hu et al., 2024). More broadly, lower bounds for non-adaptive shortest-path relaxation show ss0 on complete directed graphs, ss1 when ss2, and ss3 in general sparse regimes, so Bellman–Ford is asymptotically optimal for dense graphs and near-optimal for sparse graphs within the non-adaptive relaxation framework (Eppstein, 2023).

4. Hop-bounded Bellman–Ford and conditional optimality

One of Bellman–Ford’s most basic dynamic-programming interpretations is the shortest hop-bounded path problem: given ss4, ss5, and a hop bound ss6, compute the length of a shortest ss7-ss8 path using at most ss9 edges. The Bellman–Ford recurrence solves this in d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,0 time by truncating the number of rounds to d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,1 (Kociumaka et al., 2022).

Recent fine-grained lower bounds show that this d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,2 dependence is conditionally optimal up to subpolynomial factors, even in undirected graphs with non-negative edge weights. Under the APSP Hypothesis, there is neither an d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,3-time algorithm nor an d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,4-time algorithm for arbitrary d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,5; under the stronger Min-Plus Convolution Hypothesis, the same conclusion extends to the full parameter range. This establishes Bellman–Ford’s round-based dynamic program as the correct complexity benchmark for hop-bounded shortest paths, rather than merely a classical baseline (Kociumaka et al., 2022).

This result also clarifies a common misconception. Improvements for negative-weight SSSP do not automatically transfer to all Bellman–Ford-style tasks. In the hop-bounded setting, even the benign combination of undirected graphs and non-negative weights does not permit a polynomial-factor improvement over the Bellman–Ford recurrence under the cited hypotheses (Kociumaka et al., 2022).

5. Reweighting, attempts to beat the d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,6 barrier, and their correction

A major line of work reinterprets Bellman–Ford through potentials and reduced costs. Given a potential d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,7, reduced weights take the Johnson-style form

d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,8

For any path d[s]=0,d[v]= for vs,d[s]=0,\qquad d[v]=\infty \ \text{for } v\neq s,9,

(u,v)(u,v)0

so shortest paths between fixed endpoints are preserved under reweighting. If one can construct a potential that makes every reduced weight nonnegative, then a final Dijkstra computation suffices (Elmasry, 2024).

A 2024 paper claimed to “break the Bellman-Ford bound” by converting a graph with negative weights into one with nonnegative weights using at most

(u,v)(u,v)1

calls to a modified Dijkstra algorithm, leading to

(u,v)(u,v)2

time with Fibonacci heaps. Its progress analysis tracked “snakes,” maximal zero-weight segments followed by one negative edge, and argued that these structures grow quickly enough to force only (u,v)(u,v)3 alternating iterations (Elmasry, 2024).

That claimed deterministic breakthrough was later refuted. The refutation showed that the runtime analysis is incorrect, not that the computed shortest paths are wrong. In particular, it constructed a family of weighted DAGs (u,v)(u,v)4 with

(u,v)(u,v)5

on which the algorithm performs (u,v)(u,v)6 iterations; since each iteration costs (u,v)(u,v)7, the total runtime is

(u,v)(u,v)8

The structural flaw is that shortest nbp-paths need not extend monotonically: a minimizing path to one vertex need not extend the minimizing path to its predecessor, so a negative edge can remain negative after reweighting even when the snake argument predicts otherwise (Atalig et al., 6 Aug 2025).

At the same time, randomized progress on negative-weight SSSP has continued. A 2025 result gives an expected-time randomized algorithm running in

(u,v)(u,v)9

and a 2026 dense-graph result achieves

if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).0

time for directed graphs with real-valued possibly negative edge weights. These developments preserve Bellman–Ford as the conceptual benchmark while showing that the if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).1 barrier is not absolute in the randomized or dense-graph regimes (Rao, 28 Mar 2025, Li et al., 18 Feb 2026).

6. Bellman–Ford as a general algorithmic template

Bellman–Ford has also become a template for broader dynamic-programming and algebraic constructions. One generalization replaces additive edge-weight path cost by an arbitrary path function if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).2 on a path system if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).3, and defines the generalized single-source shortest path problem by minimizing if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).4 over if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).5 for every terminal if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).6. The resulting extended Moore–Bellman–Ford algorithm uses the update

if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).7

and runs in if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).8 time when evaluating if d[v]>d[u]+(u,v), then d[v]d[u]+(u,v).\text{if } d[v] > d[u] + \ell(u,v),\text{ then }d[v]\gets d[u]+\ell(u,v).9 takes di(v)d_i(v)0 time, provided di(v)d_i(v)1 is order-preserving and has no negative circles (Cheng, 2017).

A second line of generalization lifts Bellman–Ford from ordinary graphs to hyper-graphs arising in symbolic optimal control. There the Bellman operator is

di(v)d_i(v)2

and a generalized Bellman–Ford algorithm computes the value function with di(v)d_i(v)3 time, where

di(v)d_i(v)4

A later modification tracks which successors currently realize the relevant supremum and reactivates only predecessor states that depend on them, reducing the number of processed nodes per iteration while preserving the same Bellman-style fixed-point objective (Weber et al., 2020, Kreuzer et al., 29 Jan 2025).

More abstractly, Bellman–Ford can be viewed as iterative propagation over semirings and semimodules. In that algebraic view, classical shortest paths correspond to the min-plus semiring, while widest paths, multi-source propagation, and related “MBF-like” algorithms arise by changing the aggregation and extension operators (Friedrichs et al., 2015). The same viewpoint motivates “Neural Bellman-Ford Networks,” which reinterpret Bellman–Ford as a learned path-aggregation architecture with three components—INDICATOR, MESSAGE, and AGGREGATE—for link prediction on graphs and knowledge graphs (Zhu et al., 2021).

These extensions underscore a final point. Bellman–Ford is not only the classical negative-weight shortest-path algorithm; it is also a durable computational pattern: iterative relaxation, path extension, and aggregation under a monotone progress invariant. That pattern continues to reappear in lower-bound theory, reweighting-based SSSP, distributed computation, symbolic control, algebraic graph algorithms, and learned graph models (Friedrichs et al., 2015, Zhu et al., 2021).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Bellman-Ford Algorithm.