Lecture 10: Strongly Connected Components, Biconnected Graphs

Similar documents
Design and Analysis of Algorithms

Lecture 22 Tuesday, April 10

Graph Algorithms Using Depth First Search

Graph Representation

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

Strongly Connected Components

DFS & STRONGLY CONNECTED COMPONENTS

Finding Strongly Connected Components

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

CSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s

Graph Algorithms. Definition

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Lecture 3: Graphs and flows

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Chapter 22. Elementary Graph Algorithms

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

1 Connected components in undirected graphs

CS Elementary Graph Algorithms

CS Elementary Graph Algorithms

Cut vertices, Cut Edges and Biconnected components. MTL776 Graph algorithms

15-451/651: Design & Analysis of Algorithms October 5, 2017 Lecture #11: Depth First Search and Strong Components last changed: October 17, 2017

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Basic Graph Algorithms

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

Graph Representations and Traversal

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Inf 2B: Graphs II - Applications of DFS

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search

Graph. Vertex. edge. Directed Graph. Undirected Graph

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

CSI 604 Elementary Graph Algorithms

Trees. Arash Rafiey. 20 October, 2015

Algorithm Design and Analysis

Directed Graphs (II) Hwansoo Han

CS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.

Graph: representation and traversal

Minimum Spanning Trees Ch 23 Traversing graphs

Week 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.

Fundamental Graph Algorithms Part Four

Algorithmic Aspects of Communication Networks

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

CHAPTER 23: ELEMENTARY GRAPH ALGORITHMS Representations of graphs

Elementary Graph Algorithms CSE 6331

Undirected Graphs. Hwansoo Han

Discrete mathematics

Data Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort

Solutions to relevant spring 2000 exam problems

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Foundations of Computer Science Spring Mathematical Preliminaries

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Introduction to Algorithms. Lecture 11

Konigsberg Bridge Problem

Matching Theory. Figure 1: Is this graph bipartite?

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

CMPSCI 250: Introduction to Computation. Lecture #22: Graphs, Paths, and Trees David Mix Barrington 12 March 2014

Graph Algorithms: Chapters Part 1: Introductory graph concepts

CS521 \ Notes for the Final Exam

Algorithm Design and Analysis

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

W4231: Analysis of Algorithms

Graph representation

Applications of BDF and DFS

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

(Re)Introduction to Graphs and Some Algorithms

Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CS 473: Algorithms. Chandra Chekuri 3228 Siebel Center. Fall University of Illinois, Urbana-Champaign

Data Structures and Algorithms. Chapter 7. Graphs

Copyright 2000, Kevin Wayne 1

Algorithms and Data Structures

Problem Set 2 Solutions

Elementary Graph Algorithms

Graphs: basic concepts and algorithms

Algorithms: Lecture 10. Chalmers University of Technology

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Shortest Path Routing Communications networks as graphs Graph terminology Breadth-first search in a graph Properties of breadth-first search

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Algorithm Design and Analysis

Advanced algorithms. strongly connected components algorithms, Euler trail, Hamiltonian path. Jiří Vyskočil, Radek Mařík 2012

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Chapter 11: Graphs and Trees. March 23, 2008

Homework No. 4 Answers

Lecture 20 : Trees DRAFT

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS

22.3 Depth First Search

Connectivity. Use DFS or BFS. 03/11/04 Lecture 18 1

Fundamental Graph Algorithms Part Three

Assignment 4 Solutions of graph problems

Transcription:

15-750: Graduate Algorithms February 8, 2016 Lecture 10: Strongly Connected Components, Biconnected Graphs Lecturer: David Witmer Scribe: Zhong Zhou 1 DFS Continued We have introduced Depth-First Search (DFS) earlier in the previous lecture. There are three ways of traversing the graph: 1. Depth-First Search (DFS) 2. Breadth-First Search (BFS) 3. Random Walk DFS, Strongly Connected Components, and Biconnected Components are our focus for this lecture. Before we proceed to Strongly Connected Components, we need to prove a important theorem about Depth-First Search (DFS). For any graph G = (V, E), DFS, the strategy of exhaustively searching every path to the before exploring the next one, takes time O( V + E ). The edges traversed by DFS form a forest. Input: G = (V, E) Initialize u V, u.c = white; Initialize t = 0; for u V do if u.c = white then DFS-visit(u, G); Algorithm 1: DFS The subroutine of DFS is defined as DFS-visit: Input: u, G u.c = grey; t = t + 1; disc(u) = t; for v adj(u) do if v.c = white then DFS-visit(v, G); u.c = black; t = t + 1; finish(u) = t; return F ; Algorithm 2: DFS-visit 1

