SlideShare ist ein Scribd-Unternehmen logo
1 von 30
.Shortest Path Problems
- Greedy Approach
INTRODUCTION
Dijkstra’s algorithm calculates the least distance
from a starting vertex to a destination vertex from
the given weighted graph
Input:
• A weighted graph
• Starting vertex
• Destination vertex
Output:
A graph which connects all the vertices with least
distance
Dijkstra's Algorithm
Input:
a weighted digraph G=(V,E) with positive edge weights
a source node s V∈
Initialization:
d[s]=0
for each vertex x V-s∈
d[x]=infinity
Mark all the vertices as unprocessed
Iteration:
for i=1 to |V|
Choose an unprocessed vertex x from V with minimum d[x]
Mark x as processed
for all y adj(x)∈
if d[y] > d[x]+w(x,y)
d[y] = d[x]+w(x,y)
Dijkstra's Algorithm With PATH
Input:
a weighted digraph G=(V,E) with positive edge weights
a source node s V∈
Initialization:
d[s]=0 predecessor [ s ] = undefined
for each vertex x V-s∈
d[x]=infinity
Mark all the vertices as unprocessed
Iteration:
for i=1 to |V|
Choose an unprocessed vertex x from V with minimum d[x]
Mark x as processed
for all y adj(x)∈
if d[y] > d[x]+w(x,y)
d[y] = d[x]+w(x,y)
predecessor [ y ] = x
Printing the Distance and path
for each vertex v
{
print Distance d[v]
print_path(v);
}
print_path(v)
{
if (v is undefined)
return;
else
print_path ( prdecessor[v] ); // note recursion
print v
}
C Code
for(i=1; i<=numofvertices; i++)
{
printf("nDistance : %d ::: Path: ",distance[i]);
print_path(i);
}
void print_path(int i)
{
if (i==-1)
return;
else
print_path(prdecessor[i]);
Assumes that vertices are
numbered from 1.
distance array and
predecessor array are
computed by dijkstra
algorithm
-1 is undefined vertex
Dijkstra's Shortest Path Algorithm
Find shortest path from s to t.
7
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
Dijkstra's Shortest Path Algorithm 8
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
∞
∞
∞
∞
∞
∞
∞
0
distance label
S = { }
PQ = { s, 2, 3, 4, 5, 6, 7, t }
Dijkstra's Shortest Path Algorithm 9
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
∞
∞
∞
∞
∞
∞
∞
0
distance label
S = { }
PQ = { s, 2, 3, 4, 5, 6, 7, t }
delmin
Dijkstra's Shortest Path Algorithm
10
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
distance label
S = { s }
PQ = { 2, 3, 4, 5, 6, 7, t }
decrease key
∞X
∞
∞X
X
Dijkstra's Shortest Path Algorithm 11
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
distance label
S = { s }
PQ = { 2, 3, 4, 5, 6, 7, t }
∞X
∞
∞X
X
delmin
Dijkstra's Shortest Path Algorithm
12
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }
∞X
∞
∞X
X
Dijkstra's Shortest Path Algorithm
13
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }
∞X
∞
∞X
X
decrease key
X 33
Dijkstra's Shortest Path Algorithm
14
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
S = { s, 2 }
PQ = { 3, 4, 5, 6, 7, t }
∞X
∞
∞X
X
X 33
delmin
Dijkstra's Shortest Path Algorithm15
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
∞
14
∞
0
S = { s, 2, 6 }
PQ = { 3, 4, 5, 7, t }
∞X
∞
∞X
X
X 33
44
X
X
32
Dijkstra's Shortest Path Algorithm16
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 6 }
PQ = { 3, 4, 5, 7, t }
∞X
∞
∞X
X
44
X
delmin
∞X 33X
32
Dijkstra's Shortest Path Algorithm
17
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 6, 7 }
PQ = { 3, 4, 5, t }
∞X
∞
∞X
X
44
X
35X
59 X
24
∞X 33X
32
Dijkstra's Shortest Path Algorithm 18
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 6, 7 }
PQ = { 3, 4, 5, t }
∞X
∞
∞X
X
44
X
35X
59 X
delmin
∞X 33X
32
Dijkstra's Shortest Path Algorithm
19
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 6, 7 }
PQ = { 4, 5, t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
∞X 33X
32
Dijkstra's Shortest Path Algorithm
20
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 6, 7 }
PQ = { 4, 5, t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
delmin
∞X 33X
32
24
Dijkstra's Shortest Path Algorithm
21
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 5, 6, 7 }
PQ = { 4, t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
24
X50
X45
∞X 33X
32
Dijkstra's Shortest Path Algorithm
22
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 5, 6, 7 }
PQ = { 4, t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
24
X50
X45
delmin
∞X 33X
32
Dijkstra's Shortest Path Algorithm 23
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 4, 5, 6, 7 }
PQ = { t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
24
X50
X45
∞X 33X
32
Dijkstra's Shortest Path Algorithm
24
s
3
t
2
6
7
4
5
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 4, 5, 6, 7 }
PQ = { t }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
X50
X45
delmin
∞X 33X
32
24
Dijkstra's Shortest Path Algorithm 25
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 4, 5, 6, 7, t }
PQ = { }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
X50
X45
∞X 33X
32
Dijkstra's Shortest Path Algorithm 26
s
3
t
2
6
7
4
5
24
18
2
9
14
15
5
30
20
44
16
11
6
19
6
15
9
∞
∞
14
∞
0
S = { s, 2, 3, 4, 5, 6, 7, t }
PQ = { }
∞X
∞
∞X
X
44
X
35X
59 XX51
X 34
X50
X45
∞X 33X
32
ASSESSMENT
Single Source Shortest Path
1
2
76
5
4
3
5
3
1
7
5
4
9
4
6
8
1
4
1
Dijkstra's Algorithm - Greedy Approach for Shortest Path Problems

