在图中查找哈密顿循环的动态规划算法是什么?

发布于 2024-08-04 11:14:14 字数 61 浏览 3 评论 0原文

在无向图中查找哈密顿循环的动态规划算法是什么? 我在某处看到存在一种时间复杂度为 O(n.2^n) 的算法。

What is dynamic programming algorithm for finding a Hamiltonian cycle in an undirected graph?
I have seen somewhere that there exists an algorithm with O(n.2^n) time complexity.

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

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

发布评论

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

评论(2

陌伤浅笑 2024-08-11 11:14:14

确实存在一种用于查找哈密顿循环的 O(n2n) 动态规划算法。这个想法是一个通用的想法,可以将许多 O(n!) 回溯方法减少到 O(n22n) 或 O(n2n< /sup>)(以使用更多内存为代价),是考虑具有指定“端点”的子问题。

在这里,由于您想要一个循环,因此可以从任何顶点开始。因此修复一个,将其命名为x。子问题是:“对于给定的集合 SS 中的顶点 v,是否存在从 x< 开始的路径/code> 并遍历 S 的所有顶点,以 v 结束?”称之为poss[S][v]

与大多数动态规划问题一样,一旦定义了子问题,剩下的事情就很明显了:以任何“递增”顺序循环遍历所有 2n 组 S 的顶点,并且对于每个这样的 S 中的每个 v,您可以将 poss[S][v] 计算为:

poss[S][v] =(S 中存在一些u,使得 poss[S−{v}][u] 为 True,并且边 u-> v 存在)

最后,存在一个哈密顿环 iff 存在一个顶点 v 使得边 v->x 存在且 poss[S][ v] 为 True,其中 S 是所有顶点的集合(x 除外,具体取决于您的定义方式)。

如果您想要实际的哈密顿循环而不是仅仅决定是否存在,请使 poss[S][v] 存储使其成为可能的实际 u 而不仅仅是真或假;这样你就可以在最后追溯一条路径。

There is indeed an O(n2n) dynamic-programming algorithm for finding Hamiltonian cycles. The idea, which is a general one that can reduce many O(n!) backtracking approaches to O(n22n) or O(n2n) (at the cost of using more memory), is to consider subproblems that are sets with specified "endpoints".

Here, since you want a cycle, you can start at any vertex. So fix one, call it x. The subproblems would be: “For a given set S and a vertex v in S, is there a path starting at x and going through all the vertices of S, ending at v?” Call this, say, poss[S][v].

As with most dynamic programming problems, once you define the subproblems the rest is obvious: Loop over all the 2n sets S of vertices in any "increasing" order, and for each v in each such S, you can compute poss[S][v] as:

poss[S][v] = (there exists some u in S such that poss[S−{v}][u] is True and an edge u->v exists)

Finally, there is a Hamiltonian cycle iff there is a vertex v such that an edge v->x exists and poss[S][v] is True, where S is the set of all vertices (other than x, depending on how you defined it).

If you want the actual Hamiltonian cycle instead of just deciding whether one exists or not, make poss[S][v] store the actual u that made it possible instead of just True or False; that way you can trace back a path at the end.

北音执念 2024-08-11 11:14:14

我无法找出该特定算法,但是 汉密尔顿页面比您可能需要的更多。 :)

此页面旨在成为
论文的综合清单,
源代码、预印本、技术
报告等,可在
关于哈密顿循环的互联网
以及哈密顿路径问题
以及一些相关的问题。

(原始网址,当前为 404), (互联网档案)

I can't pluck out that particular algorithm, but there is more about Hamiltonian Cycles on The Hamiltonian Page than you will likely ever need. :)

This page intends to be a
comprehensive listing of papers,
source code, preprints, technical
reports, etc, available on the
Internet about the Hamiltonian Cycle
and Hamiltonian Path Problems as well
as some associated problems.

(original URL, currently 404), (Internet Archive)

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