Bellman Ford Shortest Path algorithm

Source: Internet
Author: User

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

Contact Us

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.