Adc 8
Adc 8
Course 8
Overview
Applications for DFS
Strongly Connected Components
Articulation Points
Bridges
Biconnected Components
Applications for DFS
Directed graphs
We have seen topological sorting
Strongly connected components
Undirected graphs
Articulation points
Bridges
Biconnected components
Strongly Connected Components
Applications:
Compiler analysis, data mining, scientific computing
Definitions:
Given a directed graph G(V, E), G is strongly connected if u,
v V, there exists a path u..v and a path v..u
uR(v) and vR(u) u, v V
Not all directed graphs are strongly connected
A A
J J
G G
B B
K K
C C
H H
L L
D D
E E
F
F
SCCs - Properties
Let CV – a SCC of G and u, v C. Any vertex z on a path u..z..v
is also in C.
Let x be any vertex in C
=> xR(v), but vR(z) => xR(z)
=> uR(x), but zR(u) => zR(x)
Therefore z C
Let CV – a SCC of G. In any DFS traversal, all the vertices in C are
always in the same DFS tree!
Let u be the first vertex in C that is discovered by the DFS
At d[u], all the other vertices in C are WHITE
There exists a path from u to all the other vertices in C that consists of
intermediate vertices that are all in C (def. of a SCC)
Therefore, there exists a white path from u to all the other vertices in C
=> all the others vertices in C become descendants of u in the same
DFS tree
Run DFS on the Example Graph
A
J
G
B
K
C
H
L
D
F
Transposing a Graph
Given G(V, E)
Complexity:
(n+m) – adjacency lists
(n2) – adjacency matrix
Gt = transpose(G)
DFS_modified(Gt, f[1..n]) // call the modified DFS for G that picks the
// roots of the DFS trees in decreasing
// order of f[u] (plus u being WHITE as
// usual)
PRINT the vertices in each separate DFS tree computed by the call to
DFS_modified. Each DFS tree contains the nodes of a SCC of G
Example – DFS(G)
I
17/24
A
1/16 J
G 18/23
11/14
B
2/15 K
19/22
C
3/10 H
12/13 L
D 20/21
5/6
E
4/9
F
7/8
Example – DFS(GT)
I I
17/24 1/6
A A
1/16 J
9/16 J
G 18/23
G 3/4
11/14 11/14
B B
2/15 K
12/13 K
19/22 2/5
C H
C
3/10 H 10/15
L 17/22
12/13
D 20/21 D
5/6 18/21
E E
4/9 19/20
F F
7/8 23/24
Idea for the Algorithm
If GSCC is a DAG => (GSCC )T is also a DAG
Therefore, for any edge of (GSCC )T: the source vertex has
a lower finish time than the one of the destination vertex
Demonstration
Consider the results of the first DFS (for G):
d[u] and f[u]
Extend the notation for d and f to sets of vertices
Let CV:
(u, v)ET => (v, u)E, uC, vC’ =>f(C’) > f(C)
Using previous lemma
Corollary – Conclusion
Let C and C’ be 2 distinct SCCs in G.
If f(C) > f(C’) there cannot be an edge from C to C’ in
(GSCC)T
If f(C) > f(C’) there cannot be an edge from C to C’ in GT
SCC Algorithm – Conclusion
When running the second DFS on GT , we pick the vertex with the
highest finish time, xV such that f(x)=maximum
Therefore, if C is the SCC that contains x, f(C)>f(C’) for any other
C’ a SCC of G.
Thus, by choosing x as the root of the first DFS tree we can only
explore the nodes that are in C
And we explore all of them => we color them in BLACK
The second vertex that we pick as a root is x’ that has the
maximum finish time out of the remaining white vertices. Let C’ be
the SCC that x’ is part of. Then:
There can be an edge only from C’ to C, but not to any other SCC
And we repeat this process until no vertices are left unvisited!
Thus, we are visiting (GSCC)T in reverse topological sorting order!
Articulation Points
Given a connected undirected graph G(V, E)
low[u] = min(
d[u],
d[x], for all x that can be reached from
any node in Subtree(x) by a back edge
)
Thus, we can take advantage that low[v] has been computed and will
never change when we compute low[u], for all v – children of u in
the DFS tree
Because color[v] is BLACK and we have already explored everything
reachable from v !
Articulation Points - Algorithm
We can use a simple DFS algorithm and make small
changes
We do not need to compute f[u]
We need color[u] to detect back edges, d[u], children[u]
and low[u]
A bridge (or cut edge) is any edge (u, v)E such that by
removing it from the graph, the remaining graph becomes
disconnected
www.cse.ohio-state.edu/~lai/780/9.graph.pdf