DIJKSTRA'S ALGORITHM
Dijkstra's algorithmis a graph search algorithm that solves
the single-source shortest path problem for a graph with
non-negative edge weights.
It was developed by EdsgerW. Dijkstra in 1956 and
published in 1959.
The algorithm is widely applied in network routing, GPS
navigation, and AI pathfinding.
KEY TERMS
PriorityQueue: A data structure used in Dijkstra's algorithm to efficiently retrieve
the next node to process, based on the current minimum distance from the source
node. Common implementations include binary heaps.
Distance Table: A data structure that stores the current shortest distance from the
source node to each node in the graph. Initially, the distance to the source node is
zero, and to all others, it is infinity.
Relaxation:The algorithm's core concept is relaxation, which involves updating
the shortest path estimates as the algorithm progresses
5.
DETAILED STEPS OFDIJKSTRA'S
ALGORITHM
Assign an initial distance of 0 to the source node and
infinity to all others.
Use a priority queue to select the node with the smallest
known distance.
Update the distances of neighboring nodes if a shorter
path is found.
Repeat until all nodes have been visited.
Given an undirected,weighted graph with V vertices numbered from 0 to V-1 with E edges
Shortest Paths:
For 0 to 1 ,minimum distance will be 4.By following path 0 1.For 0 to 2 minimum distance will
be 8, By following path 02 for 1 to 3 minimum distance will be 10.BY following path 0 2 3
for 0 to 4 minimum distance will be 10 .by following 01 4
Note:The Graph is connected and doesn't contain any negative weight edge.
15.
IMPLEMENTATION OF DIJKSTRA'SALGORITHM
PSEUDOCODE OVERVIEW:
The time complexity of Dijkstra’s algorithm when using a min-heap is O(E log V), where E is the number of
edges and V is the number of vertices. So,the complexity of Dijkstra’s algorithm is O(E log V)
Create vertex set Q
For each vertex v in graph
dist [v]= ∞
add vto Q
dist[source]=0
While Q is not empty
u=Extract-min[Q]
For each neighbor v of u
relax (u,v)
O(v)
O(log v) ,
16.
STEP-BY-STEP IMPLEMENTATION
Setdist[source]=0 and all other distances as infinity.
Push the source node into the min heap as a pair <distance, node> i.e., <0, source>.
→
Pop the top element (node with the smallest distance) from the min heap.
For each adjacent neighbor of the current node:
Calculate the distance using the formula:
dist[v] = dist[u] + weight[u][v]
If this new distance is shorter than the current dist[v], update it.
Push the updated pair <dist[v], v> into the min heap
Repeat step 3 until the min heap is empty.
Return the distance array, which holds the shortest distance from the source to all nodes.
17.
Time Complexity:O(E*logV),Where E is the number of edges and V is the
number of vertices.
Auxiliary Space: O(V),Where V is the number of vertices,We do not count the
adjacency list in auxiliary space as it is necessary for representing the input graph.
18.
LIMITATIONS AND CONSIDERATIONS
Dijkstra's algorithm does not work with graphs that contain negative weight edges,
which can lead to incorrect results.
For graphs with such characteristics, the Bellman-Ford algorithm is
recommended as it can correctly handle negative weights
19.
APPLICATIONS
Dijkstra's algorithmis widely used in various applications, including:
Navigation Systems: Finding the shortest route in mapping services (e.g., Google
Maps).
Network Routing: Determining the most efficient path for data transfer in
telecommunications.
Game Development: Enabling character navigation and movement through a
virtual environment.
Robotics: Planning routes for robotic navigation.