# Number of “hamiltonian tours” from upper left to lower left corner of a grid graph?

I got the following as an interview question:

Count the number of tours from the upper left corner to the lower left corner in a grid world where you can move in any manhattan direction. This is the number of Hamiltonian paths from upper left to lower left: a path such that every vertex is visited only once, and (this follows from the first statement) such that each edge is used at most once.

The grid world is a 4x10 matrix (4 rows and 10 columns).

Is it really this hard?

Matrix method for counting Hamiltonian cycles

And:

Number of Hamiltonian Paths from Lower Left to Upper Right

These papers seem dated--94, 97--but are they really asking a question that qualifies for publishing in a combinatorical journal?

Then I ran into this: SO question: number of Hamiltonian paths

And am thinking dynamic programming, or divide and conquer...but it is really not clear how one would go about doing this. Is there a way to solve this problem in reasonable time?

• If it's a non-trivial problem of a combinatorial nature and they make progress on it, then it definitely merits publication in a combinatorics journal. – Yuval Filmus Feb 8 '17 at 19:05

I think a divide and conquer strategy is going to work here. The asymptotic runtime isn't great, but fortunately our graph is of fixed size. Pick some arbitrary node, $v$, and partition the rest of the nodes into two sets. The number of hamiltonian tours is the number of paths that start at the upper left, go through all nodes in the first side of the partition and end at $v$ multiplied by the number of paths that start at $v$, go through every node in the second half and end at the bottom left corner summed over every possible such partition. Recursively do this for each partition.
• There are $2^{n-2}$ ways to partition the remaing vertices once you have arbitrarily selected one, which means that you will create $2^{n-1}$ subproblems. That doesn't fall into the usual paradigm of divide-and-conquer, which seeks to do less work on each division. Or perhaps I misunderstood you proposed solution. – rici Feb 8 '17 at 23:44