A Simplified Correctness Proof for a Well-Known Algorithm Computing Strongly Connected Components

Similar documents
Geometric Data Structures

Analysis of Time complexity in Binary Search Tree

Strongly Connected Components

arxiv: v3 [cs.ds] 18 Apr 2011

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

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

Graph Algorithms Using Depth First Search

Lecture 10: Strongly Connected Components, Biconnected Graphs

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

Trees. Arash Rafiey. 20 October, 2015

Chordal Graphs: Theory and Algorithms

The Join the Club Interpretation of Some. Graph Algorithms

st-orientations September 29, 2005

Using Templates to Introduce Time Efficiency Analysis in an Algorithms Course

Algorithmic Aspects of Communication Networks

1. Further Applications of Graph Traversal

Elementary Graph Algorithms CSE 6331

Algorithms & Data Structures 2

Chordal deletion is fixed-parameter tractable

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Improved Space-efficient Linear Time Algorithms for Some Classical Graph Problems

Bicriteria Network Design via Iterative Rounding

Electronic Colloquium on Computational Complexity, Report No. 18 (1998)

Lecture 22 Tuesday, April 10

Complexity Analysis of Routing Algorithms in Computer Networks

A generalization of Mader s theorem

Notes on Binary Dumbbell Trees

2 Approximation Algorithms for Metric TSP

An Algorithm for Enumerating All Spanning Trees of a Directed Graph 1. S. Kapoor 2 and H. Ramesh 3

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

Graph Algorithms. Definition

On Covering a Graph Optimally with Induced Subgraphs

Graph Algorithms. A Brief Introduction. 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ.

Fundamental Graph Algorithms Part Four

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

Minimum-Cost Spanning Tree. as a. Path-Finding Problem. Laboratory for Computer Science MIT. Cambridge MA July 8, 1994.

Introduction to Optimization

1 Connected components in undirected graphs

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

Embedded Width, A Variation of Treewidth for Planar Graphs

International Journal of Scientific & Engineering Research, Volume 4, Issue 7, July ISSN

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Every DFS Tree of a 3-Connected Graph Contains a Contractible Edge

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

Decreasing the Diameter of Bounded Degree Graphs

Applied Mathematics Letters. Graph triangulations and the compatibility of unrooted phylogenetic trees

Lecture 8: PATHS, CYCLES AND CONNECTEDNESS

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Reachability in K 3,3 -free and K 5 -free Graphs is in Unambiguous Logspace

An O (mlogn)-time Algorithm for the Maximal Planar Subgraph Problem

On the Strongly Connected and Biconnected Components of the Complement of Graphs

Greedy algorithms is another useful way for solving optimization problems.

A tight bound for online colouring of disk graphs

VISUALIZING NP-COMPLETENESS THROUGH CIRCUIT-BASED WIDGETS

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Algorithms and Data Structures

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.

A GRAPH FROM THE VIEWPOINT OF ALGEBRAIC TOPOLOGY

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

On-Line Maintenance of Simplified Weighted Graphs for Efficient Distance Queries

Lecture 10. Finding strongly connected components

time using O( n log n ) processors on the EREW PRAM. Thus, our algorithm improves on the previous results, either in time complexity or in the model o

Distributed minimum spanning tree problem

Biconnectivity on Symbolically Represented Graphs: A Linear Solution

Submodularity of Minimum-Cost Spanning Tree Games

Strongly Connected Components. Andreas Klappenecker

Statements or Basic Blocks (Maximal sequence of code with branching only allowed at end) Possible transfer of control

Expected Runtimes of Evolutionary Algorithms for the Eulerian Cycle Problem

Discrete mathematics

W4231: Analysis of Algorithms

Question 2 (Strongly Connected Components, 15 points). What are the strongly connected components of the graph below?

Matching Theory. Figure 1: Is this graph bipartite?

Reducing Directed Max Flow to Undirected Max Flow and Bipartite Matching

Dominating Set on Bipartite Graphs

