Why it matters

Bellman-Ford handles negatives. Understanding shapes shortest-path options.

Advertisement

The architecture

Relax all edges V-1 times.

V-th iteration change indicates negative cycle.

Bellman-Ford algorithmRelax edgesV-1 iterationsDetect neg cycleV-th iterationResultshortest or cycleSPFA (Shortest Path Faster Algorithm): queue-based Bellman-Ford variant, often faster in practice
Bellman-Ford steps.
Advertisement

How it works end to end

SPFA: queue-based variant. Often faster in practice but same worst case.

Applications: negative weight graphs, arbitrage detection, currency exchange.

Cycle detection: essential for correctness.