How do I learn Tarjan's algorithm?

前端 未结 4 978
名媛妹妹
名媛妹妹 2021-02-13 06:05

I have been trying to learn Tarjan\'s algorithm from Wikipedia for 3 hours now, but I just can\'t make head or tail of it. :(

http://en.wikipedia.org/wiki/Tarjan\'s_stro

4条回答
  •  北海茫月
    2021-02-13 06:19

    just adding to pjotr's answer: v.lowlink is basically the index of the upmost node that you have found in the tree. Keep in mind that upmost in this context means minimum as you keep increasing indices as you walk down. Now after processing all your successors, there's basically three cases:

    1. v.lowlink < v.index: This indicates that you have found a back edge. Note that we haven't just found any back edge, but one that points to a node that is "above" the current one. That's what v.lowlink < v.index implies.

    2. v.lowlink = v.index: What we know in this case is that there is no back edge referring to anything above the current node. There might be a back edge to this node (which means that one of your successor nodes w has a lowlink such that w.lowlink = v.lowlink = v.index). It could also be that there was a back edge referring to something below the current node, which means that there was a strongly-connected component below the current node that has been printed out already. The current node, however, is definitely the root of a strongly-connected component as well.

    3. v.lowlink > v.index: That's actually not possible. I'm just listing it for the sake of completeness. ;)

    Hope it helps!

提交回复
热议问题