Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Bellman-Ford Algorithm
Bookmark
Input
4 Nodes Simple
5 Nodes (with negative edge)
Custom
graph
=
{"1":[["2",4],["3",3]],"2":[["3",-2],["4",4]],"3":[["4",2]],"4":[]}
,
source
=
1
Bellman-Ford Algorithm (source: 1)
Initializing...
4
3
-2
4
2
1
2
3
4
0
∞
∞
∞
Distances:
1
0
2
∞
3
∞
4
∞
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Initializing...
4
3
-2
4
2
1
2
3
4
0
∞
∞
∞
Distances:
1
0
2
∞
3
∞
4
∞
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 1/3
Edge: 1 → 2
4
3
-2
4
2
1
2
3
4
0
4
∞
∞
Distances:
1
0
2
4
3
∞
4
∞
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 1/3
Edge: 2 → 3
4
3
-2
4
2
1
2
3
4
0
4
3
∞
Distances:
1
0
2
4
3
3
4
∞
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 1/3
Edge: 2 → 4
4
3
-2
4
2
1
2
3
4
0
4
2
8
Distances:
1
0
2
4
3
2
4
8
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 1/3
Edge: 3 → 4
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 2/3
Edge: 1 → 3
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 2/3
Edge: 2 → 3
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 2/3
Edge: 3 → 4
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 2/3
Edge: 3 → 4
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
Bellman-Ford Algorithm (source: 1)
Iteration: 2/3
Edge: 3 → 4
4
3
-2
4
2
1
2
3
4
0
4
2
4
Distances:
1
0
2
4
3
2
4
4
Algorithm Info:
Total iterations needed: V - 1 = 3
Time Complexity: O(V * E)
Legend:
Unprocessed
Source/Active
Checking
Relaxed
algo
master
.
io
Step:
Initialize distances: source "1" = 0, all others = ∞
0 / 28
Input
4 Nodes Simple
5 Nodes (with negative edge)
Custom
graph
=
{"1":[["2",4],["3",3]],"2":[["3",-2],["4",4]],"3":[["4",2]],"4":[]}
,
source
=
1
0 / 28
algo
master
.
io
Step:
Initialize distances: source "1" = 0, all others = ∞