Directed Graphs BOS. Directed Graphs 1 ORD JFK SFO DFW LAX MIA

Similar documents
Warshall s Algorithm: Transitive Closure

Network (Tree) Topology Inference Based on Prüfer Sequence

Data Structures and Algorithms Written Examination

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

5.1 Bipartite Matching

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

Part 2: Community Detection

Cpt S 223. School of EECS, WSU

Simplified External memory Algorithms for Planar DAGs. July 2004

Chapter 6: Graph Theory

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Social Media Mining. Graph Essentials

Exam study sheet for CS2711. List of topics

1 Definitions. Supplementary Material for: Digraphs. Concept graphs

Problem Set 7 Solutions

CSC 505, Fall 2000: Week 8

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

An Introduction to APGL

Discrete Mathematics. Hans Cuypers. October 11, 2007

Priority Based Enhancement of Online Power-Aware Routing in Wireless Sensor Network. Ronit Nossenson Jerusalem College of Technology

Data Structures. Chapter 8

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

GRAPH THEORY LECTURE 4: TREES

SCAN: A Structural Clustering Algorithm for Networks

Analysis of Algorithms, I

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Class One: Degree Sequences

TORA : Temporally Ordered Routing Algorithm

Extremal Wiener Index of Trees with All Degrees Odd

Approximation Algorithms

Protein Protein Interaction Networks

CMPSCI611: Approximating MAX-CUT Lecture 20

Outline 2.1 Graph Isomorphism 2.2 Automorphisms and Symmetry 2.3 Subgraphs, part 1

Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs

The Goldberg Rao Algorithm for the Maximum Flow Problem

Introduction to Scheduling Theory

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

On Integer Additive Set-Indexers of Graphs

Connectivity and cuts

Bicolored Shortest Paths in Graphs with Applications to Network Overlay Design

Finding and counting given length cycles

International Journal of Software and Web Sciences (IJSWS)

Computer Science Department. Technion - IIT, Haifa, Israel. Itai and Rodeh [IR] have proved that for any 2-connected graph G and any vertex s G there

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Max Flow, Min Cut, and Matchings (Solution)

Satisfiability Checking

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

Practical Graph Mining with R. 5. Link Analysis

Binary Search Trees 3/20/14

5 Directed acyclic graphs

Midterm Practice Problems

Directed Graphs. digraph search transitive closure topological sort strong components. References: Algorithms in Java, Chapter 19

Lecture 17 : Equivalence and Order Relations DRAFT

Scheduling Shop Scheduling. Tim Nieberg

Network Metrics, Planar Graphs, and Software Tools. Based on materials by Lala Adamic, UMichigan

8.1 Min Degree Spanning Tree

On the Unique Games Conjecture

Cluster detection algorithm in neural networks

The Basics of Graphical Models

Computing Label-Constraint Reachability in Graph Databases

Discrete Mathematics Problems

Data Structure [Question Bank]

Any two nodes which are connected by an edge in a graph are called adjacent node.

Graph Theory Problems and Solutions

Exponential time algorithms for graph coloring

Single machine parallel batch scheduling with unbounded capacity

A Fast Algorithm For Finding Hamilton Cycles

Graph Mining and Social Network Analysis

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Course on Social Network Analysis Graphs and Networks

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Zachary Monaco Georgia College Olympic Coloring: Go For The Gold

On the k-path cover problem for cacti

SPANNING CACTI FOR STRUCTURALLY CONTROLLABLE NETWORKS NGO THI TU ANH NATIONAL UNIVERSITY OF SINGAPORE

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Why? A central concept in Computer Science. Algorithms are ubiquitous.

A permutation can also be represented by describing its cycles. What do you suppose is meant by this?

Determination of the normalization level of database schemas through equivalence classes of attributes

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

Determine If An Equation Represents a Function

Rotation Operation for Binary Search Trees Idea:

Persistent Data Structures

OPTIMAL DESIGN OF DISTRIBUTED SENSOR NETWORKS FOR FIELD RECONSTRUCTION

Mining Social Network Graphs

Three Effective Top-Down Clustering Algorithms for Location Database Systems

The PageRank Citation Ranking: Bring Order to the Web