Weitere ähnliche Inhalte

Was ist angesagt?

All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithmSrikrishnan Suresh
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithmsana younas
 
My presentation all shortestpath
My presentation all shortestpathMy presentation all shortestpath
My presentation all shortestpathCarlostheran
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Mohanlal Sukhadia University (MLSU)
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Traian Rebedea
 
2.6 all pairsshortestpath
2.6 all pairsshortestpath2.6 all pairsshortestpath
2.6 all pairsshortestpathKrish_ver2
 
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmBellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmFulvio Corno
 
Algorithms of graph
Algorithms of graphAlgorithms of graph
Algorithms of graphgetacew
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysisgarishma bhatia
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithmtaimurkhan803
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmAcad
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)Madhu Bala
 
DISCRETE LOGARITHM PROBLEM
DISCRETE LOGARITHM PROBLEMDISCRETE LOGARITHM PROBLEM
DISCRETE LOGARITHM PROBLEMMANISH KUMAR
 

Was ist angesagt? (20)

All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
My presentation all shortestpath
My presentation all shortestpathMy presentation all shortestpath
My presentation all shortestpath
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Shortest path algorithms
Shortest path algorithmsShortest path algorithms
Shortest path algorithms
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7Algorithm Design and Complexity - Course 7
Algorithm Design and Complexity - Course 7
 
Optimisation random graph presentation
Optimisation random graph presentationOptimisation random graph presentation
Optimisation random graph presentation
 
2.6 all pairsshortestpath
2.6 all pairsshortestpath2.6 all pairsshortestpath
2.6 all pairsshortestpath
 
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s AlgorithmBellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
Bellman-Ford-Moore Algorithm and Dijkstra’s Algorithm
 
Algorithms of graph
Algorithms of graphAlgorithms of graph
Algorithms of graph
 
Topological sorting
Topological sortingTopological sorting
Topological sorting
 
Data Algorithms And Analysis
Data Algorithms And AnalysisData Algorithms And Analysis
Data Algorithms And Analysis
 
Bellmanford
BellmanfordBellmanford
Bellmanford
 
21 All Pairs Shortest Path
21 All Pairs Shortest Path21 All Pairs Shortest Path
21 All Pairs Shortest Path
 
Bellman ford Algorithm
Bellman ford AlgorithmBellman ford Algorithm
Bellman ford Algorithm
 
20 Single Source Shorthest Path
20 Single Source Shorthest Path20 Single Source Shorthest Path
20 Single Source Shorthest Path
 
