17
1 Strongly connected components

Strongly connected components

  • Upload
    cana

  • View
    41

  • Download
    1

Embed Size (px)

DESCRIPTION

Strongly connected components. Strongly connected components. - PowerPoint PPT Presentation

Citation preview

Page 1: Strongly connected components

1

Strongly connected components

Page 2: Strongly connected components

2

Strongly connected components

Definition: the strongly connected components (SCC) C1, …, Ck 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 Ci, 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|).

Page 3: Strongly connected components

3

Example: strongly connected components

d

b

f

e

a

c

g

h

Page 4: Strongly connected components

4

Example: strongly connected components

d

b

f

e

a

c

g

h

Page 5: Strongly connected components

5

Strongly connected components graph

Definition: the SCC graph G~ = (V~,E~) of the graph G = (V,E) is as follows:

V~ = {C1, …, Ck}. Each SCC is a vertex.

E~ = {(Ci,Cj)| i≠j and there is (x,y)E, where xCi and yCj}. 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,ER) of the graph G = (V,E) is G with its edge directions reversed: E R = {(u,v)| (v,u)E}.

Page 6: Strongly connected components

6

Example: reverse graph G R

d

b

f

e

a

c

g

h

d

b

f

e

a

c

g

h

G

G R

Page 7: Strongly connected components

7

Example: SCC graph

C1

C2

C4

C3

d

b

f

e

a

c

g

h

Page 8: Strongly connected components

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

If we manage to execute (*) we are done

Page 9: Strongly connected components

9

DFS numbering

Useful information

pre(v): “time” when a node is visited in a DFS post(v): “time” when DFS(v) finishes

1/16

d

b

f

e

a

c

g

h

2/15 3/14

4/13

7/128/11

9/105/6

Page 10: Strongly connected components

10

DFS numbering

DFS(G)0. time 11 Para todo v em G2 Se v não visitado então 3 DFS-Visit(G, v)

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

Page 11: Strongly connected components

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.

DFS(c) visit all nodes in D (they are reachable from c due to the existing edge)

Thus, post(c) > post(x) for every x in D

Page 12: Strongly connected components

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. DFS(d) visit all nodes in D because all of them

are reachable from d DFS(d) does not visit nodes from C since they

are not reachable from d. Thus , post(x) <post(y) for every pair of nodes

x,y, with x in D and y in C

Page 13: Strongly connected components

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)~

Page 14: Strongly connected components

14

SCC algorithm

Idea: compute the SCC graph G~ = (V~,E~) with two DFS, one for G and one for its reverse GR, visiting the vertices in reverse order.

SCC(G)

1. DFS(G) to compute post[v], ∀vV

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.

Page 15: Strongly connected components

15

Example: computing SCC

1/6

d

b

f

e

a

c

g

h

3/4

10/15

11/129/16

7/813/14

2/5

Page 16: Strongly connected components

16

Example: computing SCC

d

b

f

e

a

c

g

h8

1/6

d

b

f

e

a

c

g

h

3/4

10/15

11/129/16

7/813/14

2/5

16

Page 17: Strongly connected components

17

Example: computing SCC

d

b

f

e

a

c

g

h8

1/6

d

b

f

e

a

c

g

h

3/4

10/15

11/129/16

7/813/14

2/5

16

C1

C4

C2

C31

2

34