P. Jeyanthi and N. Angel Benseera

Reductions & NP-completeness as part of Foundations of Computer Science undergraduate course

Reading 13 : Finite State Automata and Regular Expressions

Efficient Data Structures for Decision Diagrams

Subgraph Patterns: Network Motifs and Graphlets. Pedro Ribeiro

Reliability Guarantees in Automata Based Scheduling for Embedded Control Software

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

Examination paper for MA0301 Elementær diskret matematikk

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

Community Detection Proseminar - Elementary Data Mining Techniques by Simon Grätzer

KEYWORD SEARCH OVER PROBABILISTIC RDF GRAPHS

Network File Storage with Graceful Performance Degradation

Transcription:

Directed Graphs BOS ORD JFK SFO LAX DFW MIA Directed Graphs 1

Outline and Reading Reachability Directed DFS Strong connectivity Transitive closure The Floyd-Warshall Algorithm Directed Acyclic Graphs (DAG s) Topological Sorting Directed Graphs 2

Digraphs A digraph is a graph whose edges are all directed Short for directed graph Applications one-way streets flights task scheduling A C E D B Directed Graphs 3

E Digraph Properties D A graph G=(V,E) such that Each edge goes in one direction: Edge (a,b) goes from a to b, but not b to a. If G is simple, m < n*(n-1). If we keep in-edges and out-edges in separate adjacency lists, we can perform listing of inedges and out-edges in time proportional to their size. C A B Directed Graphs 4

Digraph Application Scheduling: edge (a,b) means task a must be completed before b can be started ics21 ics22 ics23 ics51 ics53 ics52 ics161 ics131 ics141 ics121 ics171 ics151 The good life Directed Graphs 5

Directed DFS We can specialize the traversal algorithms (DFS and BFS) to digraphs by traversing edges only along their direction In the directed DFS algorithm, we have four types of edges discovery edges back edges forward edges cross edges A directed DFS starting a a vertex s determines the vertices reachable from s C E A D B Directed Graphs 6

Reachability DFS tree rooted at v: vertices reachable from v via directed paths E D E D C A C B F A E C D F A Directed Graphs 7 B

Strong Connectivity Each vertex can reach all other vertices a c g d e f b Directed Graphs 8

Strong Connectivity Algorithm Pick a vertex v in G. Perform a DFS from v in G. If there s a w not visited, print no. G: a c g Let G be G with edges reversed. d e Perform a DFS from v in G. If there s a w not visited, print no. f b Else, print yes. G : a c g Running time: O(n+m). d e f b Directed Graphs 9

Strongly Connected Components Maximal subgraphs such that each vertex can reach all other vertices in the subgraph Can also be done in O(n+m) time using DFS, but is more complicated (similar to biconnectivity). a c g { a, c, g } f d e b { f, d, e, b } Directed Graphs 10

Transitive Closure Given a digraph G, the transitive closure of G is the digraph G* such that G* has the same vertices as G if G has a directed path from u to v (u v), G* has a directed edge from u to v The transitive closure provides reachability information about a digraph B A B A D C D C E G E G* Directed Graphs 11

Computing the Transitive Closure We can perform DFS starting at each vertex O(n(n+m)) Actually O(n 3 ) for dense graphs Complex 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. Alternatively... Use dynamic programming: The Floyd-Warshall Algorithm O(n 3 ) Simple Directed Graphs 12

Floyd-Warshall Transitive Closure Idea #1: Number the vertices 1, 2,, n. Idea #2: Consider paths that use only vertices numbered 1, 2,, k, as intermediate vertices: i Uses only vertices numbered 1,,k (add this edge if it s not already in) Uses only vertices numbered 1,,k-1 k j Uses only vertices numbered 1,,k-1 Directed Graphs 13