Figure 1: A DFS Forest Formed by DFS Algorithm (Adapted from an example in [CLRS09] Section 22.3) Theorem 1.1. In a DFS-forest, v is a descant of u if and only if a path of white vertices from u to v at time disc(u). Proof. ( ) v which is a descant of u, we have disc(u) < disc(v) Therefore, v must be white at time disc(u). Since we have proven this for all v which is any descant of u, all descants of u must be white at time disc(u). All vertices in DFS tree path from u to v are white at disc(u). ( ) Suppose a white path from u to v at disc(u). From our assumption we have disc(u) < disc(v). Assume v is the first vertex on path that is not descant of u, let w be its predecessor. Then we have finish(w) finish(u). Then disc(u) < disc(v) < finish(w) finish(u) From the nesting theorem we have proven earlier, we finish v before we finish u, therefore, v is a descant of u. Therefore, we have proven both directions of the statement. 2 Strongly Connected Components In this section, we will see that any graph G = (V, E) can be partitioned into strongly connected components. For a component to be strongly connected, every vertex in the component must be reachable from every other vertex in the same component. We will define an equivalence relation on the graph G and strongly connected components are induced by this equivalence relation. The formal definitions are as follows. Definition 2.1 (Equivalence of nodes). For a directed graph, G = (V, E), u, v V, u v if a path from u to v and a path from v to u. In mathematics, an equivalence relation satisfies reflexivity, symmetry and transitivity. As a consequence of these properties, an equivalence relation provides a partition of a set into equivalence classes. 2

Figure 2: Strongly Connected Components (Adapted from an example in [CLRS09] Section 22.3) Definition 2.2 (Equivalence Relation). A given binary relation R on a set X is said to be an equivalence relation if and only if it is reflexive, symmetric and transitive. That is, for all a, b and c in X: 1. ara. (Reflexivity) 2. arb if and only if bra. (Symmetry) 3. If arb and brc then arc. (Transitivity) Our claim is that the relation that we defined on nodes of a directed graph is also an equivalence relation. The proof is straightforward. Definition 2.3 (Strongly Connected Components of G). Strongly connected components of G are equivalent classes induced by. Each strongly connected component is a maximal set S such that u, v S, u v. Definition 2.4 (Component Graph). If G has set of strongly connected components, C 1, C 2,..., C k, the component graph G scc = (V scc, E scc ) has V scc = 1, 2,..., k and E scc = {(i, j) G has an edge C i C j }. Claim 2.5. Every component graph is a DAG. Proof. We will prove by contradiction. Suppose strongly connected components C 1, C 2,..., C k such that the component graph contains a cycle. Then all components in this cycle can form a bigger strongly connected component by definition. This violates our assumption that strongly connected components are maximal. Therefore, every component graph is a DAG. Therefore, G scc has a topological ordering. Kosaraju s Algorithm uses DFS to find strongly connected components. If a DFS returned a forest such that the trees of the forest were exactly the strongly connected components, we would be all set: we could just run DFS and output the vertices of each DFS tree as a strongly connected component. We then want to order the vertices of our graph so that the trees of the resulting DFS forest are exactly the strongly connected components. That is, we don t want our DFS to traverse edges between strongly connected components. These edges, corresponding to edges of G scc, should be cross edges in our DFS forest. In order for an edge (u, v) to be a DFS cross edge, we must discover the head of the edge v before we discover its tail u so that we don t traverse it in our search. We therefore want a search order corresponding to a reverse topological sort of G scc. 3

