Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kosaraju Algorithm #353

Open
pshivesh8 opened this issue Oct 18, 2021 · 1 comment
Open

Kosaraju Algorithm #353

pshivesh8 opened this issue Oct 18, 2021 · 1 comment

Comments

@pshivesh8
Copy link

Given a Directed Graph with V vertices (Numbered from 0 to V-1) and E edges, Find the number of strongly connected components in the graph.

  1. Create an empty stack ‘S’ and do a DFS traversal of a graph. In DFS traversal, after calling recursive DFS for adjacent vertices of a vertex, push the vertex to stack. In the above graph, if we start DFS from vertex 0, we get vertices in the stack as 1, 2, 4, 3, 0.
  2. Reverse directions of all arcs to obtain the transpose graph.
  3. One by one pop a vertex from S while S is not empty. Let the popped vertex be ‘v’. Take v as the source and do DFS. The DFS starting from v prints strongly connected component of v. In the above example, we process vertices in order 0, 3, 4, 2, 1 (One by one popped from stack).

Alternatives of this solution are Tarjan's Algorithm and Path-Based Algorithm.

@pshivesh8
Copy link
Author

Please Assign this issue to me as a part of Hacktoberfest'21.
I will solve this in C++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant