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.,

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.
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
CS 473Lecture 131 CS473-Algorithms I Lecture 13-A Graphs.
Lecture 7 March 1, 11 discuss HW 2, Problem 3
Single-Source Shortest- paths. p2. Shortest-paths problems : G=(V,E) : weighted, directed graph w : E  R : weight function P=
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
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.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CS 312 – Graph Algorithms1 Graph Algorithms Many problems are naturally represented as graphs – Networks, Maps, Possible paths, Resource Flow, etc. Ch.
1 Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch]
Tirgul 8 Graph algorithms: Strongly connected components.
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.
CPSC 311, Fall CPSC 311 Analysis of Algorithms Graph Algorithms Prof. Jennifer Welch Fall 2009.
CSE 780 Algorithms Advanced Algorithms Shortest path Shortest path tree Relaxation Bellman-Ford Alg.
1 2 Introduction In last chapter we saw a few consistency tests. In this chapter we are going to prove the properties of Plane-vs.- Plane test: Thm[RaSa]:
CPSC 411 Design and Analysis of Algorithms Set 8: Graph Algorithms Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 8 1.
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
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.
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.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
The Art Gallery Problem
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
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
5.2 Trees  A tree is a connected graph without any cycles.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Elementary Graph Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
1 Chapter 22: Elementary Graph Algorithms II. 2 About this lecture Depth First Search DFS Tree and DFS Forest Properties of DFS Parenthesis theorem (very.
Chapter 22: Elementary Graph Algorithms
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
1 Chapter 22: Elementary Graph Algorithms III. 2 About this lecture Topological Sort.
Great Theoretical Ideas in Computer Science for Some.
Connectivity. Graph Scanning Algorithm Input: A graph G and some vertex s. Output: The set R of vertices reachable from s and a set T ⊆ E(G) such that.
 2004 SDU 1 Lecture5-Strongly Connected Components.
COMPSCI 102 Introduction to Discrete Mathematics.
5. Biconnected Components of A Graph If one city’s airport is closed by bad weather, can you still fly between any other pair of cities? If one computer.
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.
Introduction to Algorithms
Data Structures and Algorithm Analysis Lecture 5
Chapter 3. Decompositions of Graphs
Lecture 16 Strongly Connected Components
Planarity Testing.
Graph Algorithms – 2 DAGs Topological order
Graph Representation Adjacency list representation of G = (V, E)
Lecture 10 Algorithm Analysis
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Applications of DFS Topological sort (for directed acyclic graph)
Chapter 22: Elementary Graph Algorithms I
Advanced Algorithms Analysis and Design
Chapter 22: Elementary Graph Algorithms III
Presentation transcript:

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., decompose a directed graph into SCC)

3 Let G be a directed graph Let u and v be two vertices in G Definition: If u can reach v (by a path) and v can reach u (by a path), then we say u and v are mutually reachable We shall use the notation u  v to indicate u and v are mutually reachable Also, we assume u  u for any node u Mutually Reachable

4 Theorem:  is an equivalence relation Proof: By assumption u  u, so  is reflexive If u  v, then v  u, so  is symmetric Also, if u  v and v  w, then u  w, so  is transitive Thus,  is an equivalence relation

5 Strongly Connected Components Thus, we can partition V based on  Let V 1, V 2, …, V k denote the partition Each V i is called a strongly connected component (SCC) of G E.g., v rs wx tu y

6 Property of SCC Let G = (V, E) be a directed graph Let G T be a graph obtained from G by reversing the direction of every edge in G  Adjacency matrix of G T = transpose of adjacency matrix of G Theorem: G and G T has the same set of SCC ’s

7 Property of SCC Let V 1, V 2, …, V k denote SCC of a graph G Let G SCC be a simple graph obtained by contracting each V i into a single vertex v i We call G SCC the component graph of G v rs wx tu y G V1V1 V2V2 V3V3 G SCC v1v1 v2v2 v3v3

8 Property of G SCC Theorem: G SCC is acyclic Proof: (By contradiction) If G SCC has a cycle, then there are some vertices v i and v j with v i  v j By definition, v i and v j correspond to two distinct SCC V i and V j in G. However, we see that any pair of vertices in V i and V j are mutually reachable  contradiction

9 Property of G SCC Suppose the DAG (directed acyclic graph) on the right side is the G SCC of some graph G v1v1 v2v2 v3v3 v5v5 v4v4 v6v6 Now, suppose we perform DFS on G let u = node with largest finishing time Question: Which SCC can u be located ? (see next Lemma)

10 Property of G SCC Lemma: Consider any graph G. Let G SCC be its component graph. Suppose v is a vertex in G SCC with at least one incoming edge. Then, the node u finishing last in any DFS of G cannot be a vertex of the SCC corresponding to v

11 Proof Let SCC(v) = SCC corresponding to v Since v has incoming edge, there exists w such that (w,v) is an edge in G SCC Inside G SCC w v In the next two slides, we shall show that some node in SCC(w) must finish later than any node in SCC(v) Consequently, u cannot be in SCC(v)

12 Proof Let x = 1st node in SCC(w) discovered by DFS Let y = 1st node in SCC(v) discovered by DFS Let z = last node in SCC(v) finished by DFS // Note: z may be the same as y By white-path theorem, we must have d(y)  d(z)  f(z)  f(y) Inside G SCC(w)SCC(v) x y z

13 Proof If d(x)  d(y) then y becomes x’s descendant (by white-path)  f(z)  f(y)  f(x) If d(y)  d(x) since x cannot be y’s descendant (otherwise, they are in the same SCC)  d(y)  f(y)  d(x)  f(x)  f(z)  f(y)  f(x) Inside G SCC(w)SCC(v) x y z

14 Finding SCC So, we know that u (last finished node of G) must be in an SCC with no incoming edges Let us reverse edge directions, and start DFS on G T from u v1v1 v2v2 v3v3 v5v5 v4v4 v6v6 Question: Who will be u’s descendants ?? v1v1 v2v2 v3v3 v5v5 v4v4 v6v6 New G SCC

15 Finding SCC Note that nodes in the SCC containing u cannot connect to nodes in other SCCs in G T By white-path theorem, the descendants of u in G T must be exactly those nodes in the same SCC as u v1v1 v2v2 v3v3 v5v5 v4v4 v6v6 v1v1 v2v2 v3v3 v5v5 v4v4 v6v6 New G SCC

16 Finding SCC Once DFS on u inside G T has finished, all nodes in the same SCC as u are finished  Any subsequent DFS in G T will be made as if this SCC was removed from G T Now, let u’ be the remaining node in G T whose finishing time (in DFS in G) is latest Where can u’ be located? Who will be the descendents of u’ if we perform DFS in G T now?

17 Our observations lead to the following algorithm for finding all SCCs of G : Finding-all-SCC(G) { 1. Perform DFS on G ; 2. Construct G T ; 3. while (some node in G T is undiscovered) { u = undiscovered node with latest finishing time** ; Perform DFS on G T from u ; } // nodes in the DFS tree from u forms an SCC } // ** Finishing times always refer to Step 1’s DFS

18 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

19 Correctness & Performance The correctness of the algorithm can be proven by induction (Hint: Show that at each sub-search in Step 3, u is chosen from an SCC which has no outgoing edges to any nodes in an “unvisited” SCC of G T.  By white-path theorem, exactly all nodes in the same SCC become u’s descendants) Running Time: O(|V|+|E|) (why?)

20 Homework Exercises: , (due: Dec. 12) Practice at home: