Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2004 SDU 1 Lecture5-Strongly Connected Components.

Similar presentations


Presentation on theme: " 2004 SDU 1 Lecture5-Strongly Connected Components."— Presentation transcript:

1  2004 SDU 1 Lecture5-Strongly Connected Components

2  2004 SDU 2 Strongly Connected Components A strongly connected component of a directed graph G = (V, E) is a maximal set V’  V of vertices such that for each pair of vertices u and v in V’, they are reachable from each other.  (1): Every pair of vertices in V’ are reachable from each other; (2): Any other vertex set that contains V’ as a true subset does NOT satisfy (1). 5 4 1 3 2 Is {1,2,3} a strongly connected component? Is {1,2,3,4} a strongly connected component? And {5}?

3  2004 SDU 3 The Strongly Connected Components Decomposition Problem The problem:  Input: A directed graph G = (V, E).  Output: All the strongly connected components of G. In practice, many algorithms that work with directed graphs begin with a strongly connected components decomposition.

4  2004 SDU 4 Observation For each tree in a depth-first forest of a graph G:  It contains all the vertices in the same SCC as the root  But, it may also contain some that are not! 1/8 a b f e cg d 2/7 3/4 5/6 9/14 10/11 12/13

5  2004 SDU 5 If we regard each SCC as one vertex, and sort them in topological sort… 1/8 a b e 2/7 3/4 f 5/6 c 10/11 g 12/13 d 9/14 How if we could know the topological sort of the SCCS and one representation of each SCCS?

6  2004 SDU 6 If we list the SCCS in order of decreasing finishing times, is this a topological sort? YES How to choose representations of SCCS? How to decide their order? Latest finished vertex in the SCC? 1/8 a b 2/7 e 3/4 f 5/6 g 12/13 d 9/14 c 10/11 If search in increasing f[] order, then e is searched first, but its SCC is not first finished

7  2004 SDU 7 How if reorder the edges and search in decreasing f[] order? 1/8 a b 2/7 e 3/4 f 5/6 g 12/13 d 9/14 c 10/11

8  2004 SDU 8 Observations Given a directed graph G = (V, E)  G and G T have exactly the same strongly connected components, that is,  u and v are reachable from each other in G if and only if they are reachable from each other in G T.  Note: G T is the transpose of G, i.e., G T =(V, E T ), where E T ={(v, u)| (u, v)  E}. Given an adjacency-list representation of G, the time to create G T is  (V + E).

9  2004 SDU 9 The Component Graph of G The component graph G SCC = (V SCC, E SCC ) of a directed graph G = (V, E) is defined as follows:  Suppose that G has strongly connected components C 1, C 2, …, C k : – The vertex set V SCC = {v i | v i corresponds to component C i of G} –The edge set E SCC = {(v i, v j ) | G contains a directed edge (x, y) for some x  C i and some y  C j } If we know all the SCCs of G, how can we construct the component graph G SCC ?

10  2004 SDU 10 A Key Property of G SCC The component graph G SCC = (V SCC, E SCC ) is a directed acyclic graph. (Lemma 22.13)  Proof. Suppose for the contrary that G SCC is cyclic, that is, there exist two vertices u, v  V SCC such that u and v are reachable from each other. Suppose u and v represent the two strongly connected components C u and C v of G, then vertices in C u and C v are reachable from each other, which contradicts with the definition of strongly connected component.

11  2004 SDU 11 An Example (a): The graph G with its SCCs shaded (c): The component graph G SCC = (V SCC, E SCC ) of G (b): The transpose G T of G with SCCs shaded

12  2004 SDU 12 The Algorithm Time Complexity: line 1, line 2, line 3:  (V + E) line 4: O(V) How?

13  2004 SDU 13 Notations If U  V, define  d[U] = min u  U {d[u]}, the discovery time of vertex set U, that is, the earliest discovery time of any vertex in U;  f[U] = max u  U {f[u]}, the finishing time of vertex set U, that is, the latest finishing time of any vertex in U.

14  2004 SDU 14 A Key Property Related to SCCs and finishing times Lemma 22.14  Let C and C’ be distinct strongly connected components in directed graph G = (V, E). Suppose that there is an edge (u, v)  E, where u  C and v  C’. Then f(C) > f(C’).  Proof: C’ C u v Case 1: d[C] d[C’] x y

15  2004 SDU 15 Can we order the f[u] for all vertices and search from the smallest f[u]? C1 C2C3 C4 C5 f(C1)>f(C2)>f(C3)…

