CSC 213 Lecture 23: Shortest Path Algorithms. Weighted Graphs Each edge in weighted graph has numerical weight Weights can be distances, building costs,

Slides:



Advertisements
Similar presentations
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Advertisements

Spring 2007Shortest Paths1 Minimum Spanning Trees JFK BOS MIA ORD LAX DFW SFO BWI PVD
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
1 prepared from lecture material © 2004 Goodrich & Tamassia COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material.
Shortest Paths1 C B A E D F
1 Graphs ORD DFW SFO LAX Many slides taken from Goodrich, Tamassia 2004.
© 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.
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
CSC 213 Lecture 24: Minimum Spanning Trees. Announcements Final exam is: Thurs. 5/11 from 8:30-10:30AM in Old Main 205.
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.
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,
© 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,
Shortest Paths C B A E D F
Graphs Part 2. Shortest Paths C B A E D F
Lecture17: Graph I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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.
Graphs. Data Structure for Graphs. Graph Traversals. Directed Graphs. Shortest Paths. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
Shortest Paths 1 Chapter 7 Shortest Paths C B A E D F
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.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
1 Dijkstra’s Algorithm Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
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.
Paths in a Graph : A Brief Tutorial Krishna.V.Palem Kenneth and Audrey Kennedy Professor of Computing Department of Computer Science, Rice University 1.
CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
1 Weighted Graphs CSC401 – Analysis of Algorithms Lecture Notes 16 Weighted Graphs Objectives: Introduce weighted graphs Present shortest path problems,
Data Structures and Algorithms1 Data Structures and algorithms (IS ZC361) Weighted Graphs – Shortest path algorithms – MST S.P.Vimal BITS-Pilani
Contest Algorithms January 2016 Describe shortest path trees, SSSP, APSP, and three algorithms: Dijkstra, Bellman-Ford, Floyd-Warshall 9. Shortest Paths.
Graphs Quebec Toronto Montreal Ottawa 449 km 255 km 200 km 545 km Winnipeg 2075 km 2048 km New York 596 km 790 km 709 km.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
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
Graphs – Breadth First Search
Graphs 10/24/2017 6:47 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Shortest Paths C B A E D F Shortest Paths
Graphs Part 2.
COMP9024: Data Structures and Algorithms
Minimum Spanning Trees
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
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
Shortest Path.
Chapter 13 Graph Algorithms
Graphs Part 2.
Graph Algorithms shortest paths, minimum spanning trees, etc.
Graphs ORD SFO LAX DFW Graphs Graphs
Minimum Spanning Trees
Single-source shortest paths
Copyright © Aiman Hanna All rights reserved
Shortest Paths.
Weighted Graphs C B A E D F Sequences
CSE 417: Algorithms and Computational Complexity
Data Structures and Algorithm Analysis Lecture 8
Presentation transcript:

CSC 213 Lecture 23: Shortest Path Algorithms

Weighted Graphs Each edge in weighted graph has numerical weight Weights can be distances, building costs, travel times, etc. Example: Weights are miles between the two airports ORD PVD MIA DFW SFO LAX LGA HNL

Shortest Paths Find path of minimum weight between two vertices u and v Path’s weight is sum of the edge weights Example: Shortest path between Providence and Honolulu ORD PVD MIA DFW SFO LAX LGA HNL

Shortest Path Assumptions Assumptions: Subpath of shortest path is also shortest path (no negative weights) Shortest path from start vertex to all other vertices is a tree Example: Single-source/multi-sink shortest path solution starting at Providence ORD PVD MIA DFW SFO LAX LGA HNL

Dijkstra’s Algorithm Distance from vertex s to vertex v is length of shortest path between s and v Dijkstra’s algorithm computes the distances of all the vertices from a given start vertex s Note: Relies upon several assumptions Graph is connected Edge weights are nonnegative (0 or larger)

Dijkstra’s Algorithm (§ ) Beginning from s, grow cloud of vertices Store distance from s through cloud to each vertex v At each step Add to cloud the vertex with smallest distance that is not in cloud currently Update distances of vertices adjacent vertex added to cloud

Edge Relaxation Consider edge e where vertex u added to cloud most recently z is not in the cloud Relaxation of e updates distance to z d(z)  75 d(u)  z s u d(z)  60 d(u)  z s u e e

Example CB A E D F  C B A E D F C B A E D F C B A E D F

Example (cont.) CB A E D F CB A E D F

Shortest Paths Tree Using template method pattern, extend Dijkstra’s algorithm to return tree of shortest paths from start vertex Also store vertex’s parent edge in tree Edge relaxation step also updates the vertex’s parent label

Why Dijkstra’s Algorithm Works Dijkstra was smart. Smarter even than me Dijkstra’s algorithm is greedy. Vertices added in increasing distances order Suppose it didn’t find shortest distance to a vertex F, but did find shortest distance to D But edge from D to F was relaxed when D was added to cloud But so long as d( F )>d( D ), F ’s distance must be correct. CB A E D F

Why No Negative-Weight Edges? CB A E D F Suppose edge with negative weight exists When we add incident vertex to cloud, may discover smaller distance to opposite vertex But only consider vertices not in vertices C ’s true distance is 1, but added to cloud with distance of 5!

Not All Is Lost Algorithms computing shortest paths that include negative weights do exist Bellman-Ford algorithm takes time O ( nm ) DAG-based algorithms takes time O ( n + m ) Merlin algorithm takes time O ( n + m )