On the Complexity of Broadcast Scheduling. Problem

Assignment # 4 Selected Solutions

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class.

NOTE ON MINIMALLY k-connected GRAPHS

(Re)Introduction to Graphs and Some Algorithms

HW Graph Theory SOLUTIONS (hbovik) - Q

GRAPH THEORETICAL ALGORITHMS FOR CONTROL FLOW GRAPH COMPARISON

Polynomial-time Algorithm for Determining the Graph Isomorphism

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

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

CS3110 Spring 2017 Lecture 18: Binary Search Trees

The strong chromatic number of a graph

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

Connection of Two Nodes of A Transportation Network by Two Disjoint Paths

arxiv: v3 [cs.dm] 12 Jun 2014

On the Characterization of Plane Bus Graphs

Parameterized graph separation problems

Roman Domination in Complementary Prism Graphs

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

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

Sparse Hypercube 3-Spanners

arxiv: v2 [cs.ds] 25 Jan 2017

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

On the other hand, the main disadvantage of the amortized approach is that it cannot be applied in real-time programs, where the worst-case bound on t

An Implicit Representation of Chordal Comparabilty Graphs in Linear-time

Transcription:

A Simplified Correctness Proof for a Well-Known Algorithm Computing Strongly Connected Components Ingo Wegener FB Informatik, LS2, Univ. Dortmund, 44221 Dortmund, Germany wegener@ls2.cs.uni-dortmund.de Abstract The computation of the strongly connected components of a directed graph is one of the fundamental algorithmic graph problems. Linear-time algorithms with simple implementations are known. Here a simplified correctness proof for one of these algorithms is presented. Keywords: algorithms, depth first search, graph problems, strongly connected components. 1 Introduction The computation of the strongly connected components of a directed graph is one of the fundamental algorithmic graph problems. Remember that two vertices v and w are strongly connected if there is a directed path from v to w (denoted by v w) and a directed path from w to v. A strongly connected component (SCC) is a maximal vertex set where all pairs of vertices are strongly connected. The SCCs are a partition of the vertex set. Tarjan[10] presented the first linear-time algorithm for the computation of all SCCs. His algorithm is based on a DFS traversal and the computation of the socalled low-link numbers. This resembles the computation of the biconnected components of undirected graphs. However, the correctness proof is not too 1

simple (see also [1], [6], [8], and [5]). Variants of this approach are presented in [7] and [9]. A different algorithm is described in [2], [3], and [4]. Again, the presented proofs are not too simple. My experience is that students have difficulties with these SCC algorithms. Therefore, a much simpler and more illustrative correctness proof is presented. In Section 2, the algorithm from [2], [3], and [4] is described. In Section 3, we describe which information on SCCs can be derived from a DFS traversal. These considerations lead to the new correctness proof which uses an inductive argument on the number of SCCs. 2 The Algorithm Here we present a well-known SCC algorithm ([2], [3], [4]). Algorithm 1 G = (V, E) is a directed graph given by adjacency lists. 1.) Perform a DFS traversal on G and compute numbers such that a vertex v whose DFS call is finished later than the DFS call for w gets a smaller number. We refer to these numbers as f-numbers, since they depend on the point of time when the corresponding DFS call is finished. 2.) Compute the reversed graph G = (V, E ) where (v, w) E iff (w, v) E. 3.) Perform a DFS traversal on G where the vertex array (deciding at which vertex a new tree is started) is sorted according to the f-numbers. This algorithm is easy to implement and it is obvious that the runtime is linear, namely O(n + m). The claim is that the vertex sets of the DFS trees computed in Step 3 are the SCCs of G. This looks like a miracle. 3 The Correctness Proof We start our investigations without considering Algorithm 1. We ask which information on the SCCs can be gained from a simple DFS traversal on G, see Figure 1 for an example. We use the convention that the DFS trees are constructed from left to right and that the same holds for the subtrees of a tree. 2

