尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Shortest Path
Algorithm
 DIJIKSTRA ALGORITHM
 BELLMEN ALGORITHM
 FLOYED WARSHALL ALGORITHM
Shortest Path Algorithm
 An algorithm that is designed essentially to
find a path of minimum length between two
specified vertices of a connected weighted
graph.
Single source Shortest path algorithm
o It is defined as
Cost of shortest path from a source
vertex u to a destination v.
s a
b c
Dijkstra’s Algorithm
Dijkstra’s algorithm is a greedy algorithm for
solving single source shortest path problem
that provide us with the shortest path from one
particular source node to all other nodes in the
given graph .
Rules of Dijkstra’s algorithm
 It can be applied on both directed and undirected
graph.
 It is applied on weighted graph.
 For the algorithm to be applicable the graph must
be connected.
a 3 b
4 5 1
c d
4
Cont…
 Dijkstra’s algorithm does not work for graphs with
negative weight edges. For graphs with negative
weight edges, Bellman_ford algorithm can be used.
 In Dijkstra’s algorithm always assign source vertex to
zero distance.
 Assign every other node a tentative distance.
Dijkstra’s AlgorithmDijkstra’s(G,W,S)
INITIALIZE-SINGLE-SOURCE(G,s)
1. for each vertex v ∈ 𝐺. 𝑉
2. v.d = ∞
3. v.𝜋 = 𝑁𝐼𝐿
4. s.d = 0
5. S = ∅
6. Q = G.V
7. while (Q≠ ∅)
8. u = dequeue_min(Q)
9. S = S ∪ 𝑢
10. for each vertex v∈ 𝐴𝑑𝑗 𝑢
11. if( v.d > u.d+ w(u,v) )
12. v.d = u.d + w (u,v) // update distance of v
13. v. 𝜋 = u
14. return v.d
BellMan-Algorithm
 Bellman–Ford algorithm. The Bellman–Ford
algorithm is an algorithm that computes shortest
paths from a single source vertex to all of the other
vertices in a weighted digraph. ... Negative edge
weights are found in various applications of graphs,
hence the usefulness of this algorithm.
Cont..
 It is similar to Dijkstra's algorithm but it can work
with graphs in which edges can have negative
weights.
 Negative weight edges can create negative weight
cycles i.e. a cycle which will reduce the total path
distance by coming back to the same point.
Cont..
 Shortest path algorithms
like Dijkstra's Algorithm that
aren't able to detect such a
cycle can give an incorrect
result because they can go
through a negative weight
cycle and reduce the path
length.
A B D E
2
1 3
2 -4
C
Uses of Algorithm
 This algorithm can be used on both weighted and
unweighted graphs.
 Like Dijkstra's shortest path algorithm, the Bellman-Ford
algorithm is guaranteed to find the shortest path in a graph.
 Though it is slower than Dijkstra's algorithm, Bellman-Ford is
capable of handling graphs that contain negative edge
weights, so it is more versatile.
ALGORITHM
1. for v in V:
2. v.distance = infinity
3. v.p = None
4. source.distance = 0
5. for i from 1 to |V| - 1:
6. for (u, v) in E:
7. relax(u, v)
Explanation
 The first for loop sets the distance to each vertex in
the graph to infinity. This is later changed for the
source vertex to equal zero. Also in that first for loop,
the p value for each vertex is set to nothing. This
value is a pointer to a predecessor vertex so that we
can create a path later.
 The next for loop simply goes through each edge (u,
v) in E and relaxes it. This process is done |V| - 1 times.
Relaxation Equation
 Relaxation is the most important step in Bellman-
Ford. It is what increases the accuracy of the
distance to any given vertex. Relaxation works by
continuously shortening the calculated distance
between vertices comparing that distance with
other known distances.
Example
 Take the baseball example from earlier. Let's say I think the
distance to the baseball stadium is 20 miles. However, I know
that the distance to the corner right before the stadium is 10
miles, and I know that from the corner to the stadium, the
distance is 1 mile. Clearly, the distance from me to the
stadium is at most 11 miles. So, I can update my belief to
reflect that. That is one cycle of relaxation, and it's done over
and over until the shortest paths are found
Relax Equation
1. relax(u, v):
2. if v.distance > u.distance + weight(u, v):
v.distance = u.distance + weight(u, v)
3. v.p = u
Negative Cycle
 Detecting Negative Cycles
 A very short and simple addition to the Bellman-Ford
algorithm can allow it to detect negative cycles, something
that is very important because it disallows shortest-path
finding altogether. After the Bellman-Ford algorithm
shown above has been run, one more short loop is required
to check for negative weight cycles.
 This psuedo-code is written as a high level descrpition of the