Prim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithmPrim Algorithm and kruskal algorithm
Prim Algorithm and kruskal algorithm
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
DISCRETE LOGARITHM PROBLEM
DISCRETE LOGARITHM PROBLEMDISCRETE LOGARITHM PROBLEM
DISCRETE LOGARITHM PROBLEM
 

Andere mochten auch

1.5 weka an intoduction
1.5 weka an intoduction1.5 weka an intoduction
1.5 weka an intoductionKrish_ver2
 
Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3AtakanAral
 
Top-k shortest path
Top-k shortest pathTop-k shortest path
Top-k shortest pathredhatdb
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Multi-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureMulti-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureUmair Amjad
 
5.5 back track
5.5 back track5.5 back track
5.5 back trackKrish_ver2
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashingKrish_ver2
 
Intel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processorsIntel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processorsFadyMorris
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classificationKrish_ver2
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
 
Intel I3,I5,I7 Processor
Intel I3,I5,I7 ProcessorIntel I3,I5,I7 Processor
Intel I3,I5,I7 Processorsagar solanky
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...IOSR Journals
 

Andere mochten auch (17)

1.5 weka an intoduction
1.5 weka an intoduction1.5 weka an intoduction
1.5 weka an intoduction
 
Graphs
GraphsGraphs
Graphs
 
Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3
 
Top-k shortest path
Top-k shortest pathTop-k shortest path
Top-k shortest path
 
2.5 graph dfs
2.5 graph dfs2.5 graph dfs
2.5 graph dfs
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
2.5 dfs & bfs
2.5 dfs & bfs2.5 dfs & bfs
2.5 dfs & bfs
 
Multi-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureMulti-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architecture
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
4.4 external hashing
4.4 external hashing4.4 external hashing
4.4 external hashing
 
Intel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processorsIntel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processors
 
2.4 rule based classification
2.4 rule based classification2.4 rule based classification
2.4 rule based classification
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
 
Intel Core i7 Processors
Intel Core i7 ProcessorsIntel Core i7 Processors
Intel Core i7 Processors
 
Intel I3,I5,I7 Processor
Intel I3,I5,I7 ProcessorIntel I3,I5,I7 Processor
Intel I3,I5,I7 Processor
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...
 

Ähnlich wie Dijkstra's Algorithm - Greedy Approach for Shortest Path Problems

Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
Jaimin chp-5 - network layer- 2011 batch
Jaimin   chp-5 - network layer- 2011 batchJaimin   chp-5 - network layer- 2011 batch
Jaimin chp-5 - network layer- 2011 batchJaimin Jani
 
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdfDKTaxation
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsrLinawati Adiman
 
Graphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & AlgorithumsGraphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & AlgorithumsAin-ul-Moiz Khawaja
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's AlgorithmArijitDhali
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfShiwani Gupta
 
Randomized algorithms all pairs shortest path
Randomized algorithms  all pairs shortest pathRandomized algorithms  all pairs shortest path
Randomized algorithms all pairs shortest pathMohammad Akbarizadeh
 
Implementation of dijsktra’s algorithm in parallel
Implementation of dijsktra’s algorithm in parallelImplementation of dijsktra’s algorithm in parallel
Implementation of dijsktra’s algorithm in parallelMeenakshi Muthuraman
 
Explicit upper bound for the function of sum of divisors
Explicit upper bound for the function of sum of divisorsExplicit upper bound for the function of sum of divisors
Explicit upper bound for the function of sum of divisorsAlexander Decker
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2MuradAmn
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Saikrishna Tanguturu
 
19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structureEMEY GUJJAR
 

Ähnlich wie Dijkstra's Algorithm - Greedy Approach for Shortest Path Problems (20)

dijkstras example.ppt
dijkstras example.pptdijkstras example.ppt
dijkstras example.ppt
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
Jaimin chp-5 - network layer- 2011 batch
Jaimin   chp-5 - network layer- 2011 batchJaimin   chp-5 - network layer- 2011 batch
Jaimin chp-5 - network layer- 2011 batch
 
12_Graph.pptx
12_Graph.pptx12_Graph.pptx
12_Graph.pptx
 
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
01-05-2023, SOL_DU_MBAFT_6202_Dijkstra’s Algorithm Dated 1st May 23.pdf
 
Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsr
 
Graphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & AlgorithumsGraphs > Discrete structures , Data Structures & Algorithums
Graphs > Discrete structures , Data Structures & Algorithums
 
correlation (3).pdf
correlation (3).pdfcorrelation (3).pdf
correlation (3).pdf
 
Dijkstra algorithm
Dijkstra algorithmDijkstra algorithm
Dijkstra algorithm
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
Randomized algorithms all pairs shortest path
Randomized algorithms  all pairs shortest pathRandomized algorithms  all pairs shortest path
Randomized algorithms all pairs shortest path
 
Implementation of dijsktra’s algorithm in parallel
Implementation of dijsktra’s algorithm in parallelImplementation of dijsktra’s algorithm in parallel
Implementation of dijsktra’s algorithm in parallel
 
Explicit upper bound for the function of sum of divisors
Explicit upper bound for the function of sum of divisorsExplicit upper bound for the function of sum of divisors
Explicit upper bound for the function of sum of divisors
 
04 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x204 greedyalgorithmsii 2x2
04 greedyalgorithmsii 2x2
 
Correlation & regression uwsb
Correlation & regression   uwsbCorrelation & regression   uwsb
Correlation & regression uwsb
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
Correlation & regression
Correlation & regression Correlation & regression
Correlation & regression
 
Dijkstra c
Dijkstra cDijkstra c
Dijkstra c
 
19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure19 prim,kruskal alg. in data structure
19 prim,kruskal alg. in data structure
 

Mehr von Krish_ver2

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back trackingKrish_ver2
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02Krish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructuresKrish_ver2
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructuresKrish_ver2
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithmKrish_ver2
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03Krish_ver2
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-iKrish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02Krish_ver2
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing extKrish_ver2
 

Mehr von Krish_ver2 (20)

5.5 back tracking
5.5 back tracking5.5 back tracking
5.5 back tracking
 
5.5 back tracking 02
5.5 back tracking 025.5 back tracking 02
5.5 back tracking 02
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randomized datastructures
5.4 randomized datastructures5.4 randomized datastructures
5.4 randomized datastructures
 
5.4 randamized algorithm
5.4 randamized algorithm5.4 randamized algorithm
5.4 randamized algorithm
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
5.3 dyn algo-i
5.3 dyn algo-i5.3 dyn algo-i
5.3 dyn algo-i
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 
5.1 greedyyy 02
5.1 greedyyy 025.1 greedyyy 02
5.1 greedyyy 02
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
4.4 hashing ext
4.4 hashing  ext4.4 hashing  ext
4.4 hashing ext
 
4.2 bst
4.2 bst4.2 bst
4.2 bst
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
 
4.2 bst 02
4.2 bst 024.2 bst 02
4.2 bst 02
 

Kürzlich hochgeladen

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Kürzlich hochgeladen (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Dijkstra's Algorithm - Greedy Approach for Shortest Path Problems

  • 1. .Shortest Path Problems - Greedy Approach
  • 2. INTRODUCTION Dijkstra’s algorithm calculates the least distance from a starting vertex to a destination vertex from the given weighted graph Input: • A weighted graph • Starting vertex • Destination vertex Output: A graph which connects all the vertices with least distance
  • 3. Dijkstra's Algorithm Input: a weighted digraph G=(V,E) with positive edge weights a source node s V∈ Initialization: d[s]=0 for each vertex x V-s∈ d[x]=infinity Mark all the vertices as unprocessed Iteration: for i=1 to |V| Choose an unprocessed vertex x from V with minimum d[x] Mark x as processed for all y adj(x)∈ if d[y] > d[x]+w(x,y) d[y] = d[x]+w(x,y)
  • 4. Dijkstra's Algorithm With PATH Input: a weighted digraph G=(V,E) with positive edge weights a source node s V∈ Initialization: d[s]=0 predecessor [ s ] = undefined for each vertex x V-s∈ d[x]=infinity Mark all the vertices as unprocessed Iteration: for i=1 to |V| Choose an unprocessed vertex x from V with minimum d[x] Mark x as processed for all y adj(x)∈ if d[y] > d[x]+w(x,y) d[y] = d[x]+w(x,y) predecessor [ y ] = x
  • 5. Printing the Distance and path for each vertex v { print Distance d[v] print_path(v); } print_path(v) { if (v is undefined) return; else print_path ( prdecessor[v] ); // note recursion print v }
  • 6. C Code for(i=1; i<=numofvertices; i++) { printf("nDistance : %d ::: Path: ",distance[i]); print_path(i); } void print_path(int i) { if (i==-1) return; else print_path(prdecessor[i]); Assumes that vertices are numbered from 1. distance array and predecessor array are computed by dijkstra algorithm -1 is undefined vertex
  • 7. Dijkstra's Shortest Path Algorithm Find shortest path from s to t. 7 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6
  • 8. Dijkstra's Shortest Path Algorithm 8 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 0 distance label S = { } PQ = { s, 2, 3, 4, 5, 6, 7, t }
  • 9. Dijkstra's Shortest Path Algorithm 9 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 0 distance label S = { } PQ = { s, 2, 3, 4, 5, 6, 7, t } delmin
  • 10. Dijkstra's Shortest Path Algorithm 10 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 distance label S = { s } PQ = { 2, 3, 4, 5, 6, 7, t } decrease key ∞X ∞ ∞X X
  • 11. Dijkstra's Shortest Path Algorithm 11 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 distance label S = { s } PQ = { 2, 3, 4, 5, 6, 7, t } ∞X ∞ ∞X X delmin
  • 12. Dijkstra's Shortest Path Algorithm 12 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t } ∞X ∞ ∞X X
  • 13. Dijkstra's Shortest Path Algorithm 13 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t } ∞X ∞ ∞X X decrease key X 33
  • 14. Dijkstra's Shortest Path Algorithm 14 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 S = { s, 2 } PQ = { 3, 4, 5, 6, 7, t } ∞X ∞ ∞X X X 33 delmin
  • 15. Dijkstra's Shortest Path Algorithm15 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ ∞ 14 ∞ 0 S = { s, 2, 6 } PQ = { 3, 4, 5, 7, t } ∞X ∞ ∞X X X 33 44 X X 32
  • 16. Dijkstra's Shortest Path Algorithm16 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 6 } PQ = { 3, 4, 5, 7, t } ∞X ∞ ∞X X 44 X delmin ∞X 33X 32
  • 17. Dijkstra's Shortest Path Algorithm 17 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 6, 7 } PQ = { 3, 4, 5, t } ∞X ∞ ∞X X 44 X 35X 59 X 24 ∞X 33X 32
  • 18. Dijkstra's Shortest Path Algorithm 18 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 6, 7 } PQ = { 3, 4, 5, t } ∞X ∞ ∞X X 44 X 35X 59 X delmin ∞X 33X 32
  • 19. Dijkstra's Shortest Path Algorithm 19 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 6, 7 } PQ = { 4, 5, t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 ∞X 33X 32
  • 20. Dijkstra's Shortest Path Algorithm 20 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 6, 7 } PQ = { 4, 5, t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 delmin ∞X 33X 32 24
  • 21. Dijkstra's Shortest Path Algorithm 21 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 5, 6, 7 } PQ = { 4, t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 24 X50 X45 ∞X 33X 32
  • 22. Dijkstra's Shortest Path Algorithm 22 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 5, 6, 7 } PQ = { 4, t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 24 X50 X45 delmin ∞X 33X 32
  • 23. Dijkstra's Shortest Path Algorithm 23 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 4, 5, 6, 7 } PQ = { t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 24 X50 X45 ∞X 33X 32
  • 24. Dijkstra's Shortest Path Algorithm 24 s 3 t 2 6 7 4 5 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 4, 5, 6, 7 } PQ = { t } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 X50 X45 delmin ∞X 33X 32 24
  • 25. Dijkstra's Shortest Path Algorithm 25 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 X50 X45 ∞X 33X 32
  • 26. Dijkstra's Shortest Path Algorithm 26 s 3 t 2 6 7 4 5 24 18 2 9 14 15 5 30 20 44 16 11 6 19 6 15 9 ∞ ∞ 14 ∞ 0 S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } ∞X ∞ ∞X X 44 X 35X 59 XX51 X 34 X50 X45 ∞X 33X 32
  • 27.
  • 29. Single Source Shortest Path 1 2 76 5 4 3 5 3 1 7 5 4 9 4 6 8 1 4 1