T 1 T 2 T l v... Figure 1: The result of a DFS traversal on G. r Because of our convention, edges between trees lead from right to left and there is no directed path from T i to T j, if i < j. Hence, each SCC is contained in one of the DFS trees. How can we compute one special SCC? We choose the SCC C containing the root r of the last (rightmost) DFS tree T l. The reasons for this choice are twofold. First, r is the only vertex of T l where we know that r v for all v in T l. Hence, C is exactly the set of all vertices v in T l such that v r. Moreover, the set of these vertices can be computed by computing all vertices v in T l such that r v after reversing all edges. Second, this also explains why we have chosen the last tree T l. After reversing all edges the DFS traversal starting at r cannot reach vertices outside T l. Hence, the DFS traversal starting in G at r computes the vertices of the SCC containing r as vertex set of the first DFS tree. Moreover, it is obvious that r is the vertex with the smallest f-number (Step 1 of Algorithm 1). Do we know further properties of the SCC C containing r? If the vertex v of T l (see Figure 1) belongs to C and (r, v 0,..., v m = v) is the T l -path from r to v, then v 0,..., v m 1 also belong to C, since this T l -path and a path from v to r form a cycle. Hence, C is a connected part of T l (see Figure 2). This implies that T l without C consists of subtrees of T l (rooted in Figure 2 at v 1,..., v 5 ). In order to use an inductive argument we like to argue that the resulting forest consisting of T 1,..., T l 1, and the subtrees of T l is also the result of a DFS traversal on the subgraph of G on V C. However, this depends on the initial numbering of the vertices (deciding where to start a new tree). If this numbering equals the DFS numbering obtained in Step 1 of Algorithm 1, we obtain the same DFS forest on V as before and we obtain the desired DFS forest on V C. For our correctness proof we can assume that we start with 3

v 4 v 5 v 1 v 2 v 3 C T l r Figure 2: The DFS tree T l with the SCC C containing r. this DFS numbering, since this does not change the result of the algorithm. Surprisingly enough, this is the main observation. The formal inductive argument is now easy. If G contains only one SCC, this SCC is computed correctly. If G contains k SCCs, then the algorithm computes first the SCC C containing the root of the last DFS tree. Then Step 3 of the algorithm works on the DFS forest obtained by eliminating C and implicitly on a subgraph of G with k 1 SCCs. The correctness of the algorithm on this subgraph follows from the induction hypothesis. All correctness proofs not using induction have to argue about all SCCs and, therefore, much more carefully about the relations between the time intervals of the different DFS calls leading to more sophisticated arguments on the f-numbers. We hope that this clear and illustrative correctness proof supports the teaching of the SCC algorithm described in Section 2. 4

References [1] A. V. Aho, J. E. Hopcroft, and J. D. Ullman. The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974. [2] A. V. Aho, J. E. Hopcroft, and J. D. Ullman. Data Structures and Algorithms. Addison-Wesley, 1983. [3] T. H. Cormen, C. E. Leiserson, and R. L. Rivest. Introduction to Algorithms. MIT Press, 1990. [4] R. H. Güting. Datenstrukturen und Algorithmen. Teubner, 1992. [5] J. van Leeuwen (Ed.). Handbook of Theoretical Computer Science. Vol. A: Algorithms and Complexity. MIT Press, 1990. [6] K. Mehlhorn. Data Structures and Algorithms. Vol. 2: Graph Algorithms and NP-Completeness. Springer, 1984. [7] T. Ottmann and P. Widmayer. Algorithmen und Datenstrukturen. Spektrum Akademischer Verlag, 1996. [8] E. M. Reingold, J. Nievergelt, and N. Deo. Combinatorial Algorithms: Theory and Practice. Prentice-Hall, 1977. [9] R. Sedgewick. Algorithms. Addison-Wesley, 1983. [10] R. E. Tarjan. Depth-first search and linear graph algorithms. SIAM Journal on Computing 1, 146-160, 1972. 5