algorithm, not an implementation.
Cont..
1. for v in V:
2. v.distance = infinity
3. v.p = None
4. source.distance = 0
5. for i from 1 to |V| - 1:
6. for (u, v) in E:
7. relax(u, v) for (u, v) in E:
8. if v.distance > u.distance + weight(u, v):
9. print "A negative weight cycle exists"
Floyed Warshall ALgorithm
 Floyd–Warshall algorithm is an algorithm for
finding shortest paths in a weighted graph
 The Graph may be weighted with positive or
negative edge weights .
 The Graph may be directed or undirected.
Cont..
 If a node has not a direct path or
link to any other node then the
distance between these nodes
are infinite.
 If only one path between the two
nodes or vertices then it said to
be the shortest distance.
 The distance of a vertex to itself is
0.
Vo 10 V3
5 1
3
V1 V2
Example
0 1 2 3
0 0 5 inf 10
1 Inf 0 3 Inf
2 Inf Inf 0 1
3 inf inf Inf 0
Vo V3
V1 V2
5
10
1
3
Uses Of Shortest Path Algorithm
 Weighted graph
 Distance function or array
 Priority Queue
 Relaxation
Applications of Shortest Path Algorithm
 It is used in Google Map.
 It is used in finding Shortest Path.
 It is used in geographical Maps.
 To find locations of Map which refers to vertices of
graph.
 Distance between the location refers to edges.
 It is used in IP routing to find Open shortest Path First.
 It is used in the telephone network.

More Related Content

What's hot

Branch and bound
Branch and boundBranch and bound
Branch and bound
Dr Shashikant Athawale
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
vikas dhakane
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
Rashik Ishrak Nahian
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
Roshan Tailor
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
Gaurav Kolekar
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
MdSajjadulislamBappi
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Pankaj Thakur
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
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)
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
InteX Research Lab
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
Syed Maniruzzaman Pabel
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
Tamzida_Azad
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 

What's hot (20)

Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Backtracking
Backtracking  Backtracking
Backtracking
 
A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Single source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstraSingle source stortest path bellman ford and dijkstra
Single source stortest path bellman ford and dijkstra
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
A presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithmA presentation on prim's and kruskal's algorithm
A presentation on prim's and kruskal's algorithm
 
Bellman ford algorithm
Bellman ford algorithmBellman ford algorithm
Bellman ford algorithm
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
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)
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Floyd Warshall Algorithm
Floyd Warshall AlgorithmFloyd Warshall Algorithm
Floyd Warshall Algorithm
 
Kruskal’s Algorithm
Kruskal’s AlgorithmKruskal’s Algorithm
Kruskal’s Algorithm
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 

Similar to Shortest path algorithm

A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
Khoa Mac Tu
 
DAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
AndrewJohnson866415
 
Graph 3
Graph 3Graph 3
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
B.Kirron Reddi
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
sakthibalabalamuruga
 
The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
José Juan Herrera
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Benjamin Sach
 
dijkstra algo.ppt
dijkstra algo.pptdijkstra algo.ppt
dijkstra algo.ppt
Santhosh Krishna
 
Shortest Path Algorithm
Shortest Path AlgorithmShortest Path Algorithm
Shortest Path Algorithm
Anish Ansari
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
meisamstar
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
zefergaming
 
(148065320) dijistra algo
(148065320) dijistra algo(148065320) dijistra algo
(148065320) dijistra algo
Aravindharamanan S
 
Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10
Traian Rebedea
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraq
montaser185
 
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
DKTaxation
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
Kazi Emad
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha
 
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
Core Condor
 
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithmAAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
SantoshDood
 
Floyd aaaaaa
Floyd aaaaaaFloyd aaaaaa
Floyd aaaaaa
Pradeep Bisht
 

Similar to Shortest path algorithm (20)

A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
A study on_contrast_and_comparison_between_bellman-ford_algorithm_and_dijkstr...
 
DAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptxDAA_Presentation - Copy.pptx
DAA_Presentation - Copy.pptx
 
Graph 3
Graph 3Graph 3
Graph 3
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
The Floyd–Warshall algorithm
The Floyd–Warshall algorithmThe Floyd–Warshall algorithm
The Floyd–Warshall algorithm
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
 
dijkstra algo.ppt
dijkstra algo.pptdijkstra algo.ppt
dijkstra algo.ppt
 
Shortest Path Algorithm
Shortest Path AlgorithmShortest Path Algorithm
Shortest Path Algorithm
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Shortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdfShortest path by using suitable algorithm.pdf
Shortest path by using suitable algorithm.pdf
 
(148065320) dijistra algo
(148065320) dijistra algo(148065320) dijistra algo
(148065320) dijistra algo
 
Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10Algorithm Design and Complexity - Course 10
Algorithm Design and Complexity - Course 10
 
Bellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraqBellmanford . montaser hamza.iraq
Bellmanford . montaser hamza.iraq
 
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
 
