5
$\begingroup$

I asked Wolfram Alpha for the number of Hamiltonian cycles on the 24-cell graph. https://www.wolframalpha.com/input?i=number+of+hamiltonian+cycles+on+24-cell+graph

It answers 114.9 billion but doesn't provide any context for the answer: Is there an exact value? If it's estimated, how far off is it and what method is used?

Given the hardness of the Hamiltonian cycle problem, I don't expect there is a practical algorithm for computing this number. Would any expert be able to shed light on where this number comes from?

$\endgroup$
5
  • 1
    $\begingroup$ Good question. Of course "114.9 billion" does not look anything like an exact value. The number is not huge, so it is conceivable to compute the exact value by some bruteforce-ish method, but WolframAlpha's number looks more like an estimate, perhaps from a random sample (based on an incomplete search). This is just a guess. If you have a subscription, can you ask WA for a "step-by-step solution" and does it show anything? $\endgroup$ Commented May 14 at 9:14
  • 3
    $\begingroup$ You can run the code (based on the Held-Karp algorithm) from github.com/JorikJooken/hamiltonian_cycles. It just takes me approximately 2 minutes, and it tells me that the 24-cell graph has a total of 114,869,295,744 Hamiltonian cycles. $\endgroup$ Commented May 14 at 12:15
  • $\begingroup$ Thank you L.C. Zhang for linking to an implementation and giving the exact value. $\endgroup$
    – Etienne
    Commented May 14 at 19:28
  • $\begingroup$ L. C. Zhang's comment could be turned into an answer, since it answers the parts "is there an exact value" and "how far off is it". (The part "what method is used" [by WolframAlpha] remains unanswered and may be impossible to answer without access to their proprietary source.) $\endgroup$ Commented May 15 at 4:07
  • 1
    $\begingroup$ My question is how Wolfram Alpha knows this number? $\endgroup$ Commented May 15 at 5:27

2 Answers 2

5
$\begingroup$

The Held-Karp algorithm for TSP can be modified to count Hamiltonian cycles. The idea is to fix a starting vertex $v \in V$ and inductively count, for every vertex $w \neq v$ and subset $S \subseteq V$ with $v, w \in S$, the number $N(v,w,S)$ of permutations of $S$ which induce a path from $v$ to $w$.

In particular, induct on $|S|$ with a base case of $|S| = 2$, where the number of paths is 1 if $S$ is an edge and 0 otherwise (where $\Gamma(v)$ denotes the neighbourhood of $v$ and the bracket is the Iverson bracket notation):

$$ N(v,w,\{v,w\}) = [w \in \Gamma(v)] $$

and then use the same recurrence as in the Held-Karp algorithm, but taking a sum rather than a minimum:

$$ N(v,w,S) = \sum_{x \in S \setminus \{v, w \}} N(v,x,S \setminus \{w\}) [x \in \Gamma(w)] $$

You can then count the total number of Hamiltonian cycles as the number of Hamiltonian paths that begin at $v$ and end at a vertex $w \in \Gamma(v)$ (as then you can close up that path to form a Hamiltonian cycle):

$$ H = \frac{1}{2} \sum_{w \in \Gamma(v)} N(v,w,V) $$

The leading factor of $\frac{1}{2}$ is to account for the fact that we have counted directed cycles starting at $v$, and each undirected Hamiltonian cycle corresponds to two such directed cycles.


The number of subsets $S \subseteq V$ containing the starting vertex $v$ is $2^{n-1}$, and for each such subset there is an average of $\frac{n-1}{2}$ other vertices $w$, so the total number of values $N(v,w,S)$ that we need to evaluate is $(n-1) 2^{n-2}$.

For $n = 24$ (the graph in which you were interested), that is a total of 96468992 evaluations, which can easily be done on a computer.

$\endgroup$
2
  • $\begingroup$ Thank you for the detailed answer. I didn't realize this size of problem is nowadays solvable by an exhaustive search. $\endgroup$
    – Etienne
    Commented May 14 at 19:27
  • 1
    $\begingroup$ A good rule of thumb is that a billion is a small number, for computers nowadays, but a billion billion is big. $\endgroup$ Commented May 15 at 5:24
5
$\begingroup$

We can run the code from github due to Jorik Jooken. The folder contains an algorithm ("countHamiltonianCyclesHeldKarp") for counting the number of Hamiltonian cycles (based on the Held-Karp algorithm). It supports graph6 format.

It just takes about 2 minutes, and it tells me that the 24-cell graph has a total of 114,869,295,744 Hamiltonian cycles.


The graph6 format of the 24-cell graph comes from Mathematica:

g = GraphData["TwentyFourCellGraph"]; 
ExportString[g, "Graph6"]

WzKWWKB?[@wBsAY@U_QsAJOGUaOUaOJTGAtQ_UIQ@[hSAhQ

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .