1 Digraphs Reachability Connectivity Transitive Closure Floyd-Warshall Algorithm JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO.
Advertisements

Directed Graphs Directed Graphs Shortest Path 4/10/ :45 AM BOS
CSE 373 Graphs 1: Concepts, Depth/Breadth-First Search
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
CSC 213 – Large Scale Programming. Today’s Goals  Examine new properties of DirectedGraph s  What reaching & reachable mean for a Graph  How humans.
Graphs – Depth First Search ORD DFW SFO LAX
16a-Graphs-More (More) Graphs Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Lecture 21: Matrix Operations and All-pair Shortest Paths Shang-Hua Teng.
Directed Graphs. Given vertices u and v of a digraph G , we say that u reaches v (and v is reachable from u ) if G  has a directed path from u to.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
CS 206 Introduction to Computer Science II 10 / 31 / 2008 Happy Halloween!!! Instructor: Michael Eckmann.
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
1 The Graph Abstract Data Type CS 5050 Chapter 6.
© 2004 Goodrich, Tamassia Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
1 Directed Graphs CSC401 – Analysis of Algorithms Lecture Notes 15 Directed Graphs Objectives: Introduce directed graphs and weighted graphs Present algorithms.
TTIT33 Alorithms and Optimization – DALG Lecture 4 Graphs HT TTIT33 Algorithms and optimization Algorithms Lecture 4 Graphs.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§6.4) Reachability (§6.4.1) Directed DFS Strong connectivity Transitive.
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CSC311: Data Structures 1 Chapter 13: Graphs I Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 11 – Graphs Graphs HT TDDB56 – DALGOPT-D Algorithms and optimization Lecture 11 Graphs.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
Graphs1 Graphs Chapter 6 ORD DFW SFO LAX
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
Chapter 2 Graph Algorithms.
Lecture17: Graph I Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Graphs – ADTs and Implementations ORD DFW SFO LAX
Graphs1 Definitions Examples The Graph ADT LAX PVD LAX DFW FTL STL HNL.
October 22, DFS, BFS, Biconnectivity, Digraphs 1 CS 221 West Virginia University.
Chapter 6 Graphs ORD DFW SFO LAX
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.
© 2004 Goodrich, Tamasia Recall: Digraphs A digraph is a graph whose edges are all directed Short for “directed graph” Applications one-way streets flights.
Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl V = { a, b, c, d, e, f, g, h, i,
Chapter 8 Dynamic Programming Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
CSE 373: Data Structures and Algorithms
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
CSC401: Analysis of Algorithms 6-1 CSC401 – Analysis of Algorithms Chapter 6 Graphs Objectives: Introduce graphs and data structures Discuss the graph.
Graphs and Shortest Paths Using ADTs and generic programming.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
1 COMP9024: Data Structures and Algorithms Week Eleven: Graphs (I) Hui Wu Session 1, 2016
Directed Graphs1 JFK BOS MIA ORD LAX DFW SFO. Directed Graphs2 Outline and Reading (§12.4) Reachability (§12.4.1) Directed DFS Strong connectivity Transitive.
Directed Graphs Directed Graphs Shortest Path 12/7/2017 7:10 AM BOS
Directed Graphs 12/7/2017 7:15 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
CS 201: Design and Analysis of Algorithms
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Chapter 14 Graph Algorithms
Directed Graphs 9/20/2018 1:45 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Directed Graphs 5/1/15 12:25:22 PM
Directed Graphs Directed Graphs 1 Shortest Path Shortest Path
Graphs.
Directed Graphs (digraphs)
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Richard Anderson Autumn 2016 Lecture 5
Directed Graphs Directed Graphs Directed Graphs 2/23/ :12 AM BOS
Graphs Part 1 ORD SFO LAX DFW
Lecture 21: Matrix Operations and All-pair Shortest Paths
Presentation transcript:

1 Digraphs Reachability Connectivity Transitive Closure Floyd-Warshall Algorithm JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7

2 Digraphs wake up eat work study computer sci. more c.s. play battletris sleep dream of cs16 write c.s. program A typical student day make cookies for c.s. prof.

3 What’s a Digraph? a) A small burrowing animal with long sharp teeth and a unquenchable lust for the blood of computer science majors b) A distressed graph c) A directed graph Each edge goes in one direction Edge (a,b) goes from a to b, but not b to a a You’re saying, “Yo, how about an example of how we might be enlightened by the use of digraphs!!” - Well, if you insist...

