HamiltonianCycles


gives a list of n Hamiltonian cycles.

HamiltonianCycles[g]
gives a list of one Hamiltonian cycle.

DetailsDetails

  • To use , you first need to load the Graph Utilities Package using Needs["GraphUtilities`"].
  • returns an empty list if no Hamiltonian cycle exists.
  • considers the input graph as undirected.
  • The complexity of the algorithm is such that finding all Hamiltonian cycles for a large graph can take an exponential amount of time.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

In[1]:=
Click for copyable input

This defines a small graph and finds a Hamiltonian cycle of the graph:

In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

This plots the graph and highlights the cycle in red:

In[5]:=
Click for copyable input
Out[5]=

This finds all Hamiltonian cycles:

In[6]:=
Click for copyable input
Out[6]=
New to Mathematica? Find your learning path »
Have a question? Ask support »