gpt4 book ai didi

algorithm - Kosaraju 算法中的步骤顺序

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:45:55 26 4
gpt4 key购买 nike

<分区>

Wikipedia summary Kosaraju-Sharir 算法的原理如下:

Let G be a directed graph and S be an empty stack.

  • While S does not contain all vertices.
    • Choose an arbitrary vertex v not in S.
    • Perform a depth-first search starting at v. Each time that depth-first search finishes expanding a vertex u, push u onto S.
  • Reverse the directions of all arcs to obtain the transpose graph.
  • While S is nonempty:
    • Pop the top vertex v from S.
    • Perform a depth-first search starting at v in the transpose graph.
    • The set of visited vertices will give the strongly connected component containing v; record this and remove all these vertices from the graph G and the stack S. Equivalently, breadth-first search (BFS) can be used instead of depth-first search.

但在我的教科书 - Sedgewick 的 Algorithms (fourth edition) - 它描述了算法的步骤如下:

  • Given a digraph G, compute the reverse post-order of its reverse digraph. GR
  • Run a standard DFS on G, but consider the unmarked vertices in the order just computed instead of the standard numerial order
  • The set of all vertices...

在最后一步得出的结论是相同的,就像在它前面执行的操作一样——但这些操作似乎是以不同的顺序给出的:维基百科告诉我从对 G 和 进行 DFS 开始然后转置它,在 GR 上做第二个 DFS,而我的教科书建议我从转置开始,在 GR 上做第一个 DFS,然后第二个 G。

我的主要问题是:我的理解是否正确,或者我是否误解了对方的意思?

其次:从直觉上看,这些操作似乎是可传递的,因此这两种“不同的方法”实际上是等价的,并且总是会产生相同的最终结果。我已经在几个有向图上测试了这种直觉,它似乎是正确的 - 但它是吗?

第三:假设是,是否有任何客观原因偏爱其中一个,或者仅仅是偏好问题?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com