Dijkstras Algorithm
Dijkstras Algorithm
algorithm
TEAM #2
Short path algorithms are an important branch of support for the study of complex data
contained in graphs. Thanks to them we can determine paths within the structure of a
graph efficiently and quickly.
The shortest path algorithm is in one of the most important analysis modules of graph
algorithms. This is responsible for detecting within a graph which is the most efficient
route or the shortest distance path between a pair of vertices that make up a graph.
Within this category, the well-known Dijkstra algorithm stands out for its properties.
The shortest path problem is to find the shortest paths
between a given vertex v and all other vertices of the
graph.
- K routes of Yen
- Minimum Weight Spanning
Tree
- A*
- Random Walk
Dijkstra
Edsger Wybe Dijkstra was born in 1930 in
Rotterdam, the Netherlands. He was the son of
Wybe Douwe Dijkstra and Brechtje Cornelia
Kruyper. He was a computer scientist,
programmer, software engineer, systems
scientist, and scientific essayist.
5 steps
Once all the nodes are visited, the minimum route from the
initial node to the other nodes of the graph is obtained.
The algorithm works by iteratively selecting the vertex with the smallest distance from the
source vertex and updating the cost of its neighboring vertices. The operation of selecting
the vertex with the smallest distance is typically implemented using a priority queue, which
has a time complexity of O(log V) for insertion and extraction of the minimum element. Since
this operation is performed for each vertex in the graph, the overall time complexity of
Dijkstra's algorithm becomes O(V log V).
In addition to the vertex selection, the algorithm also needs to update the value of the
shortest path found to any adjacent vertex of the current vertex, which takes O(1) time for
each edge in the graph. Since the total number of edges is E, the time complexity for this task
is O(E).
Dijkstra's algorithm pseudocode
Example
Previous distance of b Distance from a to b
Node Distance
v dist(v)
A ∞
B ∞
s (source) = C 0
D ∞
Q = {A, B, D, E}
E ∞
Current node = C
S = {}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A ∞
B 7
s (source) = C 0
D ∞
Q = {A, B, D, E}
E ∞
Current node = C
S = {}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A 1
B 7
s (source) = C 0
D ∞
Q = {A, B, D, E, F}
E ∞
Current node = C
S = {}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A 1
B 7
s (source) = C 0
D 2
Q = {A, B, D, E}
E ∞
Current node = C
S = {}
3. Add node v to indicate that v has been visited.
Node Distance
v dist(v)
A 1
B 7
s (source) = C 0
D 2
Q = {A, B, D, E}
E ∞
Current node = C
S = {C}
1. While Q is not empty, pop the node v, that is not already in S from Q with the smallest dist(v)
Node Distance
v dist(v)
A 1
B 7
s (source) = C 0
D 2
Q = {B, D, E}
E ∞
Current node = A
S = {C}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {B, D, E}
E ∞
Current node = A
S = {C}
3. Add node v to indicate that v has been visited.
1. While Q is not empty, pop the node v, that is not already in S from Q with the smallest dist(v)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {B, E}
E ∞
Current node = D
S = {C, A}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {B, E}
E 9
Current node = D
S = {C, A}
3. Add node v to indicate that v has been visited.
1. While Q is not empty, pop the node v, that is not already in S from Q with the smallest dist(v)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {E}
E 9
Current node = B
S = {C, A, D}
2. Update dist values of adjacent nodes of the current node v as follows: for each new adjacent
node u,
● If dist(v) + w(u,v) < dist(u), there is a new minimal distance found for u
● Otherwise, no updates are made to dist(u)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {E}
E 5
Current node = B
S = {C, A, D}
3. Add node v to indicate that v has been visited.
1. While Q is not empty, pop the node v, that is not already in S from Q with the smallest dist(v)
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {}
E 5
Current node = E
S = {C, A, D, B}
The algorithm has visited all nodes in the graph and found the smallest distance to each node. The
array dist now contains the shortest path from source s to every other node.
Node Distance
v dist(v)
A 1
B 4
s (source) = C 0
D 2
Q = {}
E 5
Current node = E
S = {C, A, D, B, E}
Java
Implementation
APPLICATIONS
Public
Transportation
Networks
Network Gaming and
Routing Virtual Reality
Navigation
Systems Logistics and
Transportation
Network Routing Navigation systems
The Dijkstra algorithm is a fundamental tools in graph theory and it works as basis for other
graphing algorithms and graphing data structures. It is an easy and efficient way to find the
shortest path on a weighted graph. It is also easy to implement on a programming language
and has a lot of useful applications.
However, it is important to use this or another shortest path search algorithm depending on
the characteristics of the case in which it is needed because it has some restrictions as the
inability to handle edges with negative weights.
Sources
● https://dl.ebooksworld.ir/books/Introduction.to.Algorithms.4th.Leiserson.Stein.Rivest.Cormen.MIT.
Press.9780262046305.EBooksWorld.ir.pdf
● https://stackoverflow.com/questions/26547816/understanding-time-complexity-calculation-for-dij
kstra-algorithm
● https://www.researchgate.net/publication/220426527_An_Interview_with_Edsger_W_Dijkstra