Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tarjan's strongly-connected components algorithm - why index in the back edge?

I'm studying Tarjan's algorithm for strongly-connected components and the way it works is clear to me. Anyway there's a line I don't understand:

// Consider successors of v
for each (v, w) in E do
  if (w.index is undefined) then
    // Successor w has not yet been visited; recurse on it
    strongconnect(w)
    v.lowlink  := min(v.lowlink, w.lowlink)
  else if (w.onStack) then
    // Successor w is in stack S and hence in the current SCC
    v.lowlink  := min(v.lowlink, w.index) // *************
  end if
end for

I marked the line with asterisks. Why should we take the discovery index/time of a node when encountering a back-edge

v.lowlink  := min(v.lowlink, w.index)

rather than just grabbing its component value?

v.lowlink  := min(v.lowlink, w.lowlink)

I can't think of a case where this would be a problem.

Can someone enlighten me please? Edit: I suspect this is only a semantic requirement, i.e. lowlink being defined as the earliest ancestor reachable from the node with only one back-edge, but this is just a wild guess.

like image 399
Dean Avatar asked Aug 08 '15 17:08

Dean


People also ask

What does Tarjan's algorithm return?

Tarjan's Algorithm is an efficient graph algorithm to find the strongly connected components in a directed graph in linear time by utilizing Depth First Search traversal of a graph. The key idea used is that nodes of strongly connected component form a subtree in the DFS spanning tree of the graph.

How can the number of strongly connected components of a graph change if a new edge is added?

1) If the new edge connects two vertices that belong to a strongly connected component, the number of strongly connected components will remain the same.

Can strongly connected components overlap?

So we can conclude that the strongly connected components are a partition of the vertex set- every vertex is in some strongly connected component, and if two strongly connected components overlap, they are actually the same.

In what order are the strongly connected components SCCs found?

(a) In what order are the strongly connected components (SCCs) found? Ans: The strongly connected components determined in order are: E, B, A; HGI, CDFJ; The algorithm I have used to find the SCCs is: Step 1: Perform DFS on G and compute [pre(v),post(v)] interval for all v.


1 Answers

The correctness proof goes through if w.lowlink is at least the lowest index reachable from w and at most the lowest index reachable from w using at most one back edge. Component detection just requires us to know if we can "escape" to a lower index.

Probably the reason that it's presented the way that it is is that one can imagine lowlink only being set in post-order, and then your variation wouldn't be well defined. (The Wikipedia pseudocode initializes it in pre-order to index.)

like image 104
David Eisenstat Avatar answered Oct 06 '22 18:10

David Eisenstat