CSE221 · Algorithms

Bellman-Ford Simulator

Repeatedly relax every edge, then catch a negative cycle on the final pass.

453-342A0B∞C∞D∞E∞

A starts at 0, everything else at ∞. Bellman-Ford relaxes every edge 4 times — one pass per possible path length.

step 1 of 21
edge being relaxedreached / in shortest-path treenegative weights in red
pass 0 of 4
Nodedistpred
A0—
B∞—
C∞—
D∞—
E∞—

Build your graph

→

Edges (6)

  • A → B(4)
  • A → C(5)
  • B → D(3)
  • C → B(-3)
  • C → D(4)
  • D → E(2)
Source node

Negative weights are allowed here — that is the whole point. Try building a cycle whose weights sum below zero and watch the check pass catch it.