StudyMafia.
Org
Dijkstra Algorithm
Submitted To: Submitted By:
Studymafia.org Studymafia.org
Table Contents
– Definition
– Introduction
– Implementation of Dijkstra's Algorithm
– Steps of Dijkstra's Algorithm
– Example of Dijkstra's Algorithm
– Applications of Dijkstra's Algorithm
– Conclusion
2
Definition
An algorithm that is used for finding the shortest
distance, or path, from starting node to target node
in a weighted graph is known as Dijkstra's Algorithm
3
Introduction
• A Dutch computer scientist, Edsger Dijkstra, in
1959, proposed an algorithm that can be applied to
a weighted graph.
• The graph can either be directed or undirected
with the condition that the graph needs to
embrace a non-negative value on its every edge.
• Dijkstra's algorithm makes use of weights of the
edges for finding the path that minimizes the total
distance (weight) among the source node and all
other nodes 4
5
Implementation of Dijkstra's Algorithm
• Basically, the Dijkstra’s algorithm begins
from the node to be selected, the source
node, and it examines the entire graph to
determine the shortest path among that
node and all the other nodes in the graph.
●●●
6
Implementation of Dijkstra's Algorithm
• The algorithm maintains the track of the
currently recognized shortest distance from
each node to the source code and updates
these values if it identifies another shortest
path.
●●●
7
Implementation of Dijkstra's Algorithm
• Once the algorithm has determined the
shortest path amid the source code to
another node, the node is marked as
“visited” and can be added to the path.
●●●
8
Implementation of Dijkstra's Algorithm
• This process is being continued till all the
nodes in the graph have been added to the
path, as this way, a path gets created that
connects the source node to all the other
nodes following the plausible shortest path
to reach each node.
9
Steps of Dijkstra's Algorithm
• The very first step is to mark all nodes as
unvisited,
• Mark the picked starting node with a
current distance of 0 and the rest nodes
with infinity,
●●●
10
Steps of Dijkstra's Algorithm
• Now, fix the starting node as the current
node,
• For the current node, analyse all of its
unvisited neighbours and measure their
distances by adding the current distance
of the current node to the weight of the
edge that connects the neighbour node
and current node,
●●●
11
Steps of Dijkstra's Algorithm
• Compare the recently measured distance
with the current distance assigned to the
neighbouring node and make it as the
new current distance of the neighbouring
node,
• After that, consider all of the unvisited
neighbours of the current node, mark the
current node as visited,
●●●
12
Steps of Dijkstra's Algorithm
• If the destination node has been marked
visited then stop, an algorithm has ended,
and
• Else, choose the unvisited node that is
marked with the least distance, fix it as
the new current node, and repeat the
process again from step 4.
13
Example of Dijkstra's Algorithm
●●●
14
Example of Dijkstra's Algorithm
• During the execution of the algorithm, each
node will be marked with its minimum
distance to node C as we have selected
node C.
• In this case, the minimum distance is 0 for
node C. Also, for the rest of the nodes, as
we don’t know this distance, they will be
marked as infinity (∞), except node C
(currently marked as red dot).
●●●
15
Example of Dijkstra's Algorithm
• Now the neighbours of node C will be
checked, i.e, node A, B, and D.
• We start with B, here we will add the
minimum distance of current node (0) with
the weight of the edge (7) that linked the
node C to node B and get 0+ 7= 7.
●●●
16
Example of Dijkstra's Algorithm
• Now, this value will be compared with the
minimum distance of B (infinity), the least
value is the one that remains the minimum
distance of B, like in this case, 7 is less than
infinity, and marks the least value to node
B.
●●●
17
Example of Dijkstra's Algorithm
• Now, the same process is checked with
neighbour A. We add 0 with 1 (weight of
edge that connects node C to A), and get 1.
Again, 1 is compared with the minimum
distance of A (infinity), and marks the
lowest value.
●●●
18
Example of Dijkstra's Algorithm
• Now, we will select the new current node
such that the node must be unvisited with
the lowest minimum distance, or the node
with the least number and no check mark.
• Here, node A is the unvisited with
minimum distance 1, marked as current
node with red dot.
●●●
19
Example of Dijkstra's Algorithm
• For node B, we add 1 with 3 (weight of the
edge connecting node A to B) and obtain 4.
This value, 4, will be compared with the
minimum distance of B, 7, and mark the
lowest value at B as 4.
●●●
20
Example of Dijkstra's Algorithm
• After this, node A marked as visited with a
green check mark. The current node is
selected as node D, it is unvisited and has a
smallest recent distance.
• We repeat the algorithm and check for
node B and E.
●●●
21
Example of Dijkstra's Algorithm
• For node B, we add 2 to 5, get 7 and compare it
with the minimum distance value of B, since
7>4, so leave the smallest distance value at
node B as 4.
• For node E, we obtain 2+ 7= 9, and compare it
with the minimum distance of E which is
infinity, and mark the smallest value as node E
as 9. The node D is marked as visited with a
green check mark.
●●●
22
Example of Dijkstra's Algorithm
• The current node is set as node B, here we need
to check only node E as it is unvisited and the
node D is visited. We obtain 4+ 1=5, compare it
with the minimum distance of the node.
• We mark D as visited node with a green check
mark, and node E is set as the current node.
23
Applications of Dijkstra's Algorithm
• For map applications, it is hugely
deployed in measuring the least
possible distance and check direction
amidst two geographical regions like
Google Maps, discovering map locations
pointing to the vertices of a graph,
calculating traffic and delay-timing, etc.
●●●
24
Applications of Dijkstra's Algorithm
• For telephone networks, this is also
extensively implemented in the
conducting of data in networking and
telecommunication domains for
decreasing the obstacle taken place for
transmission.
25
Conclusion
Among many, we have discussed the Dijkstra
algorithm used for finding the shortest path,
however, one of the obstacles while implementing
the algorithm on the internet is to provide a full
representation of the graph to execute the algorithm
as an individual router has a complete outline for all
the routers on the internet.
26
Thanks
To
StudyMafia.org