Strongly Connected Components
Decomposing a directed graph into its strongly connected components is a classic application of DFS. Two vertices of directed graph are in the same component if and only if they are reachable from each other. For example, consider the following directed graph
Diagram
The above directed graph has four strongly connected components, namely {a, b, e}, {c, d}, {f, g} and {h}.
From any vertex v, one can visit to any other vertex in the same component as v and then return back v; if one visits a vertex in a different component the return to v is impossible.
The component graph for the above directed graph is
Diagram
The above directed graph has 4 strongly connected components: c1, c2, c3 and c4. If G has an edge from some vertex in ci to some vertex in cj where i ≠ j, then one can reach any vertex in cj from any vertex in ci but not return. In the example, one can reach any vertex in c3 from any vertex in c1 but cannot return to c1 from c3.
If G = (V, E) is a directed graph, its transpose, GT = (V, ET) is the same as G with all arrows reversed.
For example, given directed graph G = (V, E)
Diagram
The transpose of G = (V, E) is GT = (V, ET)
Diagram
From above example it is apparent that edge set ET contains edge (u, v) iff edge set E contains (u, v). This observation implies that GT has same strongly components as G and the strongly components of G are transposes of strongly components of GT.
ALGORITHM
A DFS(G) produces a forst of DFS-trees. Let C be any strongly connected component of G, let v be the first vertex on C discovered by the DFS and let T be the DFS-tree containing v when DFS-visit(v) is called all vertices in C are reachable from v along paths containing visible vertices; DFS-visit(v) will visit every vertex in C, add it to T as a descendant of v.
STRONGLY-CONNECTED-COMPONENTS(G)
1. Call DFS(G) to compute finishing time for each vertex.
2. Compute transpose of G i.e., GT.
3. Call DFS(GT) but this time consider the vertices in order of decreasing finish time.
4. Out the vertices of each tree in DFS-forest.
Example (CLR) Consider a graph G = (V, E)
1. Call DFS(G)
2. Compute GT
3. Call DFS(GT) but this time consider the vertices in order of decreasing finish time.
First 16
Start with 10
Start with 7
Start with 10
Start with 7
4. Output the vertices of each tree in the DFS-forest as a separate strongly connected component.
{a, b, e}, {c, d}, {f, g} and {h}
The algorithm computes the strongly connected components of a directed graph G = (V, E) using two depth searches, one on G and one on GT. Thus, the total running time is linear i.e., Theta(V + E).
Before leaving strongly connected components, lets prove that component graph of G(V, E) is a directed acylic graph.
Proof (by contradiction)
Suppose component graph of G = (V, E) was not a DAG and G comprised of a cycle consisting of vertices v1, v2 , . . . , vn . Each vi corresponds to a strongly connected component (SCC) of component graph G. If v1, v2 , . . . , vn themselves form a cycle then each vi ( i runs from 1 to n) should have been included in the SCC corresponding to vj ( j runs from 1 to n and i is Not Equal to j). But each of the vertices is a vertex from a difference SCC of G. Hence, we have a contradiction! Therefore, SCC of G is a directed acylic graph.
No comments:
Post a Comment