"Dijkstra trusts that getting farther can only cost more. Negative edges break that trust. Bellman-Ford is the patient, slower algorithm that makes no such assumption — and can even detect when 'cheapest' has no answer at all."
The Case Dijkstra Can't Handle
Some edges genuinely have negative weights: a currency exchange that nets a gain, a financial flow that's a credit, a game move that restores health. Dijkstra fails here because its core assumption — finalizing the closest node is safe — relies on every edge adding cost. A negative edge could let a node you'd already finalized be reached more cheaply later. Bellman-Ford drops that assumption entirely, at the price of being slower.
The Algorithm: Relax Everything, V−1 Times
Bellman-Ford is almost brutally simple: relax every edge in the graph, and repeat that V−1 times. 'Relax edge u→v' means: if reaching v through u is cheaper than v's current distance, update it. Why exactly V−1 rounds? Because a shortest path in a graph of V nodes uses at most V−1 edges, and each full round of relaxing all edges guarantees correct distances propagate one more edge outward from the source. After V−1 rounds, every shortest path (at most V−1 edges long) has been fully resolved. It's O(V·E) — slower than Dijkstra's O((V+E) log V) — but it tolerates negatives.
The Superpower: Negative-Cycle Detection
Bellman-Ford detects a negative cycle reachable from the source when a reachable edge can still relax after V−1 rounds. Only vertices reachable from such a cycle lose a finite shortest distance; unrelated vertices do not. For currency arbitrage, transform a rate r to weight -log(r) so a profitable product becomes a negative sum.