Strongly Connected Components Example: Strongly Connected Components

Total Page:16

File Type:pdf, Size:1020Kb

Strongly Connected Components Example: Strongly Connected Components Data Structures – LECTURE 14 Connected components • Find the largest components (sub-graphs) such that Strongly connected components there is a path from any vertex to any other vertex. • Applications : networking, communications. • Definition and motivation • Undirected graphs : apply BFS/DFS (inner function) • Algorithm from a vertex, and mark vertices as visited . Upon termination, repeat for every unvisited vertex. • Directed graphs : strongly connected components, not Chapter 22.5 in the textbook (pp 552—557). just connected: a path from u to v AND from v to u, which are not necessarily the same! Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures, Spring 2006 © L. Joskowicz 2 Example: strongly connected components Example: strongly connected components b e b e a a d g d g c c h f h f Data Structures, Spring 2006 © L. Joskowicz 3 Data Structures, Spring 2006 © L. Joskowicz 4 Strongly connected components Strongly connected components graph • Definition : the strongly connected components • Definition : the SCC graph G~ = ( V~,E~) of the (SCC) C1, …, Ck of a directed graph G = ( V,E) are graph G = ( V,E) is as follows: ~ the largest disjoint sub-graphs (no common vertices – V = { C1, …, Ck}. Each SCC is a vertex. or edges) such that for any two vertices u and v in ~ ∈ ∈ ∈ – E = {( Ci,C j)| i≠j and ( x,y) E, where x Ci and y Cj}. Ci, there is a path from u to v and from v to u. A directed edge between components corresponds to a • Equivalence classes of the binary relation path (u,v) directed edge between them from any of their vertices. denoted by u ~ v. The relation is not symmetric! • G~ is a directed acyclic graph (no directed cycles)! • Goal : compute the strongly connected components • Definition : the transpose graph GT = ( V,ET) of the of G in time linear in the graph size (| V|+| E|). graph G = ( V,E) is G with its edge directions reversed: ET= {( u,v)| ( v,u )∈E}. Data Structures, Spring 2006 © L. Joskowicz 5 Data Structures, Spring 2006 © L. Joskowicz 6 1 Example: SCC graph Example: transpose graph GT G C b e b e 3 C 4 a d a g d C1 c T g h f G c C2 b e h f a d g c h f Data Structures, Spring 2006 © L. Joskowicz 7 Data Structures, Spring 2006 © L. Joskowicz 8 SCC algorithm Example: computing SCC (1) 2/5 3/4 ~ ~ ~ b Idea : compute the SCC graph G = ( V ,E ) with two 1/6 e DFS, one for G and one for its transpose GT, a visiting the vertices in reverse order . 7/16 d g 11/12 SCC( G) c h f ∀ ∈ 14/15 1. DFS( G) to compute finishing times f [v], v V 9/10 8/13 2. Compute GT 3. DFS( GT) in the order of decreasing f [v] 4. Output the vertices of each tree in the DFS forest as a separate SCC. Data Structures, Spring 2006 © L. Joskowicz 9 Data Structures, Spring 2006 © L. Joskowicz 10 Example: computing SCC (2) Example: computing SCC (3) 2/5 3/4 b e 5 4 1/6 b e a 12 7/16 d g 11/12 a 16 d c 6 g h f 14/15 5 4 c 8/13 h f 9/10 b e 15 10 13 b e 12 2/7 a a 16 d 1/8 d 6 g g c c h f h 15 f Data Structures, Spring 2006 © L. Joskowicz 10 13 11 Data Structures, Spring 2006 © L. Joskowicz 4/5 3/6 12 2 Example: computing SCC (4) Example: computing SCC (5) 5 4 5 4 b e b e 12 12 a a 16 d 16 d 6 g 6 g c c h f h f 15 15 10 13 b e 10 13 b e a a 1/2 c 1/2 Data Structures, Spring 2006 © L. Joskowicz 13 Data Structures, Spring 2006 © L. Joskowicz 14 Example: computing SCC (6) Example: computing SCC (2) 5 Labeled transpose graph G T b e 12 2 b e a 16 d g 6 a 34’’ 4’ 4 d c 1/4 2/3 1 g 2 h f C4 15 c b e 10 13 h f C3 4 3 C1 1 C2 Data Structures, Spring 2006 © L. Joskowicz 15 Data Structures, Spring 2006 © L. Joskowicz 16 Proof of correctness: SCC (1) Proof of correctness: SCC (2) Lemma 2 : Let C and C’ be two distinct SCC of Lemma 1 : Let C and C’ be two distinct SCC of ∈ ∈ ∈ G = ( V,E), let u,v ∈ C and u’,v’ ∈ C’. G, and let ( u,v) E where and u C and v C’. If there is a path from u to u’, then there Then , f [C] > f [C’]. cannot be a path from v’ to v. Proof: there are two cases, depending on which Definition : the start and finishing times of a set of strongly connected component, C or C’ vertices U ⊆ V is: is discovered first: d[U] = min u∈U{d [u]} 1. C was discovered before C’: d(C) < d(C’) f [U] = max u∈U{f [u]} 2. C was discovered after C’: d(C) > d(C’) Data Structures, Spring 2006 © L. Joskowicz 17 Data Structures, Spring 2006 © L. Joskowicz 18 3 Example: finishing times Example: finishing times 2/5 3/4 2/5 3/4 b b 1/6 e 1/6 e a a 7/16 d g 11/12 7/16 d g 11/12 c f [C ] = 5 c h f 4 h f f [C4] = 5 14/15 14/15 8/13 8/13 9/10 b e 9/10 b e a a d g d g f [C3] = 6 f [C3] = 6 c c h f h f Data Structures, Spring 2006 © L. Joskowicz f [C2] = 15 19 Data Structures, Spring 2006 © L. Joskowicz f [C2] = 15 20 f [C1] = 16 f [C1] = 16 Proof of correctness: SCC (3) Proof of correctness: SCC (4) 1. d(C) < d(C’): C discovered before C’ 2. d(C) > d(C’): C discovered after C’ • Let x be the first vertex discovered in C. Let y be the first vertex discovered in C’. • There is a path in G from x to each vertex of C • At time d[y], all vertices in C’ are unvisited. There which has not yet been discovered. is a path in G from y to each vertex of C’ which has • Because (u,v) ∈E, for any vertex w∈C’, there is only vertices not yet discovered. Thus, all vertices in also a path at time d[x] from x to w in G consisting C’ will become descendants of y in the depth-first only of unvisited vertices: xuvw. tree, and so f [y] = f [C’]. • At time d[y], all vertices in C are unvisited. Since • Thus, all vertices in C and C’ become descendants there is an edge (u,v) from C to C’, there cannot, by of x in the depth-first tree. Lemma 1, be a path from C’ to C. Hence, no vertex • Therefore, f [x] = f [C] > f [C’]. in C is reachable from y. Data Structures, Spring 2006 © L. Joskowicz 21 Data Structures, Spring 2006 © L. Joskowicz 22 Proof of correctness: SCC (5) Proof of correctness: SCC (6) ∈ T ∈ ∈ 2. d(C) > d(C’) Corollary : for edge (u,v) E , and u C and v’ C’ • At time f [y], therefore, all vertices in C are f [C] < f [C’] unvisited. Thus, no vertex in C is reachable from y. • This provides shows to what happens during the • At time f [y], therefore, all vertices in C are still second DFS. unvisited. Thus, for anuy vertex w in C: • The algorithm starts at x with the SCC C whose f [w] > f [y] f [C] > f [C’]. finishing time f [C] is maximum. Since there are no vertices in GT from C to any other SCC, the search from x will not visit any other component! • Once all the vertices have been visited, a new SCC is constructed as above. Data Structures, Spring 2006 © L. Joskowicz 23 Data Structures, Spring 2006 © L. Joskowicz 24 4 Proof of correctness: SCC (7) Proof of correctness: SCC (8) Theorem : The SCC algorithm computes the strongly • When u is visited, all the vertices v in its SCC have not connected components of a directed graph G. been visited. Therefore, all vertices v are descendants Proof : by induction on the number of depth-first trees of u in the depth-first tree. found in the DFS of GT: the vertices of each tree • By the inductive hypothesis, and the corollary, any form a SCC. The first k trees produced by the edges in GT that leave C must be in SCC that have algorithm are SCC. already been visited. Basis : for k = 0, this is trivially true. • Thus, no vertex in any SCC other than C will be a T Inductive step : The first k trees produced by the descendant of u during the depth first search of G . algorithm are SCC. Consider the ( k+1) st tree rooted at • Thus, the vertices of the depth-first search tree in GT u in SCC C. By the lemma, f [u] = f [C] > f [C’] for that is rooted at u form exactly one connected SCC C’ that has not yet been visited. component. Data Structures, Spring 2006 © L. Joskowicz 25 Data Structures, Spring 2006 © L.
Recommended publications
  • Elementary Graph Algorithms (Chapter 22) of Graphs
    CSCE423/823 Computer Science & Engineering 423/823 Introduction Design and Analysis of Algorithms Types of Graphs Representations Lecture 03 | Elementary Graph Algorithms (Chapter 22) of Graphs Elementary Graph Algorithms Applications Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 [email protected] Introduction CSCE423/823 Introduction Types of Graphs are abstract data types that are applicable to numerous Graphs problems Representations of Graphs Can capture entities, relationships between them, the degree of the Elementary relationship, etc. Graph Algorithms This chapter covers basics in graph theory, including representation, Applications and algorithms for basic graph-theoretic problems We'll build on these later this semester 2 / 29 Types of Graphs CSCE423/823 Introduction A (simple, or undirected) graph G = (V; E) consists of V , a Types of nonempty set of vertices and E a set of unordered pairs of distinct Graphs Representations vertices called edges of Graphs D E Elementary V={A,B,C,D,E} Graph Algorithms Applications E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)} A B C 3 / 29 Types of Graphs (2) CSCE423/823 A directed graph (digraph) G = (V; E) consists of V , a nonempty set of vertices and E a set of ordered pairs of distinct vertices called Introduction edges Types of Graphs Representations of Graphs Elementary Graph Algorithms Applications 4 / 29 Types of Graphs (3) CSCE423/823 A weighted graph is an undirected or directed graph with the Introduction additional property that each edge e has associated with it a real Types of number w(e) called its weight Graphs 3 Representations of Graphs Elementary 12 Graph Algorithms 0 Applications -6 7 4 3 Other variations: multigraphs, pseudographs, etc.
    [Show full text]
  • Bidirected Graph from Wikipedia, the Free Encyclopedia Contents
    Bidirected graph From Wikipedia, the free encyclopedia Contents 1 Bidirected graph 1 1.1 Other meanings ............................................ 1 1.2 See also ................................................ 2 1.3 References ............................................... 2 2 Bipartite double cover 3 2.1 Construction .............................................. 3 2.2 Examples ............................................... 3 2.3 Matrix interpretation ......................................... 4 2.4 Properties ............................................... 4 2.5 Other double covers .......................................... 4 2.6 See also ................................................ 5 2.7 Notes ................................................. 5 2.8 References ............................................... 5 2.9 External links ............................................. 6 3 Complex question 7 3.1 Implication by question ........................................ 7 3.2 Complex question fallacy ....................................... 7 3.2.1 Similar questions and fallacies ................................ 8 3.3 Notes ................................................. 8 4 Directed graph 10 4.1 Basic terminology ........................................... 11 4.2 Indegree and outdegree ........................................ 11 4.3 Degree sequence ............................................ 12 4.4 Digraph connectivity .......................................... 12 4.5 Classes of digraphs .........................................
    [Show full text]
  • Graph Algorithms
    Graph Algorithms PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Wed, 29 Aug 2012 18:41:05 UTC Contents Articles Introduction 1 Graph theory 1 Glossary of graph theory 8 Undirected graphs 19 Directed graphs 26 Directed acyclic graphs 28 Computer representations of graphs 32 Adjacency list 35 Adjacency matrix 37 Implicit graph 40 Graph exploration and vertex ordering 44 Depth-first search 44 Breadth-first search 49 Lexicographic breadth-first search 52 Iterative deepening depth-first search 54 Topological sorting 57 Application: Dependency graphs 60 Connectivity of undirected graphs 62 Connected components 62 Edge connectivity 64 Vertex connectivity 65 Menger's theorems on edge and vertex connectivity 66 Ear decomposition 67 Algorithms for 2-edge-connected components 70 Algorithms for 2-vertex-connected components 72 Algorithms for 3-vertex-connected components 73 Karger's algorithm for general vertex connectivity 76 Connectivity of directed graphs 82 Strongly connected components 82 Tarjan's strongly connected components algorithm 83 Path-based strong component algorithm 86 Kosaraju's strongly connected components algorithm 87 Application: 2-satisfiability 88 Shortest paths 101 Shortest path problem 101 Dijkstra's algorithm for single-source shortest paths with positive edge lengths 106 Bellman–Ford algorithm for single-source shortest paths allowing negative edge lengths 112 Johnson's algorithm for all-pairs shortest paths in sparse graphs 115 Floyd–Warshall algorithm
    [Show full text]
  • Graph Theory) 15 3.1 Oriented Graphs
    Strong orientation From Wikipedia, the free encyclopedia Contents 1 Directed acyclic graph 1 1.1 Mathematical properties ....................................... 2 1.1.1 Reachability, transitive closure, and transitive reduction ................... 2 1.1.2 Topological ordering ..................................... 3 1.1.3 Combinatorial enumeration ................................. 3 1.1.4 Related families of graphs .................................. 3 1.2 Computational problems ....................................... 3 1.2.1 Topological sorting and recognition ............................. 3 1.2.2 Construction from cyclic graphs ............................... 4 1.2.3 Transitive closure and transitive reduction .......................... 4 1.2.4 Closure problem ....................................... 4 1.3 Applications .............................................. 4 1.3.1 Path algorithms ........................................ 4 1.3.2 Scheduling .......................................... 4 1.3.3 Data processing networks .................................. 5 1.3.4 Causal structures ....................................... 5 1.3.5 Genealogy and version history ................................ 5 1.3.6 Data compression ...................................... 6 1.4 References .............................................. 6 1.5 External links ............................................. 8 2 Directed graph 9 2.1 Basic terminology ........................................... 10 2.2 Indegree and outdegree .......................................
    [Show full text]
  • Graph Factorization from Wikipedia, the Free Encyclopedia Contents
    Graph factorization From Wikipedia, the free encyclopedia Contents 1 2 × 2 real matrices 1 1.1 Profile ................................................. 1 1.2 Equi-areal mapping .......................................... 2 1.3 Functions of 2 × 2 real matrices .................................... 2 1.4 2 × 2 real matrices as complex numbers ............................... 3 1.5 References ............................................... 4 2 Abelian group 5 2.1 Definition ............................................... 5 2.2 Facts ................................................. 5 2.2.1 Notation ........................................... 5 2.2.2 Multiplication table ...................................... 6 2.3 Examples ............................................... 6 2.4 Historical remarks .......................................... 6 2.5 Properties ............................................... 6 2.6 Finite abelian groups ......................................... 7 2.6.1 Classification ......................................... 7 2.6.2 Automorphisms ....................................... 7 2.7 Infinite abelian groups ........................................ 8 2.7.1 Torsion groups ........................................ 9 2.7.2 Torsion-free and mixed groups ................................ 9 2.7.3 Invariants and classification .................................. 9 2.7.4 Additive groups of rings ................................... 9 2.8 Relation to other mathematical topics ................................. 10 2.9 A note on the typography ......................................
    [Show full text]
  • Graph Algorithms
    Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Directed Graphs Let V be a finite set and E a binary relation on V, that is, E⊆VxV. Then the pair G=(V,E) is called a directed graph. • The elements in V are called vertices. • The elements in E are called edges. • Self-loops are allowed, i.e., E may contain (v,v). 2 Undirected Graphs Let V be a finite set and E a subset of { e | e ⊆ V, |e|=2 }. Then the pair G=(V,E) is called an undirected graph. • The elements in V are called vertices. • The elements in E are called edges, e={u,v}. • Self-loops are not allowed, e≠{u,u}={u}. 3 Adjacency By abuse of notation, we will write (u,v) for an edge {u,v} in an undirected graph. If (u,v) in E, then we say that the vertex v is adjacent to the vertex u. For undirected graphs, adjacency is a symmetric relation. 4 Graph Representations • Adjacency lists • Adjacency matrix 5 Adjacency List Representation a b a b c e b a d e c d c d e + Space-efficient: just O(|V|) space for sparse graphs - Testing adjacency is O(|V|) in the worst case 6 Adjacency Matrix a b c d e a b a 0 1 1 0 0 e b 1 0 0 1 1 c 1 0 0 1 0 c d d 0 1 1 0 1 e 0 1 0 1 0 + Can check adjacency in constant time - Needs Ω(|V|2) space 7 Graph Traversals Ways to traverse or search a graph such that every node is visited exactly once 8 Breadth-First Search 9 Breadth First Search (BFS) Input: A graph G = (V,E) and source node s in V for each node v do mark v as unvisited od mark s as visited enq(Q,s) // first-in first-out queue Q while Q is not empty do u := deq(Q) for each unvisited neighbor v of u do mark v as visited; enq(Q,v); od od 10 BFS Example Visit the nodes in the a b order: s s c a, d d b, c Workout the evolution of the state of queue.
    [Show full text]
  • (Gabow's Vs Kosaraju's) Based on Adjacency List by Saleh Alshomrani & Gulraiz Iqbal King Abdulaziz University, Saudi Arabia
    Global Journal of Computer Science and Technology Network, Web & Security Volume 13 Issue 11 Version 1.0 Year 2013 Type: Double Blind Peer Reviewed International Research Journal Publisher: Global Journals Inc. (USA) Online ISSN: 0975-4172 & Print ISSN: 0975-4350 An Extended Experimental Evaluation of SCC (Gabow's vs Kosaraju's) based on Adjacency List By Saleh Alshomrani & Gulraiz Iqbal King Abdulaziz University, Saudi Arabia Abstract - We present the results of a study comparing three strongly connected components algorithms. The goal of this work is to extend the understandings and to help practitioners choose appropriate options. During experiment, we compared and analysed strongly connected components algorithm by using dynamic graph representation (adjacency list). Mainly we focused on i. Experimental Comparison of strongly connected components algorithms. ii. Experimental Analysis of a particular algorithm. Our experiments consist large set of random directed graph with N number of vertices V and edges E to compute graph performance using dynamic graph representation. We implemented strongly connected graph algorithms, tested and optimized using efficient data structure. The article presents detailed results based on significant performance, preferences between SCC algorithms and provides practical recommenddations on their use. During experimentation, we found some interesting results particularly efficiency of Cheriyan-Mehlhorn- Gabow's as it is more efficient in computing strongly connected components then Kosaraju's algorithm. Keywords : graph algorithms, directed graph, SCC (strongly connected components), transitive closure. GJCST-E Classification : C.2.6 An Extended Experimental Evaluation of SCC Gabows vs Kosarajusbased on Adjacency List Strictly as per the compliance and regulations of: © 2013. Saleh Alshomrani & Gulraiz Iqbal.
    [Show full text]
  • Graph Theory, an Antiprism Graph Is a Graph That Has One of the Antiprisms As Its Skeleton
    Graph families From Wikipedia, the free encyclopedia Chapter 1 Antiprism graph In the mathematical field of graph theory, an antiprism graph is a graph that has one of the antiprisms as its skeleton. An n-sided antiprism has 2n vertices and 4n edges. They are regular, polyhedral (and therefore by necessity also 3- vertex-connected, vertex-transitive, and planar graphs), and also Hamiltonian graphs.[1] 1.1 Examples The first graph in the sequence, the octahedral graph, has 6 vertices and 12 edges. Later graphs in the sequence may be named after the type of antiprism they correspond to: • Octahedral graph – 6 vertices, 12 edges • square antiprismatic graph – 8 vertices, 16 edges • Pentagonal antiprismatic graph – 10 vertices, 20 edges • Hexagonal antiprismatic graph – 12 vertices, 24 edges • Heptagonal antiprismatic graph – 14 vertices, 28 edges • Octagonal antiprismatic graph– 16 vertices, 32 edges • ... Although geometrically the star polygons also form the faces of a different sequence of (self-intersecting) antiprisms, the star antiprisms, they do not form a different sequence of graphs. 1.2 Related graphs An antiprism graph is a special case of a circulant graph, Ci₂n(2,1). Other infinite sequences of polyhedral graph formed in a similar way from polyhedra with regular-polygon bases include the prism graphs (graphs of prisms) and wheel graphs (graphs of pyramids). Other vertex-transitive polyhedral graphs include the Archimedean graphs. 1.3 References [1] Read, R. C. and Wilson, R. J. An Atlas of Graphs, Oxford, England: Oxford University Press, 2004 reprint, Chapter 6 special graphs pp. 261, 270. 2 1.4. EXTERNAL LINKS 3 1.4 External links • Weisstein, Eric W., “Antiprism graph”, MathWorld.
    [Show full text]