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.
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- How to determine +/- sign when calculating diagona
相关文章
- Mercurial Commit Charts / Graphs [closed]
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
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. :)
(original URL, currently 404), (Internet Archive)
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 setS
and a vertexv
inS
, is there a path starting atx
and going through all the vertices ofS
, ending atv
?” 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:Finally, there is a Hamiltonian cycle iff there is a vertex
v
such that an edgev->x
exists andposs[S][v]
is True, whereS
is the set of all vertices (other thanx
, 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 actualu
that made it possible instead of just True or False; that way you can trace back a path at the end.