# constraints to the hamiltonian path: can one tell if a path is hamiltonian by looking at it?

A few days ago, the channel Numberphile released this video on the square-sum problem. The show later released this follow-up video on how they proved that every number from 25 to 91 can have themselves and all the preceding numbers be ordered so the sum of any two adjacent numbers add up to a square. (confused? check out the video!) Anyway, I wanted to see if I could get, say $100$ somehow, but the lines linking the numbers on a graph are way too complex for me to tell where a line goes. So I'm doing it the hard way...

First, I made a table from $1-100$ dictating what numbers would be added to said number to get a square number, like $100$ or $4$. To keep this question short, I have the first 12 rows...

$$\begin{matrix} \text{number}&4&9&16&25&36&49&64&81&100&\cdots\\ -&-&-&-&-&-&-&-&-&-&-\\ 1&3&8&15&24&35&48&63&80&99&\cdots\\ 2&\varnothing&7&14&23&34&47&62&79&98&\cdots\\ 3&\color{red}{1}&6&13&22&33&46&61&78&97&\cdots\\ 4&\varnothing&5&12&21&32&45&60&77&96&\cdots\\ 5&\varnothing&\color{red}{4}&11&20&31&44&59&76&95&\cdots\\ 6&\varnothing&\color{red}{3}&10&19&30&43&58&75&94&\cdots\\ 7&\varnothing&\color{red}{2}&9&18&29&42&57&74&93&\cdots\\ 8&\varnothing&\color{red}{1}&\varnothing&17&28&41&56&73&92&\cdots\\ 9&\varnothing&\varnothing&\color{red}{7}&16&27&40&55&72&91&\cdots\\ 10&\varnothing&\varnothing&\color{red}{6}&15&26&39&54&71&90&\cdots\\ 11&\varnothing&\varnothing&\color{red}{5}&14&25&38&53&70&89&\cdots\\ 12&\varnothing&\varnothing&\color{red}{4}&13&24&37&52&69&88&\cdots\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\ddots\\ \end{matrix}$$

Anyway, i did some more math and calculated the number of times that each number from $1-100$ can be added to another number between $1-100$ and made this list. (if i used this method on this question it'd be more user-friendly...)

$$\begin{matrix} \text{number of times}&\text{numbers}\\ 1&\varnothing\\ 2&\varnothing\\ 3&\varnothing\\ 4&64&65&66&67&68&81&82&83&84&85&86&87&88&89&90&91&92&93&94&95&\\ 5&37&38&39&40&41&42&43&49&50&51&52&53&54&55&56&57&58&59&60&61&62&63&69&70&71&72&73&74&75&76&77&78&79&80\\ 6&16&17&18&19&20&26&27&28&29&30&31&32&33&34&35&36&44&45&46&47&48\\ 7&9&10&11&12&13&14&15&21&22&23&24&25\\ 8&2&4&5&6&7&8\\ 9&1&3\\ \end{matrix}$$ (this is only logging the first 100 numbers) Because of how long this is taking to write, i think someone has already done this. but here's where it leads to hamiltonian: a "cross every edge" graph has one requirement: have either two or zero odd vertex. but i don't know any hamiltonian graph requirements: is there a way to tell if a graph is or isn't hamiltonian by looking at it? does anyone know if $100$ would work? Thanks in advance.

Hamiltonian paths are hard. That is why they are interesting.

You mention "cross every edge" graphs (the formal name is Eulerian) have the requirement that there are only two or zero odd degree vertices (the degree of a vertex is the number of edges incident to a vertex, what you're calling the "number of times" a number can be added to another to sum to a square). This requirement is actually sufficient as well: every graph with only two or zero odd degree vertices will be Eulerian. Even more, one of the proofs of this fact gives an algorithm for finding the walk that crosses every edge in any such graph, and this algorithm is relatively fast.

But for Hamiltonian paths, no simple characterization (like some condition on the degrees) is known. In fact, any algorithm that you could come up with to find Hamiltonian paths would be pretty slow (technically, I mean that the problem of determining if a general graph has a Hamiltonian path is NP-complete). For this reason, mathematicians have turned to necessary conditions and sufficient conditions for Hamiltonian paths. These are what might allow you to determine if a graph has a Hamiltonian path "by looking at it":

Necessary Conditions: these are conditions that all graphs that have Hamiltonian paths satisfy. For instance, connectedness (there has to be a way to get from any vertex to any other vertex) is a necessary condition. You can think of these conditions as barriers: if a graph doesn't satisfy this condition, then it definitely doesn't have a Hamiltonian path. These will give you quick negative answers.

Sufficient Conditions: these are conditions that, when satisfied, guarantee the graph to have a Hamiltonian cycle. For instance, a famous theorem of Dirac says that if a graph has $n$ vertices and the degree of each vertex is at least $\frac{n}{2}$, then the graph is Hamiltonain. These are usually relatively strong conditions, so there will definitely be graphs that have Hamiltonian cycles that do not satisfy these conditions. However, when satisfied, these conditions will give you quick positive answers.

The holy grail would be to find a condition that is both necessary and sufficient, but as that is unlikely, it is (more or less) the subject of research to close the gap between these two types of conditions.

Side note: there are a whole bunch of structures like Hamiltonian paths that researchers are interested in necessary and sufficient conditions for. Most notably hard problems are Hamiltonian cycles, clique tilings, cycle covers, and so on. The conditions and their proofs start to get much more complicated, so there's not much more I can say without going into more gory details.

So what about this square-sum problem? It doesn't seem like anyone has a good idea. These graphs seem like they have too few edges to be able to use the various sufficient conditions we have, but there is also no obvious reason they don't violate the necessary conditions we have, so we are kind of stuck in the middle. We would have to use more information about how the graph is constructed, i.e. number theory, to solve this problem. I know the problem has been verified up to 299, and my suspicion is that for large enough $n$ (number of vertices), these graphs do have Hamiltonian cycles. (Proofs might only work for very large $n$ though.)

TL;DR: if you want to find a Hamiltonian path in the graph you have, there are some slow algorithms out there, or you could just look for it yourself and get lucky (since it seems these graphs have several Hamiltonian paths). If you're looking for conditions about the graph that would help, you're more than likely out of luck!

• I should've seen this coming, there being a tag for Hamiltonian paths. – Alexander Day Jan 17 '18 at 20:31
• You could've also seen it coming because someone hasn't already answered it before. But that's what makes it exiting! Any contribution helps. – Bob Krueger Jan 17 '18 at 20:49