200 likes | 419 Vues
Shortest Path Algorithm. By Weston Vu CS 146. What is Shortest Paths?. Shortest Paths is a part of the graph algorithm. It is used to calculate the shortest way from the starting point to the destination by adding the weight of the edges together. Shortest Path.
E N D
Shortest Path Algorithm By Weston Vu CS 146
What is Shortest Paths? Shortest Paths is a part of the graph algorithm. It is used to calculate the shortest way from the starting point to the destination by adding the weight of the edges together.
Shortest Path • There are 2 types of shortest path: • Weight shortest path • Unweight shortest path: assign all edges a weight of 1 V1 V2 V4 V5 V3 V7 V6
UnWeight Shortest Path V1 V2 dw = dv + 1 if dw = ¥ V4 V5 V3 V7 V6
UnWeight Shortest Path V1 V2 V4 V5 V3 V7 V6
UnWeight Shortest Path V1 V2 V4 V5 V3 V7 V6
UnWeight Shortest Path V1 V2 V4 V5 V3 V7 V6
Dijkstra’s AlgorithmWeight Shortest Path 2 V1 V2 dw = dv + cv,w if new value for dw would be an improve 10 4 1 3 2 2 V4 V5 V3 8 4 6 5 1 V7 V6
Dijkstra’s AlgorithmWeight Shortest Path 2 V1 V2 10 4 1 3 2 2 V4 V5 V3 8 4 6 5 1 V7 V6
Dijkstra’s AlgorithmWeight Shortest Path 2 V1 V2 10 4 1 3 2 2 V4 V5 V3 8 4 6 5 1 V7 V6
Graphs with Negative Edge Cost • If the graph has negative edge costs, then it makes the problem harder • If negative-cost cycle are present, then the algorithm will loop indefinitely V1 V2 2 -10 4 1 3 2 2 V4 V5 V3 8 4 6 5 1 V7 V6
Acyclic Graph • Changing the order in which vertices are declared known • Set the vertices in topological order C-3 A-3 F-3 Finish Start D-2 G-2 B-2 E-1