We simple need to do either BFS or DFS starting from every unvisited vertex, and we get all strongly connected components. Below are steps based on DFS.
Pseudocode:
- Initialize all vertices as not visited.
- Do following for every vertex 'v'. (a) If 'v' is not visited before, call DFSUtil(v) (b) Print new line character
DFSUtil(v)
- Mark 'v' as visited.
- Print 'v'
- Do following for every adjacent 'u' of 'v'. If 'u' is not visited, then recursively call DFSUtil(u)