Understanding the Bellman-Ford algorithm
The Bellman-Ford algorithm is a single-source shortest path-finding algorithm that can solve this problem for graphs with negative edge weights. Dijkastra's algorithm fails on graphs with negative edge weights because it assumes the first time we reach a node will always be via the shortest path. This assumption is valid for graphs with non-negative edge weights but not for those with negative edge weights. The Bellman-Ford algorithm overcomes this by calculating the shortest path for each node incrementally over multiple iterations and considering every path from the source to that node.
Loading Image
Belman-ford algorithm accounts for all paths to a node.
Algorithm
Liking the course? Check our discounted plans to continue learning.