algorithm - 删除有向图中的重复边

标签 algorithm graph

给定一个有向图,如果两个节点之间存在替代路径,则删除它们之间的边。例如:给定 a->b、b->c、a->c,删除 a->c。是否有一种有效的算法来计算那些被移除的边的数量?

最佳答案

来自维基Strongly connected component :

A directed graph is acyclic if and only if it has no strongly connected subgraphs with more than one vertex, because a directed cycle is strongly connected and every nontrivial strongly connected component contains at least one directed cycle.

您可以使用 Tarjan's strongly connected components algorithm找到SCC。然后从每个组件中删除一条边。

接下来您需要迭代整个过程,因为每个非平凡强连通分量至少包含一个有向环。

一般而言,计算循环数是 NP-hard,因为如果您可以在多项式时间内计算所有循环,那么您也可以检测哈密顿循环的存在。但是Hamiltonian path是 NP 难的。

关于algorithm - 删除有向图中的重复边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50658506/

相关文章:

javascript - flotchart,禁用图形刻度上的小数点

performance - 嵌套循环的大 O 运行时间?

python - 检查一个线段是否与一组线段相交

algorithm - 启发式和 A* 算法

c - 合并插入排序如何工作?

java - 为深度优先搜索生成状态

algorithm - 哈密​​顿循环的归约算法

python - graph-tool - 从 pandas dataframe 中读取边列表

javascript - 从 1 个列表生成 2 种组合的算法

c++ - 创建具有正确边的无向图