0

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 Algorithm:

In Kosaraju's algorithm, I find the following SCCs:

SCC: {0, 1, 2, 3} Kosaraju's algorithm identifies one SCC that includes all four vertices.

Tarjan's Algorithm:

In Tarjan's algorithm, I find the following SCCs:

SCC: {0, 1, 2} SCC: {3} Tarjan's algorithm identifies two SCCs: one containing vertices {0, 1, 2} and the other containing vertex {3}.

Can anyone explain why we have two different result and what will be the SCC for the graph?

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
  • We would need to see your implementation of Tarjan's algorithm. Because, by hand, no doubt: result of Tarjan's algorithm is a single component {0,1,2,3}. – chrslg Aug 15 '23 at 13:48
  • Is your graph directed or undirected? – ravenspoint Aug 15 '23 at 13:56
  • @ravenspoint AFAIK, "strongly connected component" make no sense in an undirected graph. That is a directed graph notion. And finding connected component (which is what would be a strongly connected component in an undirected graph, following the habit to consider undirected edges as two ways edges) in an undirected graph can be done with way easier algorithm than Kosaraju or Tarjan (just explore from any edge, and mark everything accessible as component 1. And when finish, restart from any unmarked remaining vertex for component 2, etc.) – chrslg Aug 15 '23 at 17:24
  • @chrslg You have things backwards. See https://stackoverflow.com/a/76935526/16582 – ravenspoint Aug 19 '23 at 14:15

1 Answers1

0

Whichever, directed or undirected, your graph is a single strongly connected component.

So, either there is a bug in your implementation of Tarjan, or you are trying to apply Tarjan to an directed graph, which will not work.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103