algorithm - 如果在计算强连通分量时不使用 G 转置怎么办?

标签 algorithm data-structures graph-theory depth-first-search directed-graph

我正在阅读算法导论。 22.5 Strongly Connected Component中,算法STRONGLY-CONNECTED-COMPONENT(G)定义为:

  1. 调用 DFS(G) 计算每个顶点 u 的完成时间 u.f
  2. 计算G转置
  3. 调用 DFS(G 转置),但在 DFS 的主循环中,考虑按 u.f 递减顺序排列的顶点(如第 1 行中计算的那样)
  4. 将第3行形成的深度优先森林中每棵树的顶点作为单独的强连通分量输出

如果我将算法更改为仅使用 G,而不计算 G 转置。还要考虑按递增 u.f 顺序排列的顶点(拓扑排序的逆序):

  1. 调用 DFS(G) 计算每个顶点 u 的完成时间 u.f
  2. 调用 DFS(G),但在 DFS 的主循环中,按照 u.f 递增的顺序考虑顶点(如第 1 行中计算的那样)
  3. 输出第2行形成的深度优先森林中每棵树的顶点

为什么这个算法错了?

最佳答案

你的问题其实是书上的习题22.5-3。此处给出了替代算法正确性的反例: http://sites.math.rutgers.edu/~ajl213/CLRS/Ch22.pdf

Professor Bacon’s suggestion doesn’t work out. As an example, suppose that our graph is on the three vertices {1, 2, 3} and consists of the edges (2, 1),(2, 3),(3, 2). Then, we should end up with {2, 3} and {1} as our SCC’s. However, a possible DFS starting at 2 could explore 3 before 1, this would mean that the finish time of 3 is lower than of 1 and 2. This means that when we first perform the DFS starting at 3. However, a DFS starting at 3 will be able to reach all other vertices. This means that the algorithm would return that the entire graph is a single SCC, even though this is clearly not the case since there is neither a path from 1 to 2 of from 1 to 3.

关于algorithm - 如果在计算强连通分量时不使用 G 转置怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27086778/

相关文章:

algorithm - 从一组有限的图 block 中找到最大的平方(近似值)

graph-theory - 最大和最大集团

python - 使用 Levenshtein 距离作为 Python 中的启发式算法生成字符串的爬山算法?

javascript - 检查用户是否分配给特定插槽

java - 对回溯步骤历史的算法的建议?

c++ - 使用命令行参数选择数据类型?

python :How to generate a power law graph

python - 关于karatsuba乘法的问题

algorithm - 冒泡排序算法题

python - 在 Python 中实现 Trie