Juan Rodriguez
Senior Software Engineer - M.Sc. in Computer Science.
In one example
by: Juan Rodriguez
The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex to all of the other vertices in a weighted digraph[1]
It is slower than Dijkstra's algorithm for the same problem, but more versatile, as it is capable of handling graphs in which some of the edge weights are negative numbers.
Worst-case performance | |
Best-case performance | |
Worst-case space complexity |
0 | 1 | 2 | 8 | Inf | Inf |
A | B | C | D | E | F |
1st Iteration
6 vertices = max 5 iterations
0 | 1 | 2 | 7 | 4 | 10 |
A | B | C | D | E | F |
2st Iteration
0 | 1 | 2 | 7 | 4 | 8 |
A | B | C | D | E | F |
3st Iteration
6 vertices = max 5 iterations
0 | 1 | 2 | 7 | 4 | 8 |
A | B | C | D | E | F |
4st Iteration
No changes, finished!
6 vertices = max 5 iterations
[1] https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm
[2] https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/
By Juan Rodriguez