Bellman Ford Shortest Path algorithm
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "/>
The following table records the distance from S to each node:
The first iteration,
S->a = 4, because S->a is now INF. So update min (s->a) is 4
S->b = 6. Because S->b is now INF. So 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 from a begins:
A->c=3. Since S->c is currently inf, 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, due to 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 reach a point set of C, these can be recursive to the point set :
MIN (S->C) is at this time 7. and Min (s->a)->c is 1+3=4. therefore 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:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "/>
The C reach point set has 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 |
Bellman Ford Shortest Path algorithm