Dijkstra's Algorithm
Dijkstra's Algorithm
Dijkstra's Algorithm begins at the node you specify (the source node) and analyses the
graph to find the shortest path between that node and all other nodes in the graph.
It keeps track of the shortest known distance from each node to the source node and updates
these values if a short path is discovered. When the algorithm finds the shortest path between
the source and another node, it marks that node as visited and adds it to the path. The process
is repeated until all the nodes in the graph are added to the path. In this process, a path
connects the source node to all other nodes by taking the shortest possible path to each node
(Estefania, 2020).
Dijkstra's Algorithm can only be applied to graphs with positive weights. That the
weights of the edges must be added during the process to find the shortest path. If the graph
contains a negative weight, the algorithm will not function properly. When a node is marked
as visited, the current path to that node becomes the shortest path to that node. Negative
weights can change this if the total weight can be decremented after this step (Estefania,
2020).
graph. Illustrate with all steps taken in the algorithm by drawing graphs and showing
outcome as explained in the video. Find the shortest path from vertex s to vertex z and
(Fiset, 2016)
Dijkstra's Algorithm finds the shortest path in a graph between a given node (called
the "source node") and all other nodes. The weights of the edges are used by this algorithm to
find the path that minimizes the total distance (weight) between the source node and all other
dist(u)=dist(u, v)+cost(u),
here u and v are the vertices cost is the value of the vertex, dist is the distance between two
From the given graph the shortest path from vertex s to vertex z
Dijkstra's Algorithm will find the shortest path from the vertices S to vertices Z in the
graph. Dijkstra's Algorithm will also include the shortest distance from the S vertex to Z
Step1: The shortest path from the source vertex s to the source
dist(u)=dist(u, v)+cost(u)
distance 0, 0
Shortest 0
distance
Visited
vertices
(Fiset, 2016)
Step2: The path between the source vertex s to the next nearby unvisited vertex is y. The
dist(u)=dist(u, v)+cost(u).
distance 0, 0 0, 5
Shortest 0 5
distance
Visited S s
vertices
(Fiset, 2016)
Step3: The path between the vertex y to the next nearby unvisited vertex is t, the path
between the vertex y to the next nearby unvisited vertex is x, and the path between the vertex
dist(u)=dist(u, v)+cost(u).
t(3) distance is 1, so
dist(y(5), t(3))=5+1=6
distance 0, 0 5, 1 0, 5
Shortest 0 6 5
distance
Visited S y s
vertices
(Fiset, 2016)
The path between the vertex y to the next nearby unvisited vertex is t. The shortest distance
dist(u)=dist(u, v)+cost(u).
x(9) distance is 4, so
dist(y(5), x(9))=5+4=9
distance 0, 0 5 ,1 5, 4 0, 5
vertices s (0) t(3) x(9) y(5) z(11)
Shortest 0 6 9 5
distance
Visited s y y S
vertices
(Fiset, 2016)
The path between the vertex y to the next nearby unvisited vertex is z. The shortest distance
dist(u)=dist(u, v)+cost(u).
z(11) distance is 6, so
dist(y(5), z(11))=5+6=11
distance 0, 0 5 ,1 5, 4 0, 5 5, 6
vertices s (0) t(3) x(9) y(5) z(11)
Shortest 0 6 9 5 11
distance
Visited s y Y S y
vertices
So, the shortest distance from the vertices s to z is 11. And the shortest path from the
vertices s to z is s→ y→ z. So, here we find the shortest distance from s to z is 11, and
shortest path is s→ y→ z because remaining all other paths from s to z shortest distance is
From the given graph the shortest path from vertex z to vertex s
Step1: The shortest path from the source vertex z to the source
dist(u)=dist(u, v)+cost(u)
Distance 0, 0
Vertices z (11) t(3) x(9) y(5) s(0)
Shortest 0
distance
Visited
vertices
(Fiset, 2016)
Step2: The path between the vertex z to the next nearby unvisited vertex is s, the path
dist(u)=dist(u, v)+cost(u).
distance 0, 0 0, 3
vertices z (11) t(3) x(9) y(5) s(0)
Shortest 0 3
distance
Visited z
vertices
(Fiset, 2016)
Step3: The path between the vertex z to the next nearby unvisited vertex is x.
dist(u)=dist(u, v)+cost(u).
distance 0, 0 0, 7 0, 3
vertices z (11) t(3) x(9) y(5) s(0)
Shortest 0 7 3
distance
Visited Z z
vertices
So, here we find the shortest distance from z to s is 3, and shortest path is z→s because
remaining all other paths from z to s shortest distance is more than 3 (Fiset, 2016).
Conclusion
Graphs are used to show connections between objects, entities, or people. They are
made up of two main components: nodes and edges. Dijkstra's algorithm determines the
shortest path between one node and every other node in a graph. The procedures for
deploying this algorithm on the internet are outlined below. Dijkstra's algorithm simple and
phone network routing, geographic maps, and so on. This implementation could be improved
by using concurrent, which allows to analyze the child nodes in parallel, improving
References:
Estefania C N, (2020). https://www.freecodecamp.org/news/dijkstras-shortest-path-
algorithm-visual-introduction/#:~:text=Dijkstra%27s%20Algorithm%20finds%20the
%20shortest,node%20and%20all%20other%20nodes.
Carlos. H, (2020).
https://medium.com/carlos-hernandez/dijkstras-algorithm-afa09be748bf