How do I learn Tarjan's algorithm?

前端 未结 4 1421
遇见更好的自我
遇见更好的自我 2021-02-13 05:36

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

    Some Intuition about the Tarjan's Algorithm:

    • During DFS, when we encounter a back edge from vertex v, we update its lowest reachable ancestor i.e. we update the value of low[v]

    • Now when the all the outgoing edges of a vertex are processed i.e we are about to exit the DFS call for the vertex v, we check the value of low[v], whether low[v] == v (Explanation below). If not this means v is not the root of the SCC and we now give the benefit to the parent of v i.e. the lowest reachable ancestor of parent[v] is now changed to low[v].

    This sounds logical as if although there is no direct back edge from the parent[v] to the ancestor of v, but there is a path (back edge of v + edge towards v) via which the parent[v] can still reach the ancestor of v. Thus we have also updated the low[parent[v]] here. Therefore, we will keep on updating this chain and low[v] for all v will keep on updating until, we reach to the ancestor (via backtracking). For this ancestor low[v] will be equal to v. And thus this will act as the root of the SCC.

    Hope this helps

提交回复
热议问题