有向图最著名的传递闭包算法是什么?
就运行时间而言,最著名的有向图传递闭包算法是什么?
我目前正在使用 Warshall 算法,但它的时间复杂度为 O(n^3)。尽管如此,由于图形表示,我的实现效果稍好一些(不是检查所有边,而是只检查所有外出边)。有没有比这更好的传递闭包算法?特别是,有没有专门针对共享内存多线程架构的东西?
In terms of runtime, what is the best known transitive closure algorithm for directed graphs?
I am currently using Warshall's algorithm but its O(n^3). Although, due to the graph representation my implementation does slightly better (instead of checking all edges, it only checks all out going edges). Is there any transitive closure algorithm which is better than this? In particular, is there anything specifically for shared memory multi-threaded architectures?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
本文讨论了各种传递闭包算法的性能:
http://www.vldb.org/ conf/1988/P382.PDF
论文中一个有趣的想法是避免在图形变化时重新计算整个闭包。
还有 Esko Nuutila 的这个页面,其中列出了一些最新的算法:
http: //www.cs.hut.fi/~enu/tc.html
该页面上列出的他的博士论文可能是最好的起点:
http://www.cs.hut.fi/~enu/thesis.html
从该页面:
This paper discusses the performance of various transitive closure algorithms:
http://www.vldb.org/conf/1988/P382.PDF
One interesting idea from the paper is to avoid recomputing the entire closure as the graph changes.
There is also this page by Esko Nuutila, which lists a couple of more recent algorithms:
http://www.cs.hut.fi/~enu/tc.html
His PhD thesis listed on that page may be the best place to start:
http://www.cs.hut.fi/~enu/thesis.html
From that page:
算法设计手册有一些有用的信息。要点:
The Algorithm Design manual has some useful information. Key points:
令人惊讶的是,我无法找到
STACK_TC
算法的任何实现 由 Esko Nuutila 描述(由 AmigoNico 在另一个答案中链接)。所以我用 C++ 编写了自己的简单实现。它与原始算法略有不同,请参阅代码中的注释以获取解释。
它成功地通过了我尝试过的一些测试,但鼓励读者进行更多测试,并根据原始论文进行验证。该代码可能未优化。
我的测试用例(来自同一篇论文):
输入:(邻接矩阵,Y是边源,X是边目的地)
输出:
输入:
输出:
Surprisingly I was unable to find any implementations of the
STACK_TC
algorithm described by Esko Nuutila (linked by AmigoNico in the other answer).So I wrote my own simple implementation, in C++. It differs slightly from the original algorithm, see comments in the code for explanation.
It successfully passes a few tests I tried, but readers are encouraged to test it more, and to verify it against the original paper. The code is probably underoptimized.
My test-cases (from the same paper):
Input: (adjacency matrix, Y is edge source, X is edge destination)
Output:
Input:
Output: