Introduction
Today, I will write about the dijkstra method. This method is algorithm which find the shortest distance. The map is expressed by graph. If you never see this page, look at its page. This page explain the heap structure and definition of graph. The dijkstra method used heap structure, Because heap structure reduce the amout of calculation of dijkstra method.
I use this slide to explain dijkstra.
Overview
I explain algorithm by using this graph.
Fistly, Decede start node and allocate $d=\infty$ for each node.
Begin from node A. If d of B is smaller than d of A + weight(2), update d of B. Next, If d of C is smaller than d of A + weight(2), update d of C.
Next remove A from graph network.
Next, Begin from B. I do the same thing .
Today, I will write about the dijkstra method. This method is algorithm which find the shortest distance. The map is expressed by graph. If you never see this page, look at its page. This page explain the heap structure and definition of graph. The dijkstra method used heap structure, Because heap structure reduce the amout of calculation of dijkstra method.
I use this slide to explain dijkstra.
Overview
- Algorithm
- Implementation
Algorithm
This algorithm is
- Decide start node, and this node named A.
- Allocate $d=\infty$ for each node, but d=0 for start node.
- Adjacent node of A named adj_list.
- For adj in adj_list: If d of adj > d of A + weight to adj -> d = A + weight to adj.
- Remove A from graph network.
- Find node which have the smallest d and it named A, and if network have node, back to 4.
I explain this algorithm by drawing.
Fistly, Decede start node and allocate $d=\infty$ for each node.
Begin from node A. If d of B is smaller than d of A + weight(2), update d of B. Next, If d of C is smaller than d of A + weight(2), update d of C.
Next remove A from graph network.
Next, Begin from B. I do the same thing .
The dijkstra algorithm repeat this operation graph network do not have node.
Implementation
This algorithm take $O(log(|V|^2))$. Because this algorithm take time to search the node which have d of shortest distance.
However the calculation time is reduced to O((E+V)log(V)) by heap structure. Select node which have d of shortest distance by picking up node from heap structure.
I will implement the dijkstra by Python 3.
This implementation is published this github page.
I make random 100 node and , number selected by random from 0~30 edge.
Result...
This gif is expressed to update d of each node.
コメント
コメントを投稿