IsHamiltonian - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


GraphTheory

  

IsHamiltonian

  

test if graph is Hamiltonian

 

Calling Sequence

Parameters

Options

Description

Hamiltonian graphs in SpecialGraphs

Examples

Compatibility

Calling Sequence

IsHamiltonian(G, opt)

IsHamiltonian(G, C, opt)

Parameters

G

-

unweighted graph

C

-

(optional) name

opt

-

(optional) equation of the form method = value; specify method to use

Options

• 

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.

Description

• 

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=d2d1 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.

Hamiltonian graphs in SpecialGraphs

• 

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

18

Franklin graph

12

18

BidiakisCube

12

18

Chvatal graph

12

24

Heawood graph

14

21

Poussin graph

15

39

Moebius-Kantor graph

16

24

Hoffman graph

16

32

Shrikhande graph

16

48

Pappus graph

18

27

Robertson graph

19

38

Desargues graph

20

30

Kittell graph

23

63

Nauru graph

24

36

McGee graph

24

36

Schläfli graph

27

216

Foster cage graph

30

75

Dyck graph

32

48

Wells graph

32

80

Sylvester graph

36

90

Hoffman-Singleton graph

50

175

Harborth graph

52

104

Gewirtz graph

56

280

Perkel graph

57

171

Soccer ball graph

60

90

Balaban 10-cage graph

70

105

M22 graph

77

616

Brouwer-Haemers graph

81

810

Foster graph

90

135

Higman-Sims graph

100

1100

Hall-Janko graph

100

1800

Biggs-Smith graph

102

153

Balaban 11-cage graph

112

168

McLaughlin graph

275

15400

Examples

withGraphTheory:

withSpecialGraphs:

PPetersenGraph

PGraph 1: an undirected graph with 10 vertices and 15 edge(s)

(1)

IsHamiltonianP

false

(2)

AddEdgeP,1,3

Graph 1: an undirected graph with 10 vertices and 16 edge(s)

(3)

IsHamiltonianP,C

true

(4)

C

1,2,9,8,5,4,10,6,7,3,1

(5)

DrawGraphP

H3HypercubeGraph3

H3Graph 2: an undirected graph with 8 vertices and 12 edge(s)

(6)

IsHamiltonianH3,C

true

(7)

C

000,100,110,010,011,111,101,001,000

(8)

HighlightTrailH3,C,red

DrawGraphH3

infolevelIsHamiltonian2

infolevelIsHamiltonian2

(9)

IsHamiltonianH3

true

(10)

K33CompleteGraph3,3

K33Graph 3: an undirected graph with 6 vertices and 9 edge(s)

(11)

IsHamiltonianK33

IsHamiltonian:   "graph satisfies MinimumDegree(G) >= NumberOfVertices(G)/2 ==> it is hamiltonian"

true

(12)

K34CompleteGraph3,4

K34Graph 4: an undirected graph with 7 vertices and 12 edge(s)

(13)

IsHamiltonianK34

IsHamiltonian:   "graph satisfies IndependenceNumber(G) > NumberOfVertices(G)/2 ==> it's not hamiltonian"

false

(14)

Compatibility

• 

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