Dijkstra algorithm of Shortest path

Source: Internet
Author: User

Dijkstra algorithm:

First, the introduction of an auxiliary vector D, each of its components d[i] represents the length of the current found from the start point V to each endpoint VI: For example, d[3]=2 indicates that the path from point V to endpoint 3 has a relative minimum length of 2. The emphasis here is on the relative meaning that the value of D in the algorithm is constantly approaching the final result but not necessarily the length in the process. Its initial state is: if the arc from V to VI, then D is the right value on the arc, otherwise the D is ∞. Obviously, the path of length D[j]=min{d | vi∈v} is the shortest length from V. This path is (V,VJ). So, what is the next short length of the line? Assuming that the end point of the short path is VK, it is conceivable that the path is either (V,VK), or (V,VJ,VK). Its length is either the weight of the arc from V to VK, or the sum of the weights of D[j] and arcs from VJ to VK. In general, if S is a set of evaluated endpoints, it can be proved that the next shortest path (set its end point to X) or arc (v,x), or a path that only passes through the vertices of s in the middle and finally reaches the vertex x. Therefore, the length of the next short length must be the sum of D[j]=min{d | vi∈v-s}, where D is the weight on the arc (V,VI), or the weights on the D[k] (vk∈s) and Arc (VK,VI).

The algorithm is described as follows:

1) Arcs represents the weight on the arc. If it does not exist, the arcs is set to ∞ (Maxcost in this program). S is the set of endpoints that have been found from V, and the initial state is the empty setting. Then, the initial value of the possible degrees from V to the rest of the Vertex VI on the graph is D=arcs[locate vex (g,v), I] vi∈v

2) Select VJ, make D[j]=min{d | vi∈v-s} 3) Modify the shortest path length from V to set v-s from the vertex VK.

Consider the following non-network (assuming starting from V0):

Shortest Path Array change:

Initially, the v0 can reach a point of v2,v4,v5, the distance is 10, 30,100, the distance to the remaining points is the default infinity (max),

Then, take the smallest weight 10, into the s set, that is V2 point. And v2 can reach the V3, the distance is 50. The v0->v3 distance can be 10+50=60, less than the current value (max), so the secondary array is updated. Next, take out a minimum weight of 30 (remove before 10), that is, V4, and V4 can reach v3,v5, distance of 20, 60, then v0->v3,v0->v5 distance can be 30+20=50,30+60=90, less than the current value of 60,100 , the secondary array continues to be updated. And so on, finally get a shortest path array.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.