遍历给定大小的所有树

发布于 2024-10-17 17:32:43 字数 179 浏览 5 评论 0原文

我经常面临通过强力检查给定大小的树(图形树)的某些属性的问题。你有什么好的技巧吗?理想情况下,我只想检查每个同构类一次(但毕竟,速度才是最重要的)。

位旋转技巧是最受欢迎的,因为 n 通常小于 32 :)

我要求比“循环遍历所有 (n-1) 边子集并检查它们是否形成树”之类的树稍微更精细的算法在 n 个节点上。

I am often faced with the problem of checking some property of trees (the graph ones) of a given size by brute force. Do you have any nice tricks for doing this? Ideally, I'd like to examine each isomorphism class only once (but after all, speed is all that matters).

Bit twiddling tricks are most welcome since n is usually less than 32 :)

I'm asking for slightly more refined algorithms than the likes of "loop through all (n-1)-edge subsets and check if they form a tree" for trees on n nodes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪也成诗 2024-10-24 17:32:43

这是高德纳 (Knuth) 的《计算机编程艺术》一书中有关组合算法的内容。如果我没记错的话,那是一个练习。既然他有解决方案,我就向你指出。

This is in Knuth's The Art of Computer Programming volume on Combinatorial Algorithms. If I remember correctly, it's an exercise there. Since he has the solutions for such, I point you there.

意中人 2024-10-24 17:32:43

一些谷歌搜索出现了以下算法描述:http://www. cs.auckland.ac.nz/compsci720s1c/lectures/mjd/treenotes.pdf。他们采用了枚举有根树的算法来枚举无根树。

显然其他人已经证明这只需要每棵树摊销恒定时间,并且 PDF 显示了一些性能测量来证明这一点。

Some googling turned up the following algorithm description: http://www.cs.auckland.ac.nz/compsci720s1c/lectures/mjd/treenotes.pdf. They adapt an algorithm for enumerating rooted trees to enumerating unrooted trees.

Apparently others have proved that this requires only amortised constant time per tree, and the PDF shows some performance measurements demonstrating this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文