Professional Documents
Culture Documents
Dijkstra's Algorithm: Project Title
Dijkstra's Algorithm: Project Title
Presented By
Introduction
• The algorithm was developed by a Dutch computer scientist Edsger W. Dijkstra in 1956.
• It is used to find the shortest path between a node/vertex (source node) to any (or every)
other nodes/vertices (destination nodes) in a graph.
• This algorithm is sometimes referred to as Single Source Shortest Path Algorithm due
to its nature of implementation.
05-02-2021 2
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
• The algorithm keeps track of the currently known shortest distance from each node to the
source node and it updates these values if it finds a shorter path.
• Once the algorithm has found the shortest path between the source node and another
node, that node is marked as "visited" and added to the path.
• The process continues until all the nodes in the graph have been added to the path. This
way, we have a path that connects the source node to all other nodes following the
shortest path possible to reach each node.
05-02-2021 3
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
• Dijkstra's Algorithm can only work with graphs that have positive weights. This is
because, during the process, the weights of the edges have to be added to find the
shortest path.
• If there is a negative weight in the graph, then the algorithm will not work properly.
Once a node has been marked as "visited", the current path to that node is marked as the
shortest path to reach that node. And negative weights can alter this if the total weight
can be decremented after this step has occurred.
• Dijkstra’s Algorithm can be used for undirected graphs as well as directed graph.
05-02-2021 4
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Explanation
• In order to find the shortest path, Dijkstra’s algorithm mainly allocates a “cost” value
taken to reach the destination vertex from the source vertex. The “cost” can be mapped
to disance, money or time taken to reach from source to a destination.
05-02-2021 5
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Steps to be followed for solving using Dijkstra’s algorithm:
2. Maintain a list of unvisited vertices. Assign a vertex as “source” and also allocate a
maximum possible cost (infinity) to every other vertex. The cost of the source to itself
will be zero as it actually takes nothing to go to itself.
3. In every step of the algorithm, it tries to minimize the cost for each vertex.
4. For every unvisited neighbor (V2, V3) of the current vertex (V1) calculate the new cost
from V1.
6. When all the neighbors of the current node are visited and cost has been calculated,
mark the current node V1 as visited and remove it from the unvisited list.
7. Select next vertex with smallest cost from the unvisited list and repeat from step 4.
6
8. The algorithm finally ends when there are no unvisited nodes left.
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Example
Consider the map below. The cities have been selected and marked from alphabets A
to F and every edge has a cost associated with it.
We need to travel from Bengaluru to all other places and we have to identify what are
the shortest paths with minimal cost from Bengaluru to other destinations.
4
4
05-02-2021 7
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
1. Convert problem to its graph equivalent.
Upon conversion, we get the below representation. All the
cities have been replaced by the alphabets associated with it
and the edges have the cost value (to go from one node to
other) displayed on it.
05-02-2021 9
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Applications
• IP routing to find Open shortest Path First: Open Shortest Path First (OSPF) is a link-
state routing protocol that is used to find the best path between the source and the
destination router using its own Shortest Path First. Dijkstra’s algorithm is widely used
in the routing protocols required by the routers to update their forwarding table. The
algorithm provides the shortest cost path from the source router to other routers in the
network.
• Social Networking Applications: In many applications we might have seen the app
suggests the list of friends that a particular user may know. The Dijkstra algorithm can
be applied using the shortest path between users measured through connections among
them.
05-02-2021 10
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
• Robotic Path: The drones/robots which are automated and are used to deliver the
packages to a specific location or used for a task are loaded with this algorithm module
so that when the source and destination is known, the robot/drone moves in the ordered
direction by following the shortest path to keep delivering the package in a minimum
amount of time.
05-02-2021 11
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Conclusion
Dijkstra’s Algorithm is basically used find the shortest path between a given node (which
is called the "source node") and all other nodes in a graph.
05-02-2021 12
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
05-02-2021 13