Dijkstra's Shortest Path Algorithm

Slides:



Advertisements
Similar presentations
Traffic assignment.
Advertisements

CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Internet Engineering Czesław Smutnicki Discrete Mathematics – Graphs and Algorithms.
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
CS171 Introduction to Computer Science II Graphs Strike Back.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
D IJKSTRA ' S ALGORITHM By Laksman Veeravagu and Luis Barrera Edited by: Manuela Caicedo, Francisco Morales, Rafael Feliciano, and Carlos Jimenez.
CSC 331: Algorithm Analysis Paths in Graphs. The DFS algorithm we gave is recursive. DFS generates a search tree showing paths from one vertex to all.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
Directed Graph Algorithms CSE 373 Data Structures Lecture 14.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t
1 Dijkstra's Shortest Path Algorithm Find shortest path from s to t. s 3 t
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
Shortest Path Problem For weighted graphs it is often useful to find the shortest path between two vertices Here, the “shortest path” is the path that.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Fundamentals, Terminology, Traversal, Algorithms Graph Algorithms Telerik Algo Academy
ALG0183 Algorithms & Data Structures Lecture 21 d Dijkstra´s algorithm 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks Chapter 14 Weiss.
Graphs, BFS, DFS and More…
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Shortest Path in Weighted Graph : Dijkstra’s Algorithm.
D IJKSTRA ' S ALGORITHM. S INGLE -S OURCE S HORTEST P ATH P ROBLEM Single-Source Shortest Path Problem - The problem of finding shortest paths from a.
Shortest Path Graph Theory Basics Anil Kishore.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Access to Health Services and Locating Health Services March 12, 2013.
CS 367 Introduction to Data Structures Lecture 13.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Graphs – Part III CS 367 – Introduction to Data Structures.
By Laksman Veeravagu and Luis Barrera
Fundamentals, Terminology, Traversal, Algorithms
Shortest Paths and Minimum Spanning Trees
Programming Abstractions
Some applications of graph theory
CS 106B Homework 7: Trailblazer
Single-Source Shortest Paths
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Comp 245 Data Structures Graphs.
Network Routing.
Party-by-Night Problem
Graph Algorithm.
Shortest Path.
CSE 373: Data Structures and Algorithms
Chapter 11 Graphs.
Graphs Part 2 Adjacency Matrix
Shortest Path Algorithms
Shortest Paths and Minimum Spanning Trees
Case study: Strava + Waze
The Rock Boxers: Tabitha Greenwood Cameron Meade Noah Cahan
Slide Courtesy: Uwash, UT
CSE 373: Data Structures and Algorithms
Algorithms: Design and Analysis
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
CE 221 Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
CE 221 Data Structures and Algorithms
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
Dijkstra Algorithm examples
Graphs: Shortest path and mst
Graph Algorithm.
Presentation transcript:

Dijkstra's Shortest Path Algorithm Find shortest path from s to t. 2 24 3 9 s 18 14 2 6 6 4 30 19 11 15 5 5 6 20 16 t 7 44

Dijkstra's Shortest Path Algorithm PQ = { s, 2, 3, 4, 5, 6, 7, t }   2 24 3 9 s 18 14  2 6 6  4 30  19 11 15 5 5 6 20 16 t 7 44  distance label 

Dijkstra's Shortest Path Algorithm PQ = { s, 2, 3, 4, 5, 6, 7, t } Here   2 24 3 9 s 18 14  2 6 6  30  4 19 11 15 5 5 6 20 16 t 7 44  distance label 

Dijkstra's Shortest Path Algorithm PQ = { 2, 3, 4, 5, 6, 7, t } decrease key   X 9 2 24 3 9 s 18 14  X 14 2 6 6  4 30  19 11 15 5 5 6 20 16 t 7 44  distance label  15 X

