Bellman Ford Visualizer

Paste directed weighted edges, keep negative weights, then step through Bellman-Ford relaxation passes and negative-cycle detection.

Nodes
6
Edges
8
Pass
0
Distance
unreached

Directed graph input

Use one directed edge per line: source, target, weight. Negative weights are kept.

Step controls

Start at S. Its distance is 0 and every other node is unreached.

Relaxation graph

Blue marks a successful relaxation. Red marks a negative-cycle witness.

Reached Current Path
Bellman-Ford graph diagramDirected weighted graph with 6 nodes and 8 edges.45-13-26310Ad=unreachedBd=unreachedCd=unreachedDd=unreachedEd=unreachedSd=0

Distance table

NodeDistancePreviousStatus
Aunreached-unreached
Bunreached-unreached
Cunreached-unreached
Dunreached-unreached
Eunreached-unreached
S0-reached

Shortest path output

pass = 0
negative_cycle = false
distance = unreached
path = unreachable

What is a Bellman Ford Visualizer?

A Bellman Ford visualizer shows how shortest-path distances change after repeated edge relaxation passes. It is useful for learning negative edge weights, negative cycle detection, routing tables, dynamic programming over edges, and graph interview problems.

This tool lets you paste directed weighted edges, choose a start and target node, then step through every pass until distances stabilize or a negative cycle is detected.

For the full graph and data structure set, browse the Data Structure Visualizers hub.

How to use this Bellman Ford visualizer

  • Paste one directed weighted edge per line, such as S A 4 or A -> B -2.
  • Enter a start node and target node.
  • Click Run Bellman-Ford to jump to the final state.
  • Use the step controls to inspect each relaxation and pass summary.
  • Watch the distance table, predecessor chain, and highlighted edge update.

Bellman Ford vs Dijkstra

Dijkstra is faster on graphs with non-negative weights, but it does not support negative weights. Bellman-Ford is slower because it relaxes every edge for up to V - 1 passes, but it can handle negative edges and detect reachable negative cycles.

Compare this page with the Dijkstra Algorithm Visualizer for non-negative weighted graphs, the Floyd Warshall Visualizer for all-pairs shortest paths, or the A Star Pathfinding Visualizer for heuristic-guided grid search.

Frequently Asked Questions

What input format does this Bellman Ford visualizer use?
Paste one directed weighted edge per line with source, target, and weight, such as S A 4 or A -> B -2.
Can Bellman-Ford use negative edge weights?
Yes. Bellman-Ford supports negative edge weights as long as no reachable negative cycle makes the shortest path undefined.
How does this tool detect a negative cycle?
After V - 1 relaxation passes, the tool checks every edge one more time. If any reachable edge can still improve a distance, a negative cycle is reachable from the start node.
When should I use Bellman-Ford instead of Dijkstra?
Use Bellman-Ford when a graph can contain negative edge weights or when you need explicit negative cycle detection.

Related tools