SlideShare a Scribd company logo
Dijkstra’s Algorithm
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.
Example 01:
Solution
Visited
Vertex
A B C D E F
A 0 ∞ ∞ ∞ ∞ ∞
F 14 9 ∞ ∞ 7
C 14 9 ∞ 22
B 11 ∞ 20
D 19 20
E 20
if(d(u) + c(u,v) < d(v))
then d(v) = d(u) + c(u,v)
Shortest path from A to E: A, C, E
Distance = 9 + 11 = 20
A
B D
C
F
E
14
8
6
15
7
9
10
11
2
Example 02:
Solution
Visited
Vertex
A B C D E F
A 0 ∞ ∞ ∞ ∞ ∞
B 2 5 ∞ ∞ 11
C 5 7 15 11
D 7 15 11
F 15 11
E 15
if(d(u) + c(u,v) < d(v))
then d(v) = d(u) + c(u,v)
Shortest path from A to E: A, B, E
Distance = 2 + 13 = 15
Dijkstra’s Algorithm Pseudocode
function dijkstra(G, S)
for each vertex V in G
distance[V] <- infinite
previous[V] <- NULL
If V != S, add V to Priority Queue Q
A
F D
B
C
E
11
17
1
12
5
2
8 13
5
distance[S] <- 0
while Q IS NOT EMPTY
U <- Extract MIN from Q
for each unvisited neighbour V of U
tempDistance <- distance[U] + edge_weight(U, V)
if tempDistance < distance[V]
distance[V] <- tempDistance
previous[V] <- U
return distance[], previous[]

More Related Content

PPTX
Dijkstra’S Algorithm
PPTX
Stack and its applications
PDF
Quick Sort , Merge Sort , Heap Sort
PPTX
Binary Search Tree
PPTX
Dijkstra's Algorithm
PPTX
Knapsack problem algorithm, greedy algorithm
PDF
Search strategies
PDF
Red black tree
Dijkstra’S Algorithm
Stack and its applications
Quick Sort , Merge Sort , Heap Sort
Binary Search Tree
Dijkstra's Algorithm
Knapsack problem algorithm, greedy algorithm
Search strategies
Red black tree

What's hot (20)

PPTX
Ppt bubble sort
PPT
Stack application
PPTX
Complex Variable & Numerical Method
PDF
Topological Sort
PPTX
Tic tac toe simple ai game
PDF
Recurrence relation solutions
PPT
Divide and conquer
PDF
Functions in discrete mathematics
PPTX
Breadth first search (Bfs)
PPTX
Insertion Sorting
PPTX
Newton's forward & backward interpolation
PDF
Minimum spanning tree
PPTX
Tower Of Hanoi
PPTX
Bellman ford algorithm
PPTX
Merge sort algorithm
PPT
Greedy Algorithm
PPTX
Dfs presentation
PPTX
Dijkstra's algorithm presentation
PPT
1.1 binary tree
PPTX
Coin Change : Greedy vs Dynamic Programming
Ppt bubble sort
Stack application
Complex Variable & Numerical Method
Topological Sort
Tic tac toe simple ai game
Recurrence relation solutions
Divide and conquer
Functions in discrete mathematics
Breadth first search (Bfs)
Insertion Sorting
Newton's forward & backward interpolation
Minimum spanning tree
Tower Of Hanoi
Bellman ford algorithm
Merge sort algorithm
Greedy Algorithm
Dfs presentation
Dijkstra's algorithm presentation
1.1 binary tree
Coin Change : Greedy vs Dynamic Programming
Ad

Similar to Dijkstra algorithm (20)

PDF
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
PPTX
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
PPTX
dms slide discrete mathematics sem 2 engineering
PPT
Unit26 shortest pathalgorithm
PPTX
Dijkstras-Algorithm-Finding-the-Shortest-Path.pptx
PDF
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
PDF
Dijkstra's Algorithm
PPTX
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
PPTX
Data structures and algorithms Dijkstra’s Algorithm (1).pptx
PPTX
Dijkstra Searching Algorithms Shortest.pptx
PPT
Dijsktra’s Sortest path algorithm
PPT
Dijkstra algorithm ds 57612334t4t44.ppt
PPT
Dijkstra Shortest Path Algorithm in Network.ppt
PPTX
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
PPTX
Algo labpresentation a_group
PDF
24. Shortest Path Algorithm.pdf
PPT
Dijesktra 1.ppt
PPT
Dijkstra.ppt
PDF
Lecture 16 - Dijkstra's Algorithm.pdf
PPTX
Dijkstra’s algorithm
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
Deixtras Algorithm.pptxdjjdjdjdjddddddddddddddd
dms slide discrete mathematics sem 2 engineering
Unit26 shortest pathalgorithm
Dijkstras-Algorithm-Finding-the-Shortest-Path.pptx
Djikstra’s Algorithm. Approach to shortest path algorithm with greedy method
Dijkstra's Algorithm
Dijkstra Algorithm Presentation -the shortest path finding algorithm.pptx
Data structures and algorithms Dijkstra’s Algorithm (1).pptx
Dijkstra Searching Algorithms Shortest.pptx
Dijsktra’s Sortest path algorithm
Dijkstra algorithm ds 57612334t4t44.ppt
Dijkstra Shortest Path Algorithm in Network.ppt
SEMINAR ON SHORTEST PATH ALGORITHMS.pptx
Algo labpresentation a_group
24. Shortest Path Algorithm.pdf
Dijesktra 1.ppt
Dijkstra.ppt
Lecture 16 - Dijkstra's Algorithm.pdf
Dijkstra’s algorithm
Ad

