We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byKari Bunch
Modified about 1 year ago
Chapter 14 Weighted Graphs © John Urrutia 2014, All Rights Reserved1
Weighted Graphs Similar to directional Graphs Added attribute called “weight” to the edges Used to designate a preference between edges Helps answer questions like What is the minimum spanning tree for a weighted graph? What is the shortest (or cheapest) distance from one vertex to another? © John Urrutia 2014, All Rights Reserved2
Minimum Spanning Tree with weighted graphs Weight changes everything Each vertex edge must be compared based on their weight The lightest weight wins Given 6 cities where the weight between each city is the cost ($millions)of building an internet cable What is/are the least expensive route © John Urrutia 2014, All Rights Reserved3
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved4 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 Repeat until no more Vertices to add Pick a vertex Add vertex to MSP Identify the lightest Edge from this vertex New Vertex in MSP Identify the next lightest Edge from this vertex No
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved5 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 ErizoColinaFlorBordoAjoDanza 56764
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved6 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 FlorColinaErizoBordoAjoDanza 65764
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved7 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 ColinaErizoFlorBordoAjoDanza 56764
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved8 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 BordoAjoDanzaErizoColinaFlor 64756
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved9 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 AjoDanzaBordoErizoColinaFlor 46756
Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved10 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 DanzaAjoBordoErizoColinaFlor 46756
Minimum Spanning Tree The Algorithm Select a current vertex to start the tree Find all edges from the current vertex to vertices not already in the tree. Place them into a priority queue. Select the lowest priority edge from the queue add it and the destination vertex to the tree. Repeat until no more vertices to add. © John Urrutia 2014, All Rights Reserved11
Priority Queue Vertex List Minimum Spanning Trees © John Urrutia 2014, All Rights Reserved12 Colina Danza Flor Ajo Bordo Erizo 10 6 7 124 7 7 8 5 6 A D4 B6 E7 C5 F6 AjoDanzaBordoErizoColinaFlor 46756 B6 D4 E12 C8 B7 B6 C10 E7 F7 C5
Shortest Path Problem With the Minimum Spanning Tree we answer the question: Can we get there from here With the Shortest Path we answer the questions: What is the shortest way to get there from here © John Urrutia 2014, All Rights Reserved13
Dijkstra’s Algorithm Developed in 1959 by Edsger Dijkstra Based on an adjacency matrix for a directed graph Finds the shortest path between one vertex to another Finds the shortest paths between a vertex and all other vertices Similar to Warshall’s algorithm but updates a path when it is shorter than a previous one © John Urrutia 2014, All Rights Reserved14
Dijkstra’s Algorithm For each unvisited vertex in the weighted graph Select the vertex with the smallest total distance Calculate the distance through this vertex to each unvisited neighboring vertex Update the neighboring vertex distance if smaller. Mark the source vertex as visited. © John Urrutia 2014, All Rights Reserved15
Priority Queue Vertex List Shortest Path Array © John Urrutia 2014, All Rights Reserved16 Colina Danza Flor Ajo Bordo Erizo $10 $6 $7 $12$4 $7 $8 $3 $6 A D4 B6 E7 C5 F6 AjoDanzaBordoErizoColinaFlor 46756 B6 D4 E12 C8 B7 B6 C10 E7 F7 C5 ~ ~ ~ ~ ~ 0 4 6 16 12 18 6 + 10 = 16 !< 12 NoChg 12 + 3 = 15 < 16 Update 15 6 + 7 = 13 !< 4 NoChg
All-pairs Shortest Path Weighted Adjacency Matrix © John Urrutia 2014, All Rights Reserved17 From / To AjoBordoColinaDanzaErizoFlor Ajoinf$6inf$4inf Bordoinf $10$7inf Colinainf $3$6 Danzainf $8inf$12inf Erizoinf$7inf Florinf $7inf
All-pairs Shortest Path All-Pairs Table © John Urrutia 2014, All Rights Reserved18 From / To AjoBordoColinaDanzaErizoFlor Ajoinf$6$12$4$16$18 Bordoinf $10$7$13$16 Colinainf$10inf$17$3$6 Danzainf$18$8inf$12$14 Erizoinf$7$17$14inf$23 Florinf$14$24$21$7inf
Floyd’s Algorithm Dijkstra’s algorithm for producing the All-Pairs Shortest Path Table runs in O(N 2 ) Floyds algorithm for the All-Pairs Shortest Path Table is more efficient because it uses a variation on Warshall’s algorithm. © John Urrutia 2014, All Rights Reserved19
Floyd’s Algorithm Process each row and column © John Urrutia 2014, All Rights Reserved20 Adjacency Matrix AjoBordoColinaDansaErizoFlor Ajo6 4 Bordo10 7 Colina36 Dansa8 12 Erizo 7 Flor7 Ajo goes to Bordo – Bordo goes to? 1 1 1 6 + 7 = 13 !< 4 No Chg MSP goes to Nothing SAN goes to LGA,MSP,SFO,STL,TPA – what goes to SAN Nothing? SFO goes to MSP – what goes to SFO TPA goes to LGA – what goes to TPA Nothing goes to Ajo SFO goes to STL – what goes to SFO TPA goes to MSP – what goes to TPA TPA goes to STL – what goes to TPA 16 4 + 8 = 12 < 16 Update 12
Summary In a weighted graph, edges have an associated number called the weight, which might represent distances, costs, times, or other quantities. The minimum spanning tree in a weighted graph minimizes the weights of the edges necessary to connect all the vertices. An algorithm using a priority queue can be used to find the minimum spanning tree of a weighted graph. The minimum spanning tree of a weighted graph models real-world situations such as installing utility cables between cities. © John Urrutia 2014, All Rights Reserved21
Summary The shortest-path problem in a non-weighted graph involves finding the minimum number of edges between two vertices. Solving the shortest-path problem for weighted graphs yields the path with the minimum total edge weight. The shortest-path problem for weighted graphs can be solved with Dijkstra’s algorithm. The algorithms for large, sparse graphs generally run much faster if the adja- cency-list representation of the graph is used rather than the adjacency matrix. © John Urrutia 2014, All Rights Reserved22
Summary The all-pairs shortest-path problem is to find the total weight of the edges between every pair of vertices in a graph. Floyd’s algorithm can be used to solve this problem. Some graph algorithms take exponential time and are therefore not practical for graphs with more than a few vertices. © John Urrutia 2014, All Rights Reserved23
Directional Weighted Graph © John Urrutia 2014, All Rights Reserved24 Colina Danza Flor Ajo Bordo Erizo $10 $6 $7 $12$4 $7 $8 $3 $6
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
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 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
COSC 2007 Data Structures II Chapter 14 Graphs III.
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.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
1 Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges V is a set of vertices – nodes E is a set of edges defined as vertex pairs (u,v) where u.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Chapter 9: Graphs Shortest Paths Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
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.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant: A is a subset of some MST We start with.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Geography and CS Philip Chan. How do I get there? Navigation Which web sites can give you turn-by-turn directions?
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Shortest Paths CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
SPANNING TREES Lecture 21 CS2110 – Spring
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees Definitions Minimum spanning trees 3 greedy algorithms (incl. Kruskal’s & Prim’s)
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
1 Chapter 28 Weighted Graph Applications. 2 Objectives F To represent weighted edges using adjacency matrices and priority queues (§28.2). F To model.
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 28 Weighted Graph.
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
© 2017 SlidePlayer.com Inc. All rights reserved.