1 Strongly connected components. 2 Definition: the strongly connected components (SCC) C 1, …, C k of a directed graph G = (V,E) are the largest disjoint.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
CSC401 – Analysis of Algorithms Lecture Notes 14 Graph Biconnectivity
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
1 Chapter 22: Elementary Graph Algorithms IV. 2 About this lecture Review of Strongly Connected Components (SCC) in a directed graph Finding all SCC (i.e.,
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
CS 312 – Graph Algorithms1 Graph Algorithms Many problems are naturally represented as graphs – Networks, Maps, Possible paths, Resource Flow, etc. Ch.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Tirgul 8 Graph algorithms: Strongly connected components.
Tirgul 11 DFS Properties of DFS Topological sort.
16a-Graphs-More (More) Graphs Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Graph Traversals Reading Material: Chapter 9. Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application.
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
Connected Components, Directed Graphs, Topological Sort COMP171.
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Tirgul 11 BFS,DFS review Properties Use. Breadth-First-Search(BFS) The BFS algorithm executes a breadth search over the graph. The search starts at a.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
CS 312: Algorithm Analysis Lecture #16: Strongly Connected Components This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
COSC 3101A - Design and Analysis of Algorithms 10
Spring 2015 Lecture 10: Elementary Graph Algorithms
The Shape of the Web So, the Web is a directed graph, but what does it look like?
Nattee Niparnan. Graph  A pair G = (V,E)  V = set of vertices (node)  E = set of edges (pairs of vertices)  V = (1,2,3,4,5,6,7)  E = ((1,2),(2,3),(3,5),(1,4),(4,
The Tutte Polynomial Graph Polynomials winter 05/06.
Graphs.
Algorithm for obtaining the connected components of a graph Samia Qader 252a-az HW # 6 all examples obtained from LEDA software in directory: 252a/handout/demo/graphwin/graphwin.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components.
Chapter 22: Elementary Graph Algorithms
Strongly Connected Components for Directed Graphs Kelley Louie Credits: graphs by /demo/graphwin/graphwin.
 2004 SDU 1 Lecture5-Strongly Connected Components.
Hw. 6: Algorithm for finding strongly connected components. Original digraph as drawn in our book and in class: Preorder label : Postorder label Nodes:
GRAPH ALGORITHM. Graph A pair G = (V,E) – V = set of vertices (node) – E = set of edges (pairs of vertices) V = (1,2,3,4,5,6,7) E = ( (1,2),(2,3),(3,5),(1,4),(4,5),(6,7)
11 Graph Search Algorithms. 2 What parts of the graph are reachable from a given vertex ?
Lecture 7 Graph Traversal
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
Graph Algorithms – 2. graphs Parenthesis Theorem Theorem 22.7 For all u, v, exactly one of the following holds: 1. d[u] < f [u] < d[v] < f [v] or.
Nattee Niparnan. Graph  A pair G = (V,E)  V = set of vertices (node)  E = set of edges (pairs of vertices)  V = (1,2,3,4,5,6,7)  E = ((1,2),(2,3),(3,5),(1,4),(4,
CS138A Elementary Graph Algorithms Peter Schröder.
Introduction to Algorithms
Tracing An Algorithm for Strongly Connected Components that uses Depth First Search Graph obtained from Text, page a-al: Geetika Tewari.
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
Chapter 3. Decompositions of Graphs
School of Computing Clemson University Fall, 2012
Graph Theory and Algorithm 01
Lecture 12 Graph Algorithms
Graph Algorithms Using Depth First Search
Biconnectivity SEA PVD ORD FCO SNA MIA 11/16/2018 2:31 AM
Graph Algorithms – 2 DAGs Topological order
Lecture 10 Algorithm Analysis
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
Biconnectivity SEA PVD ORD FCO SNA MIA 5/6/2019 5:08 PM Biconnectivity
Biconnectivity SEA PVD ORD FCO SNA MIA 5/23/ :21 PM
Lecture 11 Graph Algorithms
Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application may require that vertices be visited in some.
Presentation transcript:

1 Strongly connected components

2 Definition: the strongly connected components (SCC) C 1, …, C k of a directed graph G = (V,E) are the largest disjoint sub-graphs (no common vertices or edges) such that for any two vertices u and v in C i, there is a path from u to v and from v to u. Equivalence classes of the binary path(u,v) relation, denoted by u ~ v. Applications: networking, communications. Problem: compute the strongly connected components of G in linear time Θ(|V|+|E|).

3 Example: strongly connected components d bfeac g h

4 d bfeac g h

5 Strongly connected components graph Definition: the SCC graph G ~ = (V ~,E ~ ) of the graph G = (V,E) is as follows: n V ~ = {C 1, …, C k }. Each SCC is a vertex. n E ~ = {(C i,C j )| i≠j and there is (x,y)  E, where x  C i and y  C j }. A directed edge between components corresponds to a directed edge between them from any of their vertices. G ~ is a directed acyclic graph (no directed cycles)! Definition: the reverse graph G R = (V,E R ) of the graph G = (V,E) is G with its edge directions reversed: E R = {(u,v)| (v,u)  E}.

6 Example: reverse graph G R d bfeac g h d bfeac g h G G R

7 Example: SCC graph C1C1 C2C2 C4C4 C3C3 d bfe a c g h

8 SCC algorithm: Approach H  G~ For i=k,...,1 v  node of G that lies in a sink node of H (*) C  connected component retuned by DFS(v) H  H - C End n If we manage to execute (*) we are done

9 DFS numbering Useful information n pre(v): “time” when a node is visited in a DFS n post(v): “time” when DFS(v) finishes 1/16 d bfeac g h 2/15 3/14 4/13 7/12 8/11 9/10 5/6

10 DFS numbering DFS(G) 0. time  1 1Para todo v em G 2Se v não visitado então 3DFS-Visit(G, v) DFS-Visit(G, v) 1Marque v como visitado 1.5pre(v)  time; time++ 2 Para todo w em Adj(v) 3 Se w não visitado então 4 Insira aresta (v, w) na árvore 5DFS-Visit(G, w) 6Post(v)  time; time++

11 DFS numbering Property If C an D are strongly connected components and there is an edge from a node in C to a node in D, then the highest post() in C is bigger than the highest post() number in D Proof. Let c be the first node visited in C and d be the first node visited in D. Case i) c is visited before d. n DFS(c) visit all nodes in D (they are reachable from c due to the existing edge) n Thus, post(c) > post(x) for every x in D

12 DFS numbering Property If C an D are strongly connected components and there is an edge from a node in C to a node in D, then the highest post() in C is bigger than the highest post() number in D Proof. Let c be the first node visited in C and d be the first node visited in D Case 2) d is visited before c. n DFS(d) visit all nodes in D because all of them are reachable from d n DFS(d) does not visit nodes from C since they are not reachable from d. n Thus, post(x) <post(y) for every pair of nodes x,y, with x in D and y in C

13 DFS numbering Corollary. The node of G with highest post number lies in a source node in G~ Observation 1. The strongly connected components are the same in G and G R Observation 2. If a node lies in a source node of G~ then it lies in a sink node in (G R )~

14 SCC algorithm Idea: compute the SCC graph G ~ = (V ~,E ~ ) with two DFS, one for G and one for its reverse G R, visiting the vertices in reverse order. SCC(G) 1. DFS(G) to compute post[v], ∀ v  V 2. Compute G R 3. DFS(G R ) in the order of decreasing post[v] 4. Output the vertices of each tree in the DFS forest as a separate SCC.

15 Example: computing SCC 1/6 d b f e a c g h 3/4 10/15 11/12 9/16 7/8 13/14 2/5

16 Example: computing SCC d b f eac g h 8 1/6 d b f e a c g h 3/4 10/15 11/12 9/16 7/8 13/14 2/5 16

17 Example: computing SCC d b f eac g h 8 1/6 d b f e a c g h 3/4 10/15 11/12 9/16 7/8 13/14 2/5 16 C1C1 C4C4 C2C2 C3C