FindHamiltonianCycle
FindHamiltonianCycle[g]
attempts to find a Hamiltonian cycle.
Details and Options
- FindHamiltonianCycle functionality is now available in the built-in Wolfram Language function FindHamiltonianCycle.
- To use FindHamiltonianCycle, you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
- FindHamiltonianCycle[g] returns an empty list if no Hamiltonian cycle is found.
- FindHamiltonianCycle considers the input graph as undirected.
- FindHamiltonianCycle uses heuristic algorithms to find a Hamiltonian cycle; therefore, there is no guarantee that a Hamiltonian cycle will be found even if one exists.
Examples
open allclose allBasic Examples (2)Summary of the most common use cases

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-byy0c
This defines a small graph and finds a Hamiltonian cycle of the graph:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-lmzedk

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-finxt2


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-joq4a6

This function has been superseded by FindHamiltonianCycle in the Wolfram System:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-qs9cop


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-s1us5t

Options (2)Common values & functionality for each option
MaxIterations (1)

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-d5urw
This limits the maximum number of iterations to try to find a Hamiltonian cycle:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-yo7g01


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-orgpti


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-karyko
RandomSeed (1)

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-9243h
This specifies a random seed different from the default to try to find a Hamiltonian cycle:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-x204sn


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-z026u6

Applications (1)Sample problems that can be solved with this function
This finds all possible Hamiltonian cycles in the graph consisting of bordering countries in South America:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-tio52j

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-6d3gmj

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-s6pel

This shows the first of these two cycles; the second is just a reversal of the first:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-hhyghm

Properties & Relations (1)Properties of the function, and connections to other functions
FindHamiltonianCycle uses heuristic algorithms. Unlike HamiltonianCycles, it is not guaranteed to find a Hamiltonian cycle even when one exists. But for large graphs, FindHamiltonianCycle can sometimes be faster at finding one cycle.
This defines a graph of 500 vertices, and uses these two functions to find a Hamiltonian cycle:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-qdtybq

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-zw5xnc


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-yjrcq0

Possible Issues (1)Common pitfalls and unexpected behavior
FindHamiltonianCycle uses heuristic algorithms, which are not guaranteed to find a Hamiltonian cycle even when one exists:

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-zxq64f

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-od59ay

https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-g5tm4w


https://wolfram.com/xid/0ye753hcr6n0hpe2iquhq-7aaigl

Wolfram Research (2007), FindHamiltonianCycle, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html.
Text
Wolfram Research (2007), FindHamiltonianCycle, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html.
Wolfram Research (2007), FindHamiltonianCycle, Wolfram Language function, https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html.
CMS
Wolfram Language. 2007. "FindHamiltonianCycle." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html.
Wolfram Language. 2007. "FindHamiltonianCycle." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html.
APA
Wolfram Language. (2007). FindHamiltonianCycle. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html
Wolfram Language. (2007). FindHamiltonianCycle. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html
BibTeX
@misc{reference.wolfram_2025_findhamiltoniancycle, author="Wolfram Research", title="{FindHamiltonianCycle}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html}", note=[Accessed: 09-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_findhamiltoniancycle, organization={Wolfram Research}, title={FindHamiltonianCycle}, year={2007}, url={https://reference.wolfram.com/language/GraphUtilities/ref/FindHamiltonianCycle.html}, note=[Accessed: 09-July-2025
]}