Single sourceshortestpath by emad
Single sourceshortestpath by emadSingle sourceshortestpath by emad
Single sourceshortestpath by emad
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
 
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithmAAD_Lec-3-B-ShortestPaths.ppt  of design and analysis of algorithm
AAD_Lec-3-B-ShortestPaths.ppt of design and analysis of algorithm
 
Floyd aaaaaa
Floyd aaaaaaFloyd aaaaaa
Floyd aaaaaa
 

More from sana younas

7 habits of highly effective people
7 habits of highly effective people7 habits of highly effective people
7 habits of highly effective people
sana younas
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
sana younas
 
Binary search
Binary searchBinary search
Binary search
sana younas
 
circular linklist
circular linklistcircular linklist
circular linklist
sana younas
 
Link list 2
Link list 2Link list 2
Link list 2
sana younas
 
Link list 1
Link list 1Link list 1
Link list 1
sana younas
 
Heapsort 1
Heapsort 1Heapsort 1
Heapsort 1
sana younas
 
Arrays
ArraysArrays
Arrays
sana younas
 
Enterpise system
Enterpise systemEnterpise system
Enterpise system
sana younas
 
Database administration
Database administrationDatabase administration
Database administration
sana younas
 
Encoders
EncodersEncoders
Encoders
sana younas
 
Universal logic gate
Universal logic gateUniversal logic gate
Universal logic gate
sana younas
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
sana younas
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
sana younas
 
Memory management
Memory managementMemory management
Memory management
sana younas
 
Parallel adders
Parallel addersParallel adders
Parallel adders
sana younas
 

More from sana younas (16)

7 habits of highly effective people
7 habits of highly effective people7 habits of highly effective people
7 habits of highly effective people
 
Connectivity of graphs
Connectivity of graphsConnectivity of graphs
Connectivity of graphs
 
Binary search
Binary searchBinary search
Binary search
 
circular linklist
circular linklistcircular linklist
circular linklist
 
Link list 2
Link list 2Link list 2
Link list 2
 
Link list 1
Link list 1Link list 1
Link list 1
 
Heapsort 1
Heapsort 1Heapsort 1
Heapsort 1
 
Arrays
ArraysArrays
Arrays
 
Enterpise system
Enterpise systemEnterpise system
Enterpise system
 
Database administration
Database administrationDatabase administration
Database administration
 
Encoders
EncodersEncoders
Encoders
 
Universal logic gate
Universal logic gateUniversal logic gate
Universal logic gate
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Memory management
Memory managementMemory management
Memory management
 
Parallel adders
Parallel addersParallel adders
Parallel adders
 

Recently uploaded

IoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdfIoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdf
roshanranjit222
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
khabri85
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Opportunity scholarships and the schools that receive them
Opportunity scholarships and the schools that receive themOpportunity scholarships and the schools that receive them
Opportunity scholarships and the schools that receive them
EducationNC
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
MattVassar1
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
Infosec
 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
Frederic Fovet
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
Celine George
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
Nguyen Thanh Tu Collection
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Catherine Dela Cruz
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
heathfieldcps1
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 

Recently uploaded (20)

IoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdfIoT (Internet of Things) introduction Notes.pdf
IoT (Internet of Things) introduction Notes.pdf
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Opportunity scholarships and the schools that receive them
Opportunity scholarships and the schools that receive themOpportunity scholarships and the schools that receive them
Opportunity scholarships and the schools that receive them
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 

