I am reading Introduction to Algorithms. In 22.5 Strongly Connected Component, the algorithm STRONGLY-CONNECTED-COMPONENT(G) is defined as:
- Call DFS(G) to compute finishing times u.f for each vertex u
- Compute G transpose
- Call DFS(G transpose), but in the main loop of DFS, consider the vertices in order of decreasing u.f(as computed in line 1)
- Output the vertices of each tree in the depth-first forest formed in line 3 as a separate strongly connected component
If I change the alogrithm to just using G, without calculating G transpose. Also consider the vertices in order of Increasing u.f(Reverse order of topological sort):
- Call DFS(G) to compute finishing times u.f for each vertex u
- Call DFS(G), but in the main loop of DFS, consider the vertices in order of increasing u.f(as computed in line 1)
- Output the vertices of each tree in the depth-first forest formed in line 2
Why is this algorithm wrong?
The vertices in strongly connected component are, by definiton, connected to each other (by a path, not necessarily by direct edge). if you make first DFS call on vertex X, you find out "which vertices is X connected to" (X -> N). To make sure that all those vertices are connected to X (N -> X) and therefore validate strong connectivity you need to traverse the edges in reversed directions. The easiest way to do such is by transposing the graph.
If you look for proof of the algorithm, i am sure you will find some. It may not be the easiest to understand but check this source for example: Correctness of the algorithm for finding strongly connected components