views:

1576

answers:

10

Is there a polynomial time algorithm for finding a Hamiltonian walk in a graph?

My algorithm is N factorial and is really slow.

+2  A: 

It's NP complete. But if you do manage to find a good method, let me know and I'll show you how to get rich.

1800 INFORMATION
+12  A: 

You just asked the million dollar question. Finding a Hamilton path is an NP-complete problem. Some NP-hard problems can be solved in polynomial time using dynamic programming, but (to my knowledge) this is not one of them.

Daniel Spiewak
NP-hard problems have yet to be solved in polynomial time, that is still the million-dollar question. They have be solved in pseudo-polynomial time (see the wikipedia page on Knapsack problem for more details).
hazzen
There are no known polynomial time algorithms for any of the NP-complete problems; if there were just one algorithm for one of the problems, all the other NP-complete problems would be reducible to it in polynomial time. I think what hazzen is referring to is the fact that some problems, such as Knapsack, can be approximated quite well in polynomial time. However, the closer you get to a perfect approximation, the further you get from polynomial.
Jay Conrod
@Daniel: Can you name the problem and describe the algorithm? We are of course interested.
piccolbo
Many NP-complete problems can be solved using dynamic programming. Consider the problem of string alignment (edit distance). O(k^n) with a naive implementation, but O(n^2) using dynamic programming. Generically, any problem which exhibits optimal substructure and overlapping subproblems can be reduced in complexity using memoization, which is what dynamic programming does. Wikipedia has a decent explanation and some examples.
Daniel Spiewak
It's important to note that dynamic programming doesn't really provide an algorithm for solving NP-complete problems in polynomial time, it's just exploiting the structure of a very specific sub-class of problems to throw out redundant work. The technique is *not* applicable to the general class of NP-complete problems. It would be a terrific result if it were. :-)
Daniel Spiewak
+2  A: 

Finding a better algorithm for the shortest is unlikely, as it is NP hard. But there are some heuristics that you could try, and perhaps you might want to consult your lecture notes for those ;) .

For less complexity you could find a short(ish) walk using the greedy algorithm.

David L Morris
+17  A: 
ShreevatsaR
A: 

Depending on just how the graphs you're working with are generated you might be able to get expected polynomial time against a random instance by doing greedy path extension and then a random edge swap when that gets stuck.

This works well against randomly generated relatively sparse graphs guaranteed to have a Hamiltonian walk.

Captain Segfault
Why the downvote? This is a good answer, much better than the "ha ha NP complete" non-answers that don't tell you what you *can* do.
ShreevatsaR
A: 

Hmmm.. this depends on what your definitions are. An hamiltonian path is certainly NP-complete. However, an hamiltonian walk which can visit edges and vertices more than once (yes it's still called hamiltonian so long as you add the walk bit at the end) can be calculated in O(p^2logp) or O(max(c^2plogp, |E|)) so long as your graph meets a certain condition which Dirac first conjectured and the Takamizawa proved. See Takamizawa (1980) "An algorithm for finding a short closed spanning walk in a graph".

Paul

Paul
A: 

http://198.170.104.138/itj/2006/851-859.pdf :P

wlark
A: 

Hmmm. Had a look to the above paper posted by wlark, but it does not prove how efficient it is. The algorithm is not even formally proved. It could be O(anything !)

pbl
A: 

Is there any O(n^5) algorithm available ? I think I have a algo which can run in O(n^5).

Anwar
If you have an O(n^5) algorithm for the general Hamiltonian Walk problem that actually works, publish. You'll be famous.
David Thornley
A: 

My Query: Show that a search problem RHAM for finding a Hamiltonian cycle in the graph G is self-reducible A search problem R is self-reducible if it is Cook-reducible to a decision problem
SR={ x : R(x) ≠ ∅ }