Figure 3: Transpose of Graph Recall from the previous lecture, we have shown that in a DAG, reverse finish time gives a topological sort. Since we need a reverse topological sort, it will be convenient to consider the transpose graph, in which every edge is reversed. Definition 2.6 (Transpose of a Graph). Given G = (V, E), the transpose of G is G T = (V, E T ) with E T = {(u, v) (v, u) E} We can now formally state Kosaraju s algorithm (1978) for finding strong components in a graph: Input: G = (V, E) 1. Perform a DFS of G and number the vertices in order of completion of the recursive calls, compute finish(u) u; 2. Construct a new directed graph G T by reversing the direction of every edge in G; 3. Perform a DFS on G T starting the search from the highest numbered vertex according to the decreasing order of finish time; 4. return DFS trees; Algorithm 3: GCC with DFS Now we need to formally prove that this algorithm is correct. We will only consider discovery times and finish times for the first DFS on G; disc and finish will refer to these times. Let U be a subset of V, and define the following: disc(u) = min x U disc(x), finish(u) = max finish(u) x U Lemma 2.7. Let C and C be distinct SCCs. If an edge (u, v) in E where u is in C and v is in C, then finish(c) > finish(c ) Proof. Case 1: disc(c) < disc(c ) Let x be the first vertex discovered in C. We know that at time disc(x), all vertices in C and C are white. For any vertex w C, a white vertex path from x to w. Therefore, all vertices in C and C are descants of x by Theorem 1.1. Thus we have finish(x) = finish(c) > finish(c ) Case 2: disc(c) > disc(c ) Let y be the first vertex discovered in C. All vertices of C are descants of y in our DFS tree. 4

Figure 4: Examples of nodes in undirected graph Therefore, finish(y) = finish(c ). Since G scc is a DAG, there does not exists a path from C to C, which means all vertices in C are still white when we finish. Thus, finish(c) > finish(c ). Therefore, in both cases, we have proven finish(c) > finish(c ). This lemma will be reversed if we look at the transpose: Corollary 2.8. Let C and C be distinct SCCs. If an edge (u, v) in E T where u is in C and v is in C, then finish(c) < finish(c ). Theorem 2.9. Kosaraju s algorithm is correct. Proof. We will do induction on number of DFS tree we have found so far. The base case is trivial. In the induction step, assume the first k trees found are SCCs. We assume the (k + 1) st tree is T, u is the first vertex of T discovered by our DFS, and u is in SCC C. We would like to show that vertices of T are exactly the same as vertices in C; this requires proofs in both directions. ( ) All vertices in C are in T. By our inductive hypothesis, we have that all vertices of C are still white at disc(u). Theorem 1.1 gives that all vertices of T are descants of u. Therefore, all vertices in C are in T. ( ) All vertices in T are in C. The DFS order ensures that f inish(u) = f inish(c) > finish(c ) SCCs C that have not been reached. By Corollary 2.8, there are no edges from C to C, so no vertices in C can be in T. Therefore, all vertices in T are in C. The vertices of T are exactly the vertices of C, and we have proven the induction for k + 1. Thus, Kosaraju s algorithm is correct. 3 Biconnected Components Before we introduce biconnected components, we need to first introduce the notion of articulation points. Definition 3.1 (Articulation Point). For a undirected graph, v is an articulation point if distinct x, y, such that all x, y path go through v. Definition 3.2 (Biconnected Graph). G is biconnected if there is no articulation point. 5

Figure 5: Examples of non-leaf, non-root node in undirected graph An undirected graph will have only tree edges or back edges. Can a leaf be an articulation point? The answer is no because we cannot disconnect a graph by removing leaves. Take a look at Figure 4; the leaf x cannot be an articulation point. If we have a root that only has one child just like the node y at Figure 4, it cannot be an articulation point either becasue we cannot disconnect the graph by removing this node. Now, what kind of root node can be an articulation point? When a root node has at least two children like node z at Figure 4, its removal will result in a disconnected graph; therefore, a root node with at least two children is an articulation point. And now, consider a non-leaf, non-root node. Such a node could be an articulation point if there is not any back edge from a descent to an ancestor in its DFS tree. Take a look at Figure 5; the node u is not an articulation point because there is an edge from its descent w to its ancestor v. Definition 3.3 (Low of a vertex). v in a graph, low(v) is the vertex with the earliest discovery time that is reachable from v by using a directed path that uses just one back edge, i.e., low(v) = min{{disc(v)} {disc(w) u such that u is descant of v and (u, w) is a back edge}}. Theorem 3.4. When using DFS to find articulation points, we have 3 cases: 1. a leaf is never an articulation point 2. a roots is an articulation point if and only if it has at least two children 3. a non-leaf, non-root vertex v is articulation point if and only if child u of v such that low(u) disc(v) References [CLRS09] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. MIT Press, third edition, 2009. 1, 2 6