Your second step is incomplete. See Wikipedia:
Kosaraju's algorithm works as follows:
- Let G be a directed graph and S be an empty stack.
- While S does not contain all vertices:
- Choose an arbitrary vertex v not in S. Perform a depth-first search starting at v. Each time that depth-first search finishes expanding a vertex u, push u onto S.
- Reverse the directions of all arcs to obtain the transpose graph.
- While S is nonempty:
- Pop the top vertex v from S. Perform a depth-first search starting at v in the transpose graph. The set of visited vertices will give the strongly connected component containing v; record this and remove all these vertices from the graph G and the stack S. Equivalently, breadth-first search (BFS) can be used instead of depth-first search.
So you shouldn't only do something with the last vertex and first vertices, but with each vertex in the DFS.
Also note that you should be backtracking - when you can't go further, you go to the previous vertex and continue from there.
And no, you can't treat it as an undirected graph - the direction of the edges matter significantly.
So, starting from E
, you'd, for example, go F
, then G
, then back to F
, then H
, then K
, then I
, then J
, then back to I
, K
, H
, F
, and finally E
, having pushed all visited vertices onto the stack.