AlgoViz

Bellman-Ford Algorithm

Bellman-Ford finds shortest paths from a source node to all other nodes, even with negative edge weights. It can detect negative weight cycles.

AdvancedTime: O(V × E)Space: O(V)
45-32462ABCDE
Step 1 / 0

Current Step

Click Play to start the visualization


## How Bellman-Ford Algorithm Works

Bellman-Ford finds shortest paths from a source node to all other nodes in a weighted graph. Unlike Dijkstra's, it can handle negative edge weights and detect negative weight cycles.

### Algorithm Steps:
1. Set distance to source = 0, all others = infinity
2. Repeat V-1 times:
- For each edge (u, v) with weight w:
- If distance[u] + w < distance[v], update distance[v]
3. Run one more iteration to detect negative cycles

### Key Characteristics:
- **Handles negative weights**: Works with negative edge weights
- **Cycle detection**: Can detect negative weight cycles
- **Slower than Dijkstra**: O(V × E) vs O((V + E) log V)
- **Dynamic programming**: Builds solution incrementally

Time & Space Complexity

CaseTime Complexity
BestO(E)
AverageO(V × E)
WorstO(V × E)
SpaceO(V)

Practice Problems

No Problems Available

Practice problems for this algorithm are coming soon!