Single Source Shortest path (Bellman-ford algorithm +dijkstra algorithm) + any two-point minimum (Floyd-warshall algorithm)

Source: Internet
Author: User

PS: It was a review of the graph theory, and finally became a preview, separated a period of time simply, re-learn!

hahaha haha, really dish ah!

single source The shortest path problem is to ask, fix a starting point, and ask for the shortest path to all other points.

The shortest path between two points is to seek, fixed the starting point and end point to find short circuit

There is no fundamental difference between the two, the same complexity

1, single source shortest 1 Bellman-ford algorithm

Core algorithms:

D[i]=min (d[j]+ (weights from vertex j to vertex i edge), D[i])

D "I" indicates the shortest distance from any point to the vertex i

Generally initialized to INF, and then start D "s" to initialize 0.

As long as there is no negative circle (negative circle refers to the two points between the weight of the circle formed by a negative value) Update operation is limited

structEdge//The weight from the vertex from-->to is the cost of the edge{    int  from; intto ; intCost ;};  Edge ES[MAXN]; //sideintD[MAXN];//Shortest distanceintV,b;//vertex and number of sides, respectivelyvoidBellmanintS//Recursive from Vertex{    for(intI=0; i<v;i++) D[i]=inf;//The shortest distance of all vertices is set to maximum, excluding the self-loopd[s]=0;//Initialize starting point    while(true)   {       BOOLvis=false;  for(intI=0; i<b;i++) {Edge e=Es[i]; if(D[e. from]!=inf&&d[e.to]>d[e. from]+e.cost) {d[e.to]=d[e. from]+E.cost; Update=true; }       }       if(!update) Break; }   }

Forget to find the big guy's detailed thinking, I read and then to fill the

Bellman-ford algorithm: http://www.wutianqi.com/?p=1912

Dijkstra algorithm: http://www.wutianqi.com/?p=1890

Floyd algorithm: http://www.wutianqi.com/?p=1903

Single Source Shortest path (Bellman-ford algorithm +dijkstra algorithm) + any two-point minimum (Floyd-warshall 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.