16  2004 SDU 16 A Corollary Corollary 22.15  Let C and C’ be distinct strongly connected components in directed graph G = (V, E). Suppose that there is an edge (u, v)  E T, where u  C and v  C’. Then f(C) < f(C’).  Here, the finishing time is got from the first depth- search  Proof: –(u, v)  E T  (v, u)  E, G and G’ have the same strongly connected components, Lemma 22.14 implies f(C) < f(C’).

17  2004 SDU 17 C1 C2C3 C4 C5 Can we search from the largest f[u] in G T ? f(C1)>f(C2)>f(C3)…

18  2004 SDU 18 Correctness of the Algorithm Theorem 22.16  STRONGLY-CONNECTED-COMPONENTS(G) correctly computes the strongly connected components of a directed graph G.  Proof: By induction on the number k of depth-first trees found in line 3, prove that the vertices of each tree form a strongly connected component, that is 1.The vertex set V(T) of each depth-first tree contains all the vertices of a strongly connected component C 2.V(T) dose not contain any more vertices other than those of C –Basic step: k = 0, it is trivially true.

19  2004 SDU 19 Proof (Continued) C1C1 C2C2 C k+2 …… C k+1 C k+3 CmCm CkCk T1T1 T2T2 TkTk T k+1 ?

20  2004 SDU 20 Proof (continued) Inductive step: Assume that each of the first k depth-first trees produced in line 3 is a strongly connected component. Consider the (k+1)st tree produced.  Let the root of the tree be vertex u, and let u be in strongly connected component C. By induction hypothesis, no vertices in C had been searched before, and since u has the biggest f[] among all the remaining vertices, f[u] = f[C] > f[C’] for any strongly connected component C’ other than C that has yet not been visited.

21  2004 SDU 21 Proof (continued ) 1.At time d[u], all other vertices of C are white. By the white-path theorem, all other vertices of C are descendants of u in its depth-first tree. 2.Moreover, by induction hypothesis and Corollary 22.15, any edge in G T that leaves C must point to SCC that have already been visited. Thus, no vertex in any SCC other than C will be a descendant of u during the depth- first search of G T. Thus, the vertices of the depth-first tree in G T that is rooted at u form exactly one strongly connected component.

22  2004 SDU 22 A Conjecture Prof Deaver: The algorithm for strongly connected components can be simplified by using the original (instead of the transpose) graph in the second depth- first search and scanning the vertices in order of increasing finishing times. Is the conjecture correct?

23  2004 SDU 23 The Answer 1/10 2/5 3/4 6/9 7/8 The reason is that the order of finishing times of vertices may not really reflect the order of finishing times of SCCs. C C’

24  2004 SDU 24 Semi-connected Graph A directed graph G = (V, E) is semi-connected if for all pairs of vertices u, v  V, we have u  v (v is reachable from u) or v  u (u is reachable from v) or both. How to determine whether or not a directed graph is semi-connected? (Exercise 22.5-7)

25  2004 SDU 25 An Observation Given a directed graph G = (V, E), its strongly connected component graph is denoted as G SSC = (V SCC, E SCC ). Then G is semi-connected if and only if for any pair of vertices u, v  V SSC, either u is reachable from v or v is reachable from u ( notice that there can not be paths in both directions).

26  2004 SDU 26 C1 C2C3 C4 C5 Notice that G SCC is acyclic. Suppose above is a topological sort of G SCC, then edges can only point from the left to right. Then C 1 must reach each C 2 …,C 5, C 2 must reach each C 3,…,C 5, …, C 4 must reach C 5. Then the red edges must exist, Vise versa.

27  2004 SDU 27 The Algorithm Outline 1.Compute the strongly connected components of G. 2.Construct the component graph G SCC of G. 3.Topological Sort G SCC. 4.Judge whether there is an edge from C i to C i+1, for 0<i<m, if no, return “no”, where C i is indexed by topological sort, and m is the number of SCCs. 5.Return “yes”.  Time complexity:  (V + E)

28  2004 SDU 28 Another method In step 3, generate topological sort by using the method that each time finding a vertex of zero in- degree. Then G is semi-connected if and only if in each run, exactly one vertex of in-degree zero exists. Proof?  simple  by induction on # of SCCs.

29  2004 SDU 29 An Example (a): The graph G with its SCCs shaded (c): The component graph G SCC = (V SCC, E SCC ) of G (b): The transpose G T of G with SCCs shaded

30  2004 SDU 30 Remarks Until now, we have introduced  Directed graph  Singly connected graph  Semi-connected graph  Strongly connected graph

31  2004 SDU 31 Exercises Page 175: 22.4-3 Page 172: 22.3-12 Page 180: 22.5-5(22.1-4)

32  2004 SDU 32


Download ppt " 2004 SDU 1 Lecture5-Strongly Connected Components."

Similar presentations


Ads by Google