0

I was recently trying to come up with the total number of hamiltonian paths (basically starting for start vertex, visit each node exaactly once and reach the end vertex). Brute force dfs goes for a long walk on a moderate sized grid of 7x8. I came up with some of these prunning strategies. The goal of these pruning techniques is that a partial path which cannot be a hamiltonian path should not be extended further.

DFS Algorithm: Start for the start vertex, visit its neighbor nodes and recurse. Keep a count of the number of nodes visited and once reaching the end vertex, check if the totla visited nodes is same as the total nodes in the grid. This is going to be exponential complexity as for each vertex you can go in 4 directions, which will be of O(4^n). So focus should be to reject a path as soon as possible and not wait until reaching the end vertex.

Pruning Techniques:

1) For a given partial path, check if the remaining graph is connected. If it is not, then this partial path cannot end up to be a hamiltonian path.

2) For a given partial path, each yet-to-be-visited node must have atleast 2 degree such that one neighbor node could be used to enter this node and other other neighbor is used to exit.

I was wondering how much these pruning techniques could save time. Also am I missing some very improtant pruning techinque because my speed up is not significant.

Thanks in Advance !!!

Amm Sokun
  • 1,298
  • 4
  • 20
  • 35
  • [This question](http://mathoverflow.net/questions/36368/efficient-way-to-count-hamiltonian-paths-in-a-grid-graph-for-a-given-pair-of-vert) on math overflow is almost identical, and there's not much help there. Apparently this problem (or a similar one) is NP-Hard, so it's unlikely there is an algorithm much faster than the one you have there. – smackcrane Jun 17 '11 at 20:55
  • yep this question is NP-Hard and i have seen that post on **MO**, but i was expecting some more activity for this problem as it has many practical applications. A problem being in NP doesn't necessarily make if unsolvable. – Amm Sokun Jun 17 '11 at 21:23

1 Answers1

0

There is an O(n^2 * 2^n) solution that works for general graphs. The structure is identical to the O(2^n * n^2) algorithm described here,

http://www.algorithmist.com/index.php/Traveling_Salesperson_Problem

Except rather than recording minimum distances, you are recording counts.

Any pruning you can do on top of that will still help.

Rob Neuhaus
  • 9,190
  • 3
  • 28
  • 37