Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Introduction to Dijkstra's

Algorithm
Dijkstra's algorithm, named after Dutch computer scientist Edsger W. Dijkstra,
is a widely-used algorithm for finding the shortest path between nodes in a
graph. It's particularly helpful in network routing and transportation systems,
where finding the most efficient route is crucial.

by Chakshu,09 E
Overview of the algorithm's steps
Step 1: Initialize the algorithm Step 2: Select the next node with the
minimum distance
Set the initial node's distance to 0 and all
other nodes' distances to infinity. Choose the unvisited node with the smallest
known distance from the start node.

Step 3: Update the distances of Step 4: Repeat steps 2 and 3 until all
neighboring nodes nodes are visited
Update the distances of adjacent nodes if a Continue the process until all nodes are
shorter path is found through the current visited and the shortest path to each node is
node. determined.
Step 1: Initialize the algorithm
1 Set Initial Node
Choose the starting node and set its distance from the source as 0.

2 Set Unvisited Nodes


Set the initial distance of all other nodes to infinity and mark them as unvisited.

3 Set Current Node


Set the current node as the starting node for the rest of the algorithm.
Step 2: Select the next node
with the minimum distance
Calculate tentative distances: Calculate the tentative distances from the
initial node to all its neighboring nodes.

Choose the node with the shortest distance: Select the node with the
minimum tentative distance as the next node to explore.
Update the distances: Update the distances of the neighboring nodes
based on the selected node's distance.
Step 3: Update the distances of neighboring
nodes
1 Calculate tentative distances
For each neighboring node, calculate the tentative distances by summing the distance to
the current node and the edge weight.

2 Compare tentative distances


Compare the tentative distances with the current known distances to the neighboring
nodes and update if the tentative distance is smaller.

3 Repeat for all neighbors


Repeat this process for all neighboring nodes to ensure the accurate updating of their
distances.
Step 4: Repeat steps 2 and 3 until all
nodes are visited
1 Repeat Step 2
Select the next node with the minimum distance to start the iteration.

2 Repeat Step 3
Update the distances of neighboring nodes to continue the iteration.

3 Complete All Nodes


Continue repeating steps 2 and 3 until all nodes in the graph are visited.
Example: Applying Dijkstra's Algorithm to
a graph
Dijkstra's algorithm is applied to find the
shortest path in a graph.

It starts from a source node and calculates the


minimum distance to all other nodes.

The process continues until all nodes are visited


and the shortest path is found.
Conclusion and key
takeaways
After understanding Dijkstra's Algorithm, it's clear that it's a powerful tool for
finding the shortest path in a graph.

By identifying the key steps and considerations, it becomes possible to apply


this algorithm in various real-world scenarios, from logistics to network
routing.
example of Dijkstra's Algorithm

Step-by-Step Process Graph Visualization Pathfinding Example


An illustration showing the A visual representation of a An example of pathfinding
sequential steps of Dijkstra's graph with labeled nodes and using Dijkstra's Algorithm,
Algorithm, visually edges, highlighting the process showcasing the efficient
demonstrating its application. of finding the shortest path. discovery of the shortest path.
numerical on Dijkstra's Algorithm

O(V^2) O(E + VlogV)


Time Complexity Space Complexity
The time complexity of Dijkstra's Algorithm. The space complexity of Dijkstra's Algorithm.

You might also like