Floyd-Warshall s Algorithm Floyd-Warshall s algorithm numbers the vertices of G as v 1,, v n and computes a series of digraphs G 0,, G n G 0 =G G k has a directed edge (v i, v j ) if G has a directed path from v i to v j with intermediate vertices in the set {v 1,, v k } We have that G n = G* In phase k, digraph G k is computed from G k - 1 Running time: O(n 3 ), assuming areadjacent is O(1) (e.g., adjacency matrix) Algorithm FloydWarshall(G) Input digraph G Output transitive closure G* of G i 1 for all v G.vertices() denote v as v i i i + 1 G 0 G for k 1 to n do G k G k - 1 for i 1 to n (i k) do for j 1 to n (j i, k) do if G k - 1.areAdjacent(v i, v k ) G k - 1.areAdjacent(v k, v j ) if G k.areadjacent(v i, v j ) G k.insertdirectededge(v i, v j, k) return G n Directed Graphs 14

Floyd-Warshall Example BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 15

Floyd-Warshall, Iteration 1 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 16

Floyd-Warshall, Iteration 1 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 17

Floyd-Warshall, Iteration 2 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 18

Floyd-Warshall, Iteration 3 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 19

Floyd-Warshall, Iteration 3 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 20

Floyd-Warshall, Iteration 4 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 21

Floyd-Warshall, Iteration 4 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 22

Floyd-Warshall, Iteration 5 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 23

Floyd-Warshall, Iteration 5 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 24

Floyd-Warshall, Iteration 6 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 25

Floyd-Warshall, Iteration 7 BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 26

Floyd-Warshall, Conclusion BOS v 7 ORD v 4 v 2 SFO JFK v 6 LAX v 1 v 3 DFW MIA v 5 Directed Graphs 27

DAGs and Topological Ordering A directed acyclic graph (DAG) is a digraph that has no directed cycles A topological ordering of a digraph is a numbering v 1,, v n of the vertices such that for every edge (v i, v j ), we have i < j Example: in a task scheduling digraph, a topological ordering of a task sequence satisfies the precedence constraints Theorem A digraph admits a topological ordering if and only if it is a DAG v 2 v 1 B A B A Directed Graphs 28 D C E DAG G v 4 v 5 D E C v3 Topological ordering of G

Topological Sorting Number vertices, so that (u,v) in E implies u < v wake up 2 3 eat study computer sci. 7 play 9 1 make cookies for professors nap 8 write c.s. program 10 sleep A typical student day 4 5 more c.s. 6 work out dream about graphs Directed Graphs 29 11

Algorithm for Topological Sorting Note: This algorithm is different (more compact) than the one in Goodrich-Tamassia (yet of the same big-oh) Method TopologicalSort(G) H G // Temporary copy of G n G.numVertices() while H is not empty do Let v be a vertex with no outgoing edges Label v n n n - 1 Remove v from H Running time: O(n + m). Why? Directed Graphs 30

Topological Sorting Algorithm using DFS Simulate the algorithm by using depth-first search Algorithm topologicaldfs(g) Input dag G Output topological ordering of G n G.numVertices() for all u G.vertices() setlabel(u, UNEXPLORED) for all e G.edges() setlabel(e, UNEXPLORED) for all v G.vertices() if getlabel(v) = UNEXPLORED topologicaldfs(g, v) O(n+m) time. Algorithm topologicaldfs(g, v) Input graph G and a start vertex v of G Output labeling of the vertices of G in the connected component of v setlabel(v, VISITED) for all e G.outgoingEdges(v) if getlabel(e) = UNEXPLORED w opposite(v,e) if getlabel(w) = UNEXPLORED setlabel(e, DISCOVERY) topologicaldfs(g, w) else {e is a forward or cross edge} Label v with topological number n n n - 1 Directed Graphs 31

Topological Sorting Example Directed Graphs 32

Topological Sorting Example 9 Directed Graphs 33

Topological Sorting Example 8 9 Directed Graphs 34

Topological Sorting Example 8 7 9 Directed Graphs 35

Topological Sorting Example 6 8 7 9 Directed Graphs 36

Topological Sorting Example 6 5 8 7 9 Directed Graphs 37

Topological Sorting Example 6 4 5 8 7 9 Directed Graphs 38

Topological Sorting Example 3 6 4 5 8 7 9 Directed Graphs 39

Topological Sorting Example 2 3 6 4 5 8 7 9 Directed Graphs 40

Topological Sorting Example 2 1 3 6 4 5 8 7 9 Directed Graphs 41