Linear time algorithm to find the strongly connected components of a directed graph
Questions tagged [kosaraju-algorithm]
24 questions
6
votes
3 answers
Why do we need to run DFS on the complement of a graph in the Kosaraju's algorithm?
There's a famous algorithm to find the strongly connected components called Kosaraju's algorithm, which uses two DFS's to solve this problem, and runs in θ(|V| + |E|) time.
First we use DFS on complement of the graph (GR) to compute reverse…

Atinesh
- 1,790
- 9
- 36
- 57
3
votes
1 answer
why does kosaraju algorithm works and what is the idea behind it and is this a correct implementation?
why do we create a transpose of the graph and then run dfs on the transpose in the second pass.I've tried reading proof of correctness http://www.jeffreykarres.com/blog/kosaraju/ online but couldn't understand is there some alternative approach to…

anuragtiwari691
- 33
- 5
3
votes
0 answers
How can I get rid of this stack overflow problem in python for Kosaraju's algorithm?
I'm a new programmer, and I'm working through Stanford's algorithms course on edX.
One of the programming assignments is to find strongly connected components using Kosaraju's algorithm, on a graph with ~1,000,000 vertices. My implementation is the…

Adam Tolnay
- 139
- 2
3
votes
1 answer
Kosaraju’s algorithm for scc
Can anyone explain me the logic behind Kosaraju’s algorithm for finding connected component?
I have read the description, though I can't understand how the DFS on reversed graph can detect the number of strongly connected components.
def…

Daniel Chepenko
- 2,229
- 7
- 30
- 56
3
votes
3 answers
Tail Recursion in F# : Stack Overflow
I'm trying to implement Kosaraju's algorithm on a large graph
as part of an assignment [MOOC Algo I Stanford on Coursera]
https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm
The current code works on a small graph, but I'm hitting Stack Overflow…

Fagui Curtain
- 1,867
- 2
- 19
- 34
3
votes
1 answer
Non recursive Kosaraju's two pass algorithm implementation taking forever to execute on a large data set
I coded this for an assignment which has passed its deadline.
This implementation works completely fine with various smaller test cases and displays the sizes of the 5 largest Strongly Connected Components in the graph as it should.
But seems to…

Tauseef
- 55
- 10
2
votes
1 answer
Kosaraju's Algorithm for SCCs, non-recursive
I have an implementation of Kosaraju's algorithm for finding SCCs in Python. The code below contains a recursive (fine on the small test cases) version and a non-recursive one (which I ultimately need because of the size of the real dataset).
I have…

ceik
- 33
- 5
1
vote
0 answers
Kattis problem Dominos, run time error on the final testcase, am i missing something obvious or an edge case?
I have spent a lot of time on the problem Dominos from kattis, see here: https://open.kattis.com/problems/dominos.
I am passing 3 testcases and on the final one I receive a runtime error. I suspect some out of bond errors might occur, but I really…

NeoFraMatrix
- 13
- 3
1
vote
1 answer
Kosaraju algorithm - computing SCCs
For a given directed graph G I need to compute its strongly connected components (SCCs) using Kosaraju's algorithm. As far as I've understood the steps of the algorithm are as follows:
Let Grev = G wit all arcs reversed
Run DFS (Depth-First Search)…

lukaabra
- 83
- 1
- 10
1
vote
0 answers
Size (number of edges) of strongly connected components (SCC) in a graph using Kosaraju's algorithm
I have coded up Kosaraju's two-pass algorithm in Python 3, the current implementation finds SCCs and determines the size of each SCC based on the number of nodes in each SCC. Then, the largest SCCs are determined. How can I change the code so it can…

saj
- 11
- 3
1
vote
1 answer
Iterative DFS on graph with post-visit ordering
I'm currently trying to implement the Kosaraju's algorithm on directed graph to find all strongly connected components.
I understand quite well how this algorithm works, but I have some issues when getting the post-visit order of the DFS result.
For…

valkorai
- 40
- 6
1
vote
2 answers
Can the finishing times for Kosaraju's algorithm be generated from the original graph, not the reverse graph?
In Kosaraju's algorithm, finishing times are generated from the reversed graph. Then, the strongly connected components are discovered from the original graph by performing DFS, starting from the greatest to the lowest finishing times generated…

tingting
- 11
- 1
0
votes
1 answer
Strongly connected component for the graph is giving different result for Kosaraju's Algorithm and Tarjan's Algorithm
I am learning graph concept and got to the graph which is giving result for finding strong connected component with Kosaraju's Algorithm and Tarjan's Algorithm.
Graph:
V = 4
The graph's edges are:
(0, 1)
(1, 2)
(2, 0)
(1, 3)
(3, 2)
Kosaraju's…

Abhishek kumar
- 1
- 1
0
votes
1 answer
How to break down Strongly Connected Components (SCC) in a graph to obtain smaller and smaller nested cycles in JavaScript?
So I have been wondering about how to convert complex graphs with nested cycles into simple Directed Acyclic Graphs (DAGs). I think I landed on the solution (not 100% sure). The solution is to use Kosaraju's algorithm, which I have borrowed from…

Lance
- 75,200
- 93
- 289
- 503
0
votes
1 answer
Implementing Kosaraju's Algorithm for SCC's
I am trying to implement Kosaraju's algorithm to find strongly connected components of a directed graph in linear time. The goal is to store and output the list of SCC sizes.
class Graph:
def __init__(self, edge_list, num_nodes):
self.graph =…

Magus-Maxime
- 3
- 1