Bellman Ford Alg
Bellman Ford Alg
• Edge relaxation:
Bellman Ford Pseudocode
Example
Vertex A B C D E F
Distance 0 ∞ ∞ ∞ ∞ ∞
Parent -- -- -- --- -- --
Identify the all edge pairs
• From the graph, the edge pairs:
• From vertex A, edge pairs are: (A,B) (A,C) (A,D).
• From vertex B, edge pairs: (B,E)
• From vertex C, edge pairs: (C,B) (C,E)
• From vertex D, edge pairs: (D,C) (D,F)
• From vertex E, edge pairs: (E,F)
• From vertex F, edge pairs: ---
Do the 1st iteration
Vertex A B C D E F
Distance 0 6 4 5 ∞ ∞
Parent -- A A A -- --
Do the 2nd iteration
Vertex A B C D E F
Distance 0 2 3 5 5 4
Parent -- C D A B D
Do the 3rd iteration
Vertex A B C D E F
Distance 0 1 3 5 1 4
Parent -- C D A B D
Do the 4th iteration
Vertex A B C D E F
Distance 0 1 3 5 0 3
Parent -- C D A B E
Do the 5th iteration
Vertex A B C D E F
Distance 0 1 3 5 0 3
Parent -- C D A B E
Drawbacks of Bellman ford algorithm
• The bellman ford algorithm does not produce a
correct answer if the sum of the edges of a
cycle is negative.