Dijkstra's Shortest Path Algorithm PQ = { 2, 3, 4, 5, 6, 7, t } Here   X 9 2 24 3 9 s 18 14  X 14 2 6 6  4 30  19 11 15 5 5 6 20 16 t 7 44  distance label  15 X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, 6, 7, t }   X 9 2 24 3 9 s 18 14  X 14 2 6 6  30  4 19 11 15 5 5 6 20 16 t 7 44   15 X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, 6, 7, t } decrease key  X 33  X 9 2 24 3 9 s 18 14  X 14 2 6 6   4 30 19 11 15 5 5 6 20 16 t 7 44   15 X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, 6, 7, t }  X 33  X 9 2 24 3 9 Here s 18 14  X 14 2 6 6   4 30 19 11 15 5 5 6 20 16 t 7 44   15 X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, 7, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 30  X 4 19 11 15 5 5 6 20 16 t 7 44   15 X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, 7, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 30  X 4 19 11 15 5 5 6 20 16 t 7 44   15 Here X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 X 35  X 4 30 19 11 15 5 5 6 20 16 t 7 44 59   15 X X

Dijkstra's Shortest Path Algorithm PQ = { 3, 4, 5, t } Here 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 X 35 4 30  X 19 11 15 5 5 6 20 16 t 7 44 59   15 X X

Dijkstra's Shortest Path Algorithm PQ = { 4, 5, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 X 35 X 34 4 30  X 19 11 15 5 5 6 20 16 t 7 44 51 59   15 X X X

Dijkstra's Shortest Path Algorithm PQ = { 4, 5, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6  44 X 35 X 34 30  X 4 19 11 15 5 5 6 20 Here 16 t 7 44 51 59   15 X X X

Dijkstra's Shortest Path Algorithm PQ = { 4, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X 30  X 4 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59   15 X X X

Dijkstra's Shortest Path Algorithm PQ = { 4, t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X 30  X 4 19 11 15 5 Here 5 6 20 16 t 7 44 50 51 X 59   15 X X X

Dijkstra's Shortest Path Algorithm PQ = { t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X 30  X 4 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59   15 X X X

Dijkstra's Shortest Path Algorithm PQ = { t } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X 30  X 4 19 11 15 5 5 6 20 16 t 7 44 Here 50 51 X 59   15 X X X

Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X  X 4 30 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59   15 X X X

Dijkstra's Shortest Path Algorithm S = { s, 2, 3, 4, 5, 6, 7, t } PQ = { } 32  X 33 X  X 9 2 24 3 9 s 18 14  X 14 2 6 6 45  44 X 35 X 34 X  X 4 30 19 11 15 5 5 6 20 16 t 7 44 50 51 X 59   15 X X X

The Algoritm 1. Assign to every node a distance value. Set it to zero for our initial node and to infinity (-9999) for all other nodes. 2. Mark all nodes as unvisited. Set initial node as current. 3. For current node, consider all its unvisited neighbors and calculate their distance (from the initial node). For example, if current node (A) has distance of 6, and an edge connecting it with another node (B) is 2, the distance to B through A will be 6+2=8. If this distance is less than the previously recorded distance (infinity in the beginning, zero for the initial node), overwrite the distance. 4. When we are done considering all neighbors of the current node, mark it as visited. A visited node will not be checked ever again; its distance recorded now is final and minimal. 5. If all nodes have been visited, finish. Otherwise, set the unvisited node with the smallest distance (from the initial node) as the next "current node" and continue from step 3.

Pseudo Code of the Dijkstra’s Alg Algorithm Dijkstra(Graph, source): for each vertex v in Graph: // Initializations dist[v] := infinity // Unknown distance function from source to v previous[v] := undefined // Previous node in optimal path from source dist[source] := 0 // Distance from source to source Q := the set of all nodes in Graph // All nodes in the graph are unoptimized - thus are in Q while Q is not empty: // The main loop u:= dequeue (Q) // u := vertex in Q with smallest dist[] if dist[u] = infinity: break // all remaining vertices are inaccessible from source dequeue(u,Q) // remove u from Q for each neighbor v of u: // where v has not yet been removed from Q. alt := dist[u] + dist_between(u, v) // Dist. from start point to neighbor if alt < dist[v]: // Relax (u,v) dist[v] := alt previous[v] := u return dist