More from A. S. M. Shafi (20)

DOCX
Data Warehouse Schema (Star, Snowflake).docx
PDF
Correlation Analysis in Machine Learning.pdf
PDF
Naive Bayes and Decision Tree Algorithm.pdf
PDF
Frequent Pattern Growth Mining Algorithm.pdf
PDF
Direct Hashing and Pruning Algorithm in Data MIning.pdf
PDF
Association Rule Mining with Apriori Algorithm.pdf
PDF
HITS Algorithm in Data and Web MIning.pdf
PDF
Page Rank Algorithm in Data Mining and Web Application.pdf
PDF
K Nearest Neighbor Classifier in Machine Learning.pdf
PDF
K Means Clustering Algorithm in Machine Learning.pdf
PDF
2D Transformation in Computer Graphics
PDF
3D Transformation in Computer Graphics
PDF
Projection
PDF
2D Transformation
PDF
Line drawing algorithm
PDF
Fragmentation
PDF
File organization
PDF
Bankers algorithm
PDF
RR and priority scheduling
PDF
Fcfs and sjf
Data Warehouse Schema (Star, Snowflake).docx
Correlation Analysis in Machine Learning.pdf
Naive Bayes and Decision Tree Algorithm.pdf
Frequent Pattern Growth Mining Algorithm.pdf
Direct Hashing and Pruning Algorithm in Data MIning.pdf
Association Rule Mining with Apriori Algorithm.pdf
HITS Algorithm in Data and Web MIning.pdf
Page Rank Algorithm in Data Mining and Web Application.pdf
K Nearest Neighbor Classifier in Machine Learning.pdf
K Means Clustering Algorithm in Machine Learning.pdf
2D Transformation in Computer Graphics
3D Transformation in Computer Graphics
Projection
2D Transformation
Line drawing algorithm
Fragmentation
File organization
Bankers algorithm
RR and priority scheduling
Fcfs and sjf

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chinmaya Tiranga quiz Grand Finale.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Types and Its function , kingdom of life
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Anesthesia in Laparoscopic Surgery in India
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Final Presentation General Medicine 03-08-2024.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

Dijkstra algorithm

  • 1. Dijkstra’s Algorithm 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. Example 01: Solution Visited Vertex A B C D E F A 0 ∞ ∞ ∞ ∞ ∞ F 14 9 ∞ ∞ 7 C 14 9 ∞ 22 B 11 ∞ 20 D 19 20 E 20 if(d(u) + c(u,v) < d(v)) then d(v) = d(u) + c(u,v) Shortest path from A to E: A, C, E Distance = 9 + 11 = 20 A B D C F E 14 8 6 15 7 9 10 11 2
  • 2. Example 02: Solution Visited Vertex A B C D E F A 0 ∞ ∞ ∞ ∞ ∞ B 2 5 ∞ ∞ 11 C 5 7 15 11 D 7 15 11 F 15 11 E 15 if(d(u) + c(u,v) < d(v)) then d(v) = d(u) + c(u,v) Shortest path from A to E: A, B, E Distance = 2 + 13 = 15 Dijkstra’s Algorithm Pseudocode function dijkstra(G, S) for each vertex V in G distance[V] <- infinite previous[V] <- NULL If V != S, add V to Priority Queue Q A F D B C E 11 17 1 12 5 2 8 13 5
  • 3. distance[S] <- 0 while Q IS NOT EMPTY U <- Extract MIN from Q for each unvisited neighbour V of U tempDistance <- distance[U] + edge_weight(U, V) if tempDistance < distance[V] distance[V] <- tempDistance previous[V] <- U return distance[], previous[]