Bellman Ford Shortest Path algorithm
The following table records the distance from S to each node:
The first iteration,
S->a = 4 because S->a is currently INF, so the update min (s->a) is 4
S->b = 6 Because s->b is currently INF, so the update min (s->b) is 6
S->c=inf (indicates unreachable)
S->d=inf
|
MIN (S->s) |
MIN (S->a) |
MIN (S->B) |
MIN (S->C) |
MIN (S->D) |
|
0 |
4 |
6 |
Inf |
Inf |
The second iteration begins with a:
A->c=3, because S->c is currently inf, so update min (s->c) is 7
|
MIN (S->s) |
MIN (S->a) |
MIN (S->B) |
MIN (S->C) |
MIN (S->D) |
|
0 |
4 |
6 |
7 |
Inf |
The second iteration begins with B,
B->a=-5, because s->a=4 s->b=6, so s->b->a=1 < S->a = 4, so update min (s->a) =1
Because the S->a is updated, and a can have a point set of C, you need to recursive these sets of points :
Min (s->c) At this time is 7, and min (s->a)->c is 1+3=4, so need to update min (s->c) =4
B->d = 1, because min (s->d) = INF, so min (s->d) needs to be updated to 7
|
MIN (S->s) |
MIN (S->a) |
MIN (S->B) |
MIN (S->C) |
MIN (S->D) |
|
0 |
1 |
6 |
4 |
7 |
Start the iteration from point C:
The C reach point set is only D because min (s->d) is 7, and min (s->c)->d is 4+2=6, so min (s->d) needs to be updated to 6
To get the final result:
|
MIN (S->s) |
MIN (S->a) |
MIN (S->B) |
MIN (S->C) |
MIN (S->D) |
|
0 |
1 |
6 |
4 |
6 |
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bellman Ford Shortest Path algorithm