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

随声附和 提交于 2021-02-04 18:05:48

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/31896765/tarjans-strongly-connected-components-algorithm-why-index-in-the-back-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!