GraphTheory
IsHamiltonian
test if graph is Hamiltonian
Calling Sequence
Parameters
Options
Description
Hamiltonian graphs in SpecialGraphs
Examples
Compatibility
IsHamiltonian(G, opt)
IsHamiltonian(G, C, opt)
G
-
unweighted graph
C
(optional) name
opt
(optional) equation of the form method = value; specify method to use
method=one of legacy, sat, or tsp.
Specifies the algorithm to use in seeking a Hamiltionian circuit. The default, method=legacy, uses a simple depth-first search to find a Hamiltonian circuit. The sat method encodes the problem as a logical formula and seeks a satisfying solution, and the tsp method seeks to find a Hamiltonian circuit which is an optimal solution to the traveling salesman problem.
A graph G on n vertices is Hamiltonian if there exists a Hamiltonian circuit, that is, a cycle in G containing each of the n vertices exactly once.
The IsHamiltonian(G) function returns true if the graph is Hamiltonian and false otherwise. If G is Hamiltonian and a name C is specified as a second argument, then C is assigned a list of vertices of a Hamiltonian cycle of the graph starting and ending with the first vertex in G. For example, if the graph G is the triangle graph created with Graph({{1,2},{1,3},{2,3}}), the cycle is output as 1,2,3,1.
The algorithm works for directed graphs and it ignores the edge weights of weighted graphs.
The algorithm first checks whether G is disconnected or whether it has any articulation points. If so, then G is not Hamiltonian. Then it tests whether the minimum degree of G is at least n2 where n is the number of vertices. If so G is Hamiltonian. Then, if G is not too sparse, the algorithm checks whether the independence number of G is greater than n2. If so, then G is not Hamiltonian. Failing these checks, the default algorithm does a simple exhaustive search for a Hamiltonian cycle using depth-first-search. By setting infolevel[IsHamiltonian] to an integer greater than 1 a message will be displayed stating how the graph was proven, or disproven, to be Hamiltonian.
An example of a graph which is Hamiltonian for which it will take exponential time to find a Hamiltonian cycle is the hypercube in d dimensions which has n=2d vertices and m=d⁢2d−1 edges. The algorithm has no difficulty in finding a Hamiltonian cycle for d=5 where n=32 and m=80 but for d=6, n=64, and m=192 it takes a long time.
The following are graphs in the SpecialGraphs subpackage which are Hamiltonian..
Graph
Number of Vertices
Number of Edges
House graph
5
6
Golomb graph
10
18
Groetzsch graph
11
20
Frucht graph
12
Franklin graph
BidiakisCube
Chvatal graph
24
Heawood graph
14
21
Poussin graph
15
39
Moebius-Kantor graph
16
Hoffman graph
32
Shrikhande graph
48
Pappus graph
27
Robertson graph
19
38
Desargues graph
30
Kittell graph
23
63
Nauru graph
36
McGee graph
Schläfli graph
216
Foster cage graph
75
Dyck graph
Wells graph
80
Sylvester graph
90
Hoffman-Singleton graph
50
175
Harborth graph
52
104
Gewirtz graph
56
280
Perkel graph
57
171
Soccer ball graph
60
Balaban 10-cage graph
70
105
M22 graph
77
616
Brouwer-Haemers graph
81
810
Foster graph
135
Higman-Sims graph
100
1100
Hall-Janko graph
1800
Biggs-Smith graph
102
153
Balaban 11-cage graph
112
168
McLaughlin graph
275
15400
with⁡GraphTheory:
with⁡SpecialGraphs:
P≔PetersenGraph⁡
P≔Graph 1: an undirected graph with 10 vertices and 15 edge(s)
IsHamiltonian⁡P
false
AddEdge⁡P,1,3
Graph 1: an undirected graph with 10 vertices and 16 edge(s)
IsHamiltonian⁡P,C
true
1,2,9,8,5,4,10,6,7,3,1
DrawGraph⁡P
H3≔HypercubeGraph⁡3
H3≔Graph 2: an undirected graph with 8 vertices and 12 edge(s)
IsHamiltonian⁡H3,C
000,100,110,010,011,111,101,001,000
HighlightTrail⁡H3,C,red
DrawGraph⁡H3
infolevelIsHamiltonian≔2
IsHamiltonian⁡H3
K33≔CompleteGraph⁡3,3
K33≔Graph 3: an undirected graph with 6 vertices and 9 edge(s)
IsHamiltonian⁡K33
IsHamiltonian: "graph satisfies MinimumDegree(G) >= NumberOfVertices(G)/2 ==> it is hamiltonian"
K34≔CompleteGraph⁡3,4
K34≔Graph 4: an undirected graph with 7 vertices and 12 edge(s)
IsHamiltonian⁡K34
IsHamiltonian: "graph satisfies IndependenceNumber(G) > NumberOfVertices(G)/2 ==> it's not hamiltonian"
The GraphTheory[IsHamiltonian] command was updated in Maple 2019.
The method option was introduced in Maple 2019.
For more information on Maple 2019 changes, see Updates in Maple 2019.
See Also
DrawGraph
HighlightTrail
IsEulerian
SpecialGraphs[HypercubeGraph]
TravelingSalesman
Download Help Document