⬅ Previous Topic
Bellman-Ford Algorithm for Shortest PathsInput Matrix | Output Matrix | Description |
---|---|---|
[[0, 3, -1], [-1, 0, 1], [4, -1, 0]] | [[0, 3, 4], [5, 0, 1], [4, 7, 0]] | Shortest paths computed between all vertex pairs |
[[0, 5, -1], [-1, 0, 2], [3, -1, 0]] | [[0, 5, 7], [5, 0, 2], [3, 8, 0]] | Path from 0 to 2 via 1 with weight 5+2=7 |
[[0, -1, -1], [-1, 0, -1], [-1, -1, 0]] | [[0, -1, -1], [-1, 0, -1], [-1, -1, 0]] | No edges means no shorter paths can be found |