1 Dijkstra’s Algorithm Dr. Ying Lu RAIK 283 Data Structures & Algorithms.

Slides:



Advertisements
Similar presentations
Spring 2007Shortest Paths1 Minimum Spanning Trees JFK BOS MIA ORD LAX DFW SFO BWI PVD
Advertisements

Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
Lecture 21: Matrix Operations and All-pair Shortest Paths Shang-Hua Teng.
Shortest Paths1 C B A E D F
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
CSC 213 Lecture 23: Shortest Path Algorithms. Weighted Graphs Each edge in weighted graph has numerical weight Weights can be distances, building costs,
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
© 2004 Goodrich, Tamassia Shortest Paths1 Shortest Paths (§ 13.6) Given a weighted graph and two vertices u and v, we want to find a path of minimum total.
1 Graphs: shortest paths Fundamental Data Structures and Algorithms Ananda Guna April 3, 2003.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
CSC311: Data Structures 1 Chapter 13: Graphs II Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
Shortest Paths1 C B A E D F
© 2004 Goodrich, Tamassia Shortest Paths1 C B A E D F
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Dijkstra's algorithm.
Lecture20: Graph IV Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Graphs – Shortest Path (Weighted Graph) ORD DFW SFO LAX
Weighted Graphs In a weighted graph, each edge has an associated numerical value, called the weight of the edge Edge weights may represent, distances,
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
© 2010 Goodrich, Tamassia Shortest Paths1 C B A E D F
1 Shortest Path Problem Topic 11 ITS033 – Programming & Algorithms C B A E D F Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program,
Greedy Algorithms Fundamental Data Structures and Algorithms Peter Lee March 19, 2004.
Shortest Paths C B A E D F
Graphs Part 2. Shortest Paths C B A E D F
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
Greedy Algorithms Fundamental Data Structures and Algorithms Ananda Guna February 6, 2003 Based on lectures given by Peter Lee, Avrim Blum, Danny.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
Lecture 16. Shortest Path Algorithms
Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine.
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.
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA
CSE 373: Data Structures and Algorithms
Greedy Algorithms Fundamental Data Structures and Algorithms Peter Lee February 6, 2003.
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
© 2010 Goodrich, Tamassia Shortest Paths1 C B A E D F
1 COMP9024: Data Structures and Algorithms Week Twelve: Graphs (II) Hui Wu Session 1, 2014
Minimum-cost spanning tree
Shortest Paths C B A E D F Shortest Paths
Minimum-Cost Spanning Tree and Kruskal’s Algorithm
COMP9024: Data Structures and Algorithms
Shortest Paths C B A E D F Shortest Paths
Shortest Path 6/18/2018 4:22 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Shortest Paths C B A E D F Shortest Paths 1
Shortest Paths C B A E D F Shortest Paths
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Shortest Paths C B A E D F Shortest Paths
Shortest Paths C B A E D F
Shortest Paths C B A E D F Shortest Paths
Shortest Paths C B A E D F Shortest Paths
Chapter 13 Graph Algorithms
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Graph Algorithms shortest paths, minimum spanning trees, etc.
Minimum Spanning Trees
Single-source shortest paths
CSE 373: Data Structures and Algorithms
Shortest Paths.
Minimum Spanning Trees
Weighted Graphs C B A E D F Sequences
CSE 417: Algorithms and Computational Complexity
Lecture 21: Matrix Operations and All-pair Shortest Paths
Presentation transcript:

1 Dijkstra’s Algorithm Dr. Ying Lu RAIK 283 Data Structures & Algorithms

2  Giving credit where credit is due: »Most of slides for this lecture are based on slides created by Dr. John Vergara at Ateneo De Manila UniversityDr. John VergaraAteneo De Manila University »I have modified them and added new slides

3 Single-Source Shortest-Paths Problem  Problem: given a connected graph G with non-negative weights on the edges and a source vertex s in G, determine the shortest paths from s to all other vertices in G.  Useful in many applications (e.g., road map applications)

4 Single-Source Shortest-Paths  For instance, the following edges form the shortest paths from node A HBC GED F A

5 Single-Source Shortest-Paths HBC GED F A Hint: does this problem looks similar? Can we modify Prim’s algorithm to solve this problem?

6 Dijkstra’s Algorithm  Solves the single-source shortest paths problem  Involves keeping a table of current shortest path lengths from source vertex (initialize to infinity for all vertices except s, which has length 0)  Repeatedly select the vertex u with shortest path length, and update other lengths by considering the path that passes through that vertex  Stop when all vertices have been selected  Could use a priority queue to facilitate selection of shortest lengths »Here, priority is defined differently from that of the Prim’s algorithm »Like Prim’s algorithm, it needs to refine data structure so that the update of key-values in priority queue is allowed »Like Prim’s algorithm, time complexity is O( (n + m) log n )

7 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO

8 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO

9 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO JFK

10 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO PVD

11 Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO BOS

Dijkstra’s algorithm ORD BOS PVD JFK BWI MIA DFW LAX SFO ORD

13 Dijkstra’s algorithm (cont) ORD BOS PVD JFK BWI MIA DFW LAX SFO MIA

Dijkstra’s algorithm (cont) ORD BOS PVD JFK MIA DFW LAX SFO BWI DFW

15 Dijkstra’s algorithm (cont) LAX SFO ORD BOS PVD JFK BWI MIA DFW SFO

16 Dijkstra’s algorithm (cont) LAX SFO ORD BOS PVD JFK BWI MIA DFW LAX

17 In-Class Exercises

18 In-Class Exercises  Design a linear-time, (i.e.,  ( n + m)) algorithm for solving the single-source shortest-paths problem for dags (directed acyclic graphs) represented by their adjacency lists.  Hint: topologically sort the dag’s vertices first.

19 In-Class Exercise  Suppose a person is making a travel plan driving from city 1 to city n, n > 1, following a route that will go through cities 2 through n –1 in between. The person knows the mileages between adjacent cities, and knows how many miles a full tank of gasoline can travel. Based on this information, the problem is to minimize the number of stops for filling up the gas tank, assuming there is exactly one gas station in each of the cities. Design a greedy algorithm to solve this problem and analyze its time complexity.

fill up the gas tank in City 1 for c = 2 to n –1 do // decide whether to stop in City c for gas while approaching (2.1) if there is still enough gas to go to City (c+1) then don’t stop in City c (2.2) else fill up the gas tank in City c It can be proved that this greedy algorithm minimizes the number of gas stops. The time complexity is O(n) because the loop in Step (2) runs O(n) iterations in which each iteration uses O(1) time (in Steps (2.1) and (2.2)). Proofs Techniques for Greedy Algorithms