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.

Slides:



Advertisements
Similar presentations
Bellman-Ford algorithm
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
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,
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.
CSC 213 Lecture 23: Shortest Path Algorithms. Weighted Graphs Each edge in weighted graph has numerical weight Weights can be distances, building costs,
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
1 Graphs ORD DFW SFO LAX Many slides taken from Goodrich, Tamassia 2004.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
© 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.
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
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
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
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is NOT meant by term “Graph”  Why no bar charts, scatter plots, & pie charts mentioned.
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.
Introduction to Algorithms Jiafen Liu Sept
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,
Contest Algorithms January 2016 Describe shortest path trees, SSSP, APSP, and three algorithms: Dijkstra, Bellman-Ford, Floyd-Warshall 9. Shortest Paths.
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
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 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.
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 Path Problems
Shortest Path Graph represents highway system Edges have weights
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.
CSE 373: Data Structures and Algorithms
Chapter 13 Graph Algorithms
Shortest Path Problems
Single-source shortest paths
CSE 373: Data Structures and Algorithms
Copyright © Aiman Hanna All rights reserved
Algorithms: Design and Analysis
Shortest Paths.
Presentation transcript:

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 weights to model problems  How to solve problems once Graph is set up  Learn about myth & legend of Edsgar Dijkstra  Who was he? Why should we care? How is it related?  What was his largest contribution to graph theory?  How does Dijkstra’s algorithm find smallest path?

Weighted Graphs  Edge’s weight is cost of using edge  Distance, cost, travel time, &c. usable as the weight  Weights below are distance in miles ORD PVD MIA DFW SFO LAX LGA HNL

Cheapest Path Problem  Find path with min. weight between 2 vertices  Sum of edge weights is the path weight  Consider the cheapest path from PVD to HNL  None of edges is cheapest in this example ORD PVD MIA DFW SFO LAX LGA HNL

Cheapest Path Problem  Subpath on shortest path is shortest path also  Otherwise we would use shorter subpath  Tree made by all shortest paths from vertex  Consider all shortest paths from PVD ORD PVD MIA DFW SFO LAX LGA HNL

Dijkstra’s Algorithm  Finds cheapest paths from single vertex  Normally, computes cheapest path to all vertices  Stop once vertex computed for single target vertex  Makes several fundamental assumptions  Connected graph needed when targeting all vertices edge weights must be nonnegative  Only works if edge weights must be nonnegative

Dijkstra’s Algorithm  Grows cloud of vertices as it goes  Cloud starts with source vetex  Add vertex to cloud with each step  Tracks distances to each vertex not in cloud  For each vertex, considers only cheapest path  Only uses 1 edge from cloud to vertex not in cloud  Each step uses vertex with smallest distance  Adds this vertex to cloud, if not done yet  Checks if creates smaller path to any vertices

Edge Relaxation  Consider e from u to z  When u added to cloud  Check adjacent vertices  Assume z not in cloud  Found faster path!  Update via relaxation  New minimum selected: d( z ) = 75 z s u d( u ) = e

Edge Relaxation  Consider e from u to z  When u added to cloud  Check adjacent vertices  Assume z not in cloud  Found faster path!  Update via relaxation  New minimum selected: d( z ) = 75 z s u d( u ) = e d( z ) = 60

Edge Relaxation  Consider e from u to z  When u added to cloud  Check adjacent vertices  Assume z not in cloud  Found faster path!  Update via relaxation  New minimum selected: d( z ) = 75 z s u d( u ) = e d( z ) = 60

Edge Relaxation  Consider e from u to z  When u added to cloud  Check adjacent vertices  Assume z not in cloud  Found faster path!  Update via relaxation  New minimum selected: z s u d( u ) = e d( z ) = 60

Dijkstra Example CB A E D F  

C B A E D F

Dijkstra Example C B A E D F

C B A E D F

CB A E D F

CB A E D F

Why Dijkstra’s Algorithm Works  Ultimately, Dijkstra was smart  Smarter than me, if that is possible

Why Dijkstra’s Algorithm Works  Ultimately, Dijkstra was smart  Smarter than me, if that is possible

Why Dijkstra’s Algorithm Works  Ultimately, Dijkstra was smart  Smarter than me, if that is possible  Example of a greedy algorithm  Takes best choice at each point in time  Vertices added in increasing distance  Brings vertices closer at each step  Stops when vertex cannot move closer

Why No Negative-Weight Edges?  Assume edge has negative weight  Greedily chose vertex before finding edge  Cloud will include only one endpoint  Negative weight changes everything, however  Vertices not added in order  Negative weight cycles?  Repeat cycle to optimize CB A E D F

Why No Negative-Weight Edges?  Assume edge has negative weight  Greedily chose vertex before finding edge  Cloud will include only one endpoint  Negative weight changes everything, however  Vertices not added in order  Negative weight cycles?  Repeat cycle to optimize C added when distance was 5, but cheapest distance is 1! CB A E D F

Not All Is Lost  Slower cheapest paths algorithms can work  Bellman-Ford algorithm takes time O ( nm )  DAG-based algorithms takes time O ( n + m )  Merlin algorithm takes time O ( n + m )

Not All Is Lost  Slower cheapest paths algorithms can work  Bellman-Ford algorithm takes time O ( nm )  DAG-based algorithms takes time O ( n + m )  Merlin algorithm takes time O ( n + m )

For Next Lecture