2. A
E
F
G
C
D
B
H
6
-1
4
6
2
3
1
-2
6
8
Vertices Distance Parent
A 0 0
B ∞ 0
C ∞ 0
D ∞ 0
E ∞ 0
F ∞ 0
G ∞ 0
H ∞ 0 ∞
0
∞
∞
∞
∞
∞∞
2
For demonstration purpose, we would consider the following graph:
• Considering A as the source, assign it the distance zero.
• For all vertices except A assign a distance infinity.
16. *There are two cases in iterations
*We might not notice any change in distance for any vertex in
later iterations. It would be good to stop at that point for
making the algorithm efficient.
*We might endlessly notice changes in distances of one or the
other vertex in later iterations. This will be the case of negative
weight cycles. Hence, we need to stop at some point and that
would be the after |V| – 1