4 Applications Maps: digraphs handle one-way streets (especially helpful in Providence)

5 Another Application Scheduling: edge (a,b) means task a must be completed before b can be started cs16 cs15 cs31 cs126 cs32 cs127 cs167 cs141 cs22 old computer scientists never die, they just fall into black holes

6 DAG’s dag: (noun) dÂ-g 1. Di-Acyl-Glycerol - My favorite snack! 2.“man’s best friend” 3. directed acyclic graph Say What?! ab c d e ab c d e DAG not a DAG directed graph with no directed cycles

7 Depth-First Search Same algorithm as for undirected graphs On a connected digraph, may yield unconnected DFS trees (i.e., a DFS forest) ab c d e f a b c d e f

8 Reachability DFS tree rooted at v: vertices reachable from v via directed paths ab c d e f c a b d e b f d c a

9 Strongly Connected Digraphs Each vertex can reach all other vertices a b d c e f g

10 Strongly Connected Components a b d c e f g { a, c, g } { f, d, e, b }

11 Transitive Closure Digraph G* is obtained from G using the rule: If there is a directed path in G from a to b, then add the edge (a,b) to G* G G *

12 Computing the Transitive Closure We can perform DFS starting at each vertex Time: O(n(n+m)) Alternatively... Floyd-Warshall Algorithm: if there's a way to get from A to B and from B to C then there's a way to get from A to C. “Pink” Floyd

13 Example BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7 JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7

14 Floyd-Warshall Algorithm Assumes that methods areAdjacent and insertDirectedEdge take O(1) time (e.g., adjacency matrix structure) Algorithm FloydWarshall(G) let v1... vn be an arbitrary ordering of the vertices G 0 = G for k = 1 to n do // consider all possible routing vertices vk G k = G k-1 // these are the only ones you need to store for each (i, j = 1,..., n) (i != j) (i, j != k) do // for each pair of vertices v i and v j if G k-1.areAdjacent(v i,v k ) and G k-1.areAdjacent(v k,v j ) then G k.insertDirectedEdge(v i,v j,null) return G n Digraph G k is the subdigraph of the transitive closure of G induced by paths with intermediate vertices in the set { v 1,..., v k } Running time: O(n 3 )

15 Example digraph G JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6

16 Example digraph G* JFK BOS MIA ORD LAX DFW SFO v 2 v 1 v 3 v 4 v 5 v 6 v 7

17 Topological Sorting For each edge (u,v), vertex u is visited before vertex v wake up eat work cs16 meditation more cs16 play cxhextris make cookies for cs16 HTA sleep dream of cs16 cs16 program A typical student day

18 Topological Sorting Topological sorting may not be unique A B C D A B C D or A C B D - You make the call!

19 Topological Sorting Labels are increasing along a directed path A digraph has a topological sorting if and only if it is acyclic (i.e., a dag) A B C D E

20 Algorithm for Topological Sorting method TopologicalSort if there are more vertices letv be a source; // a vertex w/o incoming edges label and removev; TopologicalSort ; A B C D E

21 Algorithm (continued) Simulate deletion of sources using indegree counters TopSort(Vertex v); label v; foreach edge(v,w) indeg(w) = indeg(w)  1; if indeg(w) = 0 TopSort(w); Compute indeg(v) for all vertices Foreach vertex v do if v not labeled and indeg(v) = 0 then TopSort(v)

22 Example A C E H G D F I B ?0 ?0 ?1 ?3 ?1 ?2 ?2 ?1 ?3