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

1

9

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.

Hellen answered 8/8, 2015 at 17:39 Comment(3)
Tarjan came up with tons of elegant algorithms. I hope you don't mind my edit.Geniality
Oh absolutely not. Sorry for not specifying it in the first place. Thanks.Hellen
Read my answer herePatroclus
W
5

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.)

Wickman answered 8/8, 2015 at 18:10 Comment(1)
OMG thank you! I was cracking my head trying to figure out why it wouldn't work. Good to know it does work!Penninite

© 2022 - 2024 — McMap. All rights reserved.