DFS for finding strongly connected components

SCC(G):
	Input: directed graph G = (V,E) in adjacency list
	Output: labeling of V by strongly connected component
		1. Construct G^R
		2. Run DFS on G^R
		3. Order V by decreasing post order number.
		4. Run directed DFS on G using the vertex ordering from before and
		   label the connected components we reach.

Additional property

In addition to labelling the connected components the order we have labelled them is in reverse topological ordering. This is because we always start at the next sink vertex after we have labelled a component.

This takes as we do two runs of a DFS algorithm.

Correctness Proof

Find this in Week 6 - Graph algorithms - strongly connected components.

Example

Suppose we want to find the strongly connected components of the graph below.

First we look at and run the DFS to find path in an undirected graph algorithm.

This gives us - in this example we started at and did a fairly random vertex ordering.

LetterPrePost
A78
B611
C112
D1213
E910
F34
G25
H1718
I1920
J1621
K1522
L1423

Then we order the vertices by reverse post order.

LetterLKJIHDCBEAGF
Post232221201813121110854

Now run a connected components DFS using the vertex ordering above.

LetterLKJIHDCBEAGF
Post232221201813121110854
CC111112344533

Notice also that the strongly connected component graph is the following.

Giving that our ordering is exactly a reverse topological sorting.