Shortest path algorithm

  • 1. Shortest Path Algorithm  DIJIKSTRA ALGORITHM  BELLMEN ALGORITHM  FLOYED WARSHALL ALGORITHM
  • 2. Shortest Path Algorithm  An algorithm that is designed essentially to find a path of minimum length between two specified vertices of a connected weighted graph.
  • 3. Single source Shortest path algorithm o It is defined as Cost of shortest path from a source vertex u to a destination v. s a b c
  • 4. Dijkstra’s Algorithm Dijkstra’s algorithm is a greedy algorithm for solving single source shortest path problem that provide us with the shortest path from one particular source node to all other nodes in the given graph .
  • 5. Rules of Dijkstra’s algorithm  It can be applied on both directed and undirected graph.  It is applied on weighted graph.  For the algorithm to be applicable the graph must be connected. a 3 b 4 5 1 c d 4
  • 6. Cont…  Dijkstra’s algorithm does not work for graphs with negative weight edges. For graphs with negative weight edges, Bellman_ford algorithm can be used.  In Dijkstra’s algorithm always assign source vertex to zero distance.  Assign every other node a tentative distance.
  • 7. Dijkstra’s AlgorithmDijkstra’s(G,W,S) INITIALIZE-SINGLE-SOURCE(G,s) 1. for each vertex v ∈ 𝐺. 𝑉 2. v.d = ∞ 3. v.𝜋 = 𝑁𝐼𝐿 4. s.d = 0 5. S = ∅ 6. Q = G.V 7. while (Q≠ ∅) 8. u = dequeue_min(Q) 9. S = S ∪ 𝑢 10. for each vertex v∈ 𝐴𝑑𝑗 𝑢 11. if( v.d > u.d+ w(u,v) ) 12. v.d = u.d + w (u,v) // update distance of v 13. v. 𝜋 = u 14. return v.d
  • 8. BellMan-Algorithm  Bellman–Ford algorithm. The Bellman–Ford algorithm is an algorithm that computes shortest paths from a single source vertex to all of the other vertices in a weighted digraph. ... Negative edge weights are found in various applications of graphs, hence the usefulness of this algorithm.
  • 9. Cont..  It is similar to Dijkstra's algorithm but it can work with graphs in which edges can have negative weights.  Negative weight edges can create negative weight cycles i.e. a cycle which will reduce the total path distance by coming back to the same point.
  • 10. Cont..  Shortest path algorithms like Dijkstra's Algorithm that aren't able to detect such a cycle can give an incorrect result because they can go through a negative weight cycle and reduce the path length. A B D E 2 1 3 2 -4 C
  • 11. Uses of Algorithm  This algorithm can be used on both weighted and unweighted graphs.  Like Dijkstra's shortest path algorithm, the Bellman-Ford algorithm is guaranteed to find the shortest path in a graph.  Though it is slower than Dijkstra's algorithm, Bellman-Ford is capable of handling graphs that contain negative edge weights, so it is more versatile.
  • 12. ALGORITHM 1. for v in V: 2. v.distance = infinity 3. v.p = None 4. source.distance = 0 5. for i from 1 to |V| - 1: 6. for (u, v) in E: 7. relax(u, v)
  • 13. Explanation  The first for loop sets the distance to each vertex in the graph to infinity. This is later changed for the source vertex to equal zero. Also in that first for loop, the p value for each vertex is set to nothing. This value is a pointer to a predecessor vertex so that we can create a path later.  The next for loop simply goes through each edge (u, v) in E and relaxes it. This process is done |V| - 1 times.
  • 14. Relaxation Equation  Relaxation is the most important step in Bellman- Ford. It is what increases the accuracy of the distance to any given vertex. Relaxation works by continuously shortening the calculated distance between vertices comparing that distance with other known distances.
  • 15. Example  Take the baseball example from earlier. Let's say I think the distance to the baseball stadium is 20 miles. However, I know that the distance to the corner right before the stadium is 10 miles, and I know that from the corner to the stadium, the distance is 1 mile. Clearly, the distance from me to the stadium is at most 11 miles. So, I can update my belief to reflect that. That is one cycle of relaxation, and it's done over and over until the shortest paths are found
  • 16. Relax Equation 1. relax(u, v): 2. if v.distance > u.distance + weight(u, v): v.distance = u.distance + weight(u, v) 3. v.p = u
  • 17. Negative Cycle  Detecting Negative Cycles  A very short and simple addition to the Bellman-Ford algorithm can allow it to detect negative cycles, something that is very important because it disallows shortest-path finding altogether. After the Bellman-Ford algorithm shown above has been run, one more short loop is required to check for negative weight cycles.  This psuedo-code is written as a high level descrpition of the algorithm, not an implementation.
  • 18. Cont.. 1. for v in V: 2. v.distance = infinity 3. v.p = None 4. source.distance = 0 5. for i from 1 to |V| - 1: 6. for (u, v) in E: 7. relax(u, v) for (u, v) in E: 8. if v.distance > u.distance + weight(u, v): 9. print "A negative weight cycle exists"
  • 19. Floyed Warshall ALgorithm  Floyd–Warshall algorithm is an algorithm for finding shortest paths in a weighted graph  The Graph may be weighted with positive or negative edge weights .  The Graph may be directed or undirected.
  • 20. Cont..  If a node has not a direct path or link to any other node then the distance between these nodes are infinite.  If only one path between the two nodes or vertices then it said to be the shortest distance.  The distance of a vertex to itself is 0. Vo 10 V3 5 1 3 V1 V2
  • 21. Example 0 1 2 3 0 0 5 inf 10 1 Inf 0 3 Inf 2 Inf Inf 0 1 3 inf inf Inf 0 Vo V3 V1 V2 5 10 1 3
  • 22. Uses Of Shortest Path Algorithm  Weighted graph  Distance function or array  Priority Queue  Relaxation
  • 23. Applications of Shortest Path Algorithm  It is used in Google Map.  It is used in finding Shortest Path.  It is used in geographical Maps.  To find locations of Map which refers to vertices of graph.  Distance between the location refers to edges.  It is used in IP routing to find Open shortest Path First.  It is used in the telephone network.
  翻译: