# Bellman Ford Shortest Path algorithm

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.