← 🧮 Algorithms & AI

🧮 Bellman–Ford

Introduce negative cycle
Iteration: 0 /
Edge relaxed:
Status: Ready
FPS:
⚠ Negative-weight cycle detected — shortest paths through it are undefined (can be decreased forever).
Drag — rotate · Scroll — zoom

🧮 Bellman–Ford Algorithm Explained

A 3D directed weighted graph — including negative-weight edges — where each edge relaxation step animates live, building a shortest-path tree from a golden source node, with a toggle to introduce a negative cycle and watch the algorithm detect it on the extra verification pass.

🔬 What It Demonstrates

Bellman–Ford relaxes every edge in the graph up to V−1 times, updating each node's shortest known distance from the source. A final Vth pass checks whether any edge can still relax — if so, a negative-weight cycle exists and no finite shortest path is defined.

🎮 How to Use

Pick a preset graph, or flip on "Introduce negative cycle" to add a back-edge that creates one. Press Play to auto-run edge relaxations, or Step through them one at a time. Teal edges show the current shortest-path tree; red edges carry negative weight.

💡 Did You Know?

Distance-vector routing protocols like RIP are essentially distributed, gossip-based versions of Bellman–Ford — each router relaxes its known distances using updates from its neighbours, round after round.