create account

Dijkstra’s algorithm of finding optimal paths by krishtopa

View this thread on: hive.blogpeakd.comecency.com
· @krishtopa ·
$70.03
Dijkstra’s algorithm of finding optimal paths
*One of the common tasks of graph theory is the one in which you need to find the most optimal path between two points. It can be solved on the plane as the graph in which the vertices - cities - are interconnected with ribs, which could be possible roads. And each road has its own length; therefore, traveling through it will take some resources. This amount is equivalent to the weight of the edge of the graph. Then the problem in practice can be formulated as follows: how to pave the way from one city to another, to spend the minimum resources on the road. The solution of this problem can be obtained by the Dijkstra algorithm.*

![](https://i.imgur.com/EieAOmD.jpg)

-------

Let’s consider initial vertex as a 0. This means that we will look for the shortest route from the vertex 0 to the other ones.

This algorithm goes step by step through all the vertices and assigns them labels, which are the minimum distances from an initial vertex to a particular node.

Let’s assign 0 to the 1st mark, because this vertex is initial.

![](https://i.imgur.com/AwKA2dI.png)

Next, we choose a vertex that has a minimum label and look at all the vertices, to which there is a path from it. Each of the peaks gets the label, the amount equal to the initial label plus a length of a path from it to the considered vertex, but only if the amount is less than the previous value of the label. If the amount is not less, then we leave unchanged the previous label.

After we looked at all the vertices, in which there is a direct path from the start, we note the initial vertex as visited and choose one which has a minimum value of the label from not visited, and it will be the next initial vertex. If there are multiple nodes with the same label, it does not matter which one we choose as the primary.

Again we find the sum of the initial vertex label and weight the edge, and if that amount is less than the previous label, then we replace the label with a received amount. 

![](https://i.imgur.com/XDGniiN.gif)

Then we note this vertex as visited and choose the next vertex, which has the minimum label. We repeat all the steps above until there are unvisited vertices.

After completing all the steps, we get the following result:


# Program execution

For a software implementation of the algorithm, we will need two arrays, logical “visited” - to store information about visited vertices and numerical “distance”, in which the shortest path would be placed. Thus, there exists a graph G = (V, E). 

Each of the peaks included in the set of the V, was originally marked as unvisited, it means that elements of the “visited” array are set to “false”. As we must find the most profitable paths, in each element of the “distance” vector the number that is certainly larger than any potential path is recorded. 

As a starting point is selected vertex s, and it is attributed to the zero path:. Distance [s] = 0, as there is no edge from s to s. 

Then, all neighboring vertices (in which there is an s edge) [let those be t and u] are found, and investigated, the cost of the route from s to each of them is calculated:

*distance [t] = distance [s] + s and t incident weight ribs;*
*distance [u] = distance [s] + s, and u incident weight ribs.*

![](https://i.imgur.com/dWtprX5.gif)

**There you can see Dijkstra's algorithm written in C++ (http://www.hastuts.com/dijkstra-shortest-path-algorithm-in-cpp/)**

But it is likely that there are several ways to the s vertex, so the cost in the distance array will have to be revised, then the highest value is ignored, and the smallest is associated with the vertex.

After processing the vertices adjacent to s it is marked as the visited: visited [s] = true and vertex the path from s to which is minimum becomes active. 

Assume the path from u to s shorter than s to t, hence, vertex u becomes active in the way described above and its neighbors except the vertex s are investigated. Furthermore, u is marked as visited: visited [u] = true, vertex t becomes active, and the whole procedure is repeated for it. Dijkstra's algorithm can be extended as long as some of the s vertexes won’t be investigated.

--------

*Algorithm of a Dutch scientist Edsger Dijkstra finds the shortest path from one vertex to all the others. With its help, in the presence of all the necessary information, it is possible, for example, to learn how better to use a sequence of roads to get from one city to many others, and to which countries it is more profitable to export oil. The downside of this method is the impossibility of processing graphs, in which there are ribs with negative weight.*

References: [1](http://users.informatik.uni-halle.de/~jopsi/dssea/chap8.shtml)

***[Follow me](https://steemit.com/@krishtopa), to be the first to learn about my publications devoted to popular science and educational topics***

***With Love,
Kate***

Image credit: [1](http://www.hastuts.com/dijkstra-shortest-path-algorithm-in-cpp/), [2](http://users.informatik.uni-halle.de/~jopsi/dssea/chap8.shtml), [3](http://www.math.cornell.edu/~mec/Winter2009/Thompson/search.html), [4](http://ru.forwallpaper.com/wallpaper/light-and-darkness-758565.html)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 61 others
properties (23)
authorkrishtopa
permlinkdijkstra-s-algorithm-of-finding-optimal-paths
categorypopularscience
json_metadata{"tags":["popularscience","science","math","academia","education"],"image":["https://i.imgur.com/EieAOmD.jpg","https://i.imgur.com/AwKA2dI.png","https://i.imgur.com/XDGniiN.gif","https://i.imgur.com/dWtprX5.gif"],"links":["http://www.hastuts.com/dijkstra-shortest-path-algorithm-in-cpp/","http://users.informatik.uni-halle.de/~jopsi/dssea/chap8.shtml","https://steemit.com/@krishtopa","http://www.math.cornell.edu/~mec/Winter2009/Thompson/search.html","http://ru.forwallpaper.com/wallpaper/light-and-darkness-758565.html"]}
created2016-10-14 22:32:15
last_update2016-10-14 22:32:15
depth0
children5
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value61.034 HBD
curator_payout_value8.992 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,181
author_reputation48,350,480,258,009
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,536,143
net_rshares57,739,591,910,281
author_curate_reward""
vote details (125)
@jlufer ·
I was never good with science but ud makes it look easy, excellent work is carried out along its publications congratulations and thanks for sharing a very interesting post
👍  ,
properties (23)
authorjlufer
permlinkre-krishtopa-dijkstra-s-algorithm-of-finding-optimal-paths-20161014t224429037z
categorypopularscience
json_metadata{"tags":["popularscience"]}
created2016-10-14 22:44:36
last_update2016-10-14 22:44:36
depth1
children1
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation1,402,434,836,727,056
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,536,218
net_rshares117,004,884,410
author_curate_reward""
vote details (2)
@krishtopa ·
@jlufer Thanks for the good feedback and stay tuned to learn more
properties (22)
authorkrishtopa
permlinkre-jlufer-re-krishtopa-dijkstra-s-algorithm-of-finding-optimal-paths-20161018t200133072z
categorypopularscience
json_metadata{"tags":["popularscience"],"users":["jlufer"]}
created2016-10-18 20:01:33
last_update2016-10-18 20:01:33
depth2
children0
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length65
author_reputation48,350,480,258,009
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,567,217
net_rshares0
@lemouth ·
Are there other algorithms or is this one the most efficient one? I would like to have a look to the cpp code, but I cannot do that from my mobile.... will check tonight ;)
properties (22)
authorlemouth
permlinkre-krishtopa-dijkstra-s-algorithm-of-finding-optimal-paths-20161015t070959380z
categorypopularscience
json_metadata{"tags":["popularscience"]}
created2016-10-15 07:10:03
last_update2016-10-15 07:10:03
depth1
children2
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length172
author_reputation338,011,164,701,274
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,538,527
net_rshares0
@krishtopa ·
Hi, Lemouth.
I'm sorry for the late response.  Choice of the algorithm should depend on the specific application. If it's a single-source shortest path problem then Dijkstra's algorithm with Fibonacci heap is a best choice. If you need to find all pairs shortest paths, then you should rather use Floyd–Warshall algorithm
properties (22)
authorkrishtopa
permlinkre-lemouth-re-krishtopa-dijkstra-s-algorithm-of-finding-optimal-paths-20161018t195949739z
categorypopularscience
json_metadata{"tags":["popularscience"]}
created2016-10-18 19:59:51
last_update2016-10-18 19:59:51
depth2
children1
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length321
author_reputation48,350,480,258,009
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,567,197
net_rshares0
@lemouth ·
Thanks! I always appreciate answers, even when late. We are all pretty busy and I can understand that, don't worry ^^
👍  
properties (23)
authorlemouth
permlinkre-krishtopa-re-lemouth-re-krishtopa-dijkstra-s-algorithm-of-finding-optimal-paths-20161019t053352809z
categorypopularscience
json_metadata{"tags":["popularscience"]}
created2016-10-19 05:34:03
last_update2016-10-19 05:34:03
depth3
children0
last_payout2016-11-15 01:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length117
author_reputation338,011,164,701,274
root_title"Dijkstra’s algorithm of finding optimal paths"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,570,686
net_rshares80,326,395,398
author_curate_reward""
vote details (1)