Almost Hamiltonian Graph

Author

Eric W. Weisstein
April 3, 2024

This notebook downloaded from http://mathworld.wolfram.com/notebooks/GraphTheory/AlmostHamiltonianGraph.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/AlmostHamiltonianGraph.html.

©2024 Wolfram Research, Inc. except for portions noted otherwise

Enumeration

class=Table[{n,GraphData["AlmostHamiltonian",n]},{n,7}];

Length/@class[[All,2]]

Grid[class,Dividers->All,Alignment->Left]

GraphicsGrid[Map[GraphPlot[GraphData[#],PlotLabel->TextCell[Style[If[Head[not=GraphData[#,"Notation"]]===Missing,StringReplace[GraphData[#,"Name"],"\[Hyphen]"->"-"],not],Italic,FontFamily->"Times"],PageWidth->80,TextAlignment->Center]]&,Flatten[Partition[#,7,7,{1,1},{}]&/@DeleteCases[Take[class[[All,2]],6],{}],1],{2}],Spacings->{-30,10},ImageSize->500,Dividers->{All,{True,True,True,True,False,False,False,True}}]

Cubic nonhamiltonian with κ≥2 and (n-1)-cycle

Not Almost Hamiltonian

no=Select[Intersection[GraphData[{"Cubic","Nonhamiltonian"}],GraphData["CyclePolynomial","Defined"]],GraphData[#,"VertexConnectivity"]≥2&&Coefficient[GraphData[#,"CyclePolynomial"][x],x,GraphData[#,"V"]-1]===0&]

TextGrid[Sort[GraphData[#,{"V","HamiltonianNumber","#"}]&/@no],Dividers->All]

Almost Hamiltonian

yes=SortBy[Select[Intersection[GraphData[{"Cubic","Nonhamiltonian"}],GraphData["CyclePolynomial","Defined"]],GraphData[#,"VertexConnectivity"]≥2&&Coefficient[GraphData[#,"CyclePolynomial"][x],x,GraphData[#,"V"]-1]>0&],GraphData[#,"V"]&]

Checks

DeleteCases[Monitor[{g=#,GraphData[#,"AlmostHamiltonian"],AlmostHamiltonianGraphQ[GraphData[#]]}&/@GraphData["Connected",;;8],g],{_,x_,x_}]//Timing

Here is a case where FindAlmostHamiltonianWalk i.e., FindHamiltonianWalk with Method->"HamiltonianPath" fails:

FindHamiltonianWalk[GraphData["ButterflyGraph"],Method->"HamiltonianPath",Debug->True]

GraphData["ButterflyGraph","Graph","Labeled"]

FindHamiltonianWalk[GraphData["ButterflyGraph"]]

FindHamiltonianWalk[GraphData["ButterflyGraph"],MaxIterations->4]

GraphData["ButterflyGraph","Hamiltonian"]

GraphData["ButterflyGraph","HamiltonianWalks"]

GraphDataCountTable

GraphDataCountTable["AlmostHamiltonian"]

Parametrized families

<<MathWorld`Graphs`

Alkane

seq=Table[GraphData[{"Alkane",n},"AlmostHamiltonian"],{n,10}]

AlternatingGroupGraph

seq=Table[GraphData[{"AlternatingGroupGraph",n},"AlmostHamiltonian"],{n,2,6}]

Andrasfai

seq=Table[GraphData[{"Andrasfai",n},"AlmostHamiltonian"],{n,20}]

Antelope n×n

seq=Table[GraphData[{"Antelope",{n,n}},"AlmostHamiltonian"],{n,20}]

Antiprism

Entity["Graph",{"Antiprism",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Antiprism",n},"AlmostHamiltonian"],{n,3,25}]

Apollonian

seq=Table[GraphData[{"Apollonian",n},"AlmostHamiltonian"],{n,5}]

Barbell

seq=Table[GraphData[{"Barbell",n},"AlmostHamiltonian"],{n,3,20}]

BlackBishop n×n

seq=Table[GraphData[{"BlackBishop",{n,n}},"AlmostHamiltonian"],{n,20}]

Bishop n×n

seq=Table[GraphData[{"Bishop",{n,n}},"AlmostHamiltonian"],{n,20}]

Book

seq=Table[GraphData[{"Book",n},"AlmostHamiltonian"],{n,20}]

Bruhat

seq=Table[GraphData[{"Bruhat",n},"AlmostHamiltonian"],{n,6}]

Camel n×n

seq=Table[GraphData[{"Camel",{n,n}},"AlmostHamiltonian"],{n,20}]

Centipede

seq=Table[GraphData[{"Centipede",n},"AlmostHamiltonian"],{n,10}]

FindSequenceFunction[seq,n]

CocktailParty

seq=Table[GraphData[{"CocktailParty",n},"AlmostHamiltonian"],{n,20}]

Complete

Entity["Graph",{"Complete",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Complete",n},"AlmostHamiltonian"],{n,30}]

CompleteBipartite n×n

Entity["Graph",{"CompleteBipartite",{n,n}}]["AlmostHamiltonian"]

seq=Table[GraphData[{"CompleteBipartite",{n,n}},"AlmostHamiltonian"],{n,20}]

CompleteBipartite m×n

Entity["Graph",{"CompleteBipartite",{m,n}}]["AlmostHamiltonian"]

DeleteCases[Flatten[Table[{
{m,n},
GraphData[{"CompleteBipartite",{m,n}},"AlmostHamiltonian"],
Piecewise[{{True,Abs[m-n]==1}},False]
},{n,10},{m,n}],1],{_,x_,x_}]

CompleteTripartite n×n×n

Entity["Graph",{"CompleteTripartite",{n,n,n}}]["AlmostHamiltonian"]

seq=Table[GraphData[{"CompleteTripartite",{n,n,n}},"AlmostHamiltonian"],{n,10}]

CompleteTripartite k×m×n

Entity["Graph",{"CompleteTripartite",{k,m,n}}]["AlmostHamiltonian"]

DeleteCases[Flatten[Table[{
{k,m,n},
GraphData[{"CompleteTripartite",{k,m,n}},"AlmostHamiltonian"],
Piecewise[{{True,k+m+n+1==2Max[k,m,n]}},False]
},{n,10},{m,n},{k,m}],2],{_,x_,x_}]

CrossedPrism

seq=Table[GraphData[{"CrossedPrism",2n},"AlmostHamiltonian"],{n,2,12}]

Crown

seq=Table[GraphData[{"Crown",n},"AlmostHamiltonian"],{n,20}]

CubeConnectedCycle

Entity["Graph",{"CubeConnectedCycle",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"CubeConnectedCycle",n},"AlmostHamiltonian"],{n,3,8}]

Cycle

Entity["Graph",{"Cycle",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Cycle",n},"AlmostHamiltonian"],{n,3,30}]

CycleComplement

seq=Table[GraphData[{"CycleComplement",n},"AlmostHamiltonian"],{n,3,20}]

DiagonalIntersection

seq=Table[GraphData[{"DiagonalIntersection",n},"AlmostHamiltonian"],{n,3,14}]

Dipyramid

seq=Table[GraphData[{"Dipyramid",n},"AlmostHamiltonian"],{n,3,20}]

DorogovtsevGoltsevMendes

seq=Table[GraphData[{"DorogovtsevGoltsevMendes",n},"AlmostHamiltonian"],{n,0,7}]

DoubleCone

seq=Table[GraphData[{"DoubleCone",n},"AlmostHamiltonian"],{n,3,20}]

Empty

Entity["Graph",{"Empty",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Empty",n},"AlmostHamiltonian"],{n,30}]

FibonacciCube

seq=Table[GraphData[{"FibonacciCube",n},"AlmostHamiltonian"],{n,15}]

Fiveleaper n×n

seq=Table[GraphData[{"Fiveleaper",{n,n}},"AlmostHamiltonian"],{n,20}]

Flower

seq=Table[GraphData[{"Flower",n},"AlmostHamiltonian"],{n,5,20}]

FoldedCube

seq=Table[GraphData[{"FoldedCube",n},"AlmostHamiltonian"],{n,2,10}]

FindSequenceFunction[seq,n]

Gear

seq=Table[GraphData[{"Gear",n},"AlmostHamiltonian"],{n,3,20}]

FindSequenceFunction[seq,n]

Giraffe n×n

seq=Table[GraphData[{"Giraffe",{n,n}},"AlmostHamiltonian"],{n,20}]

Goldberg

seq=Table[GraphData[{"Goldberg",n},"AlmostHamiltonian"],{n,3,20}]

Grid n×n

Entity["Graph",{"Grid",{n,n}}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Grid",{n,n}},"AlmostHamiltonian"],{n,20}]

Table[Piecewise[{{True,Mod[n,2]==1&&n>1}},False],{n,20}]==seq

Grid m×n

Entity["Graph",{"Grid",{m,n}}]["AlmostHamiltonian"]

DeleteCases[Flatten[Table[{
{m,n},
GraphData[{"Grid",{m,n}},"AlmostHamiltonian"],
Piecewise[{{True,Mod[m n,2]==1&&(Min[m,n]>1||m n==3)}},False]
},{n,10},{m,n}],1],{_,x_,x_}]

Grid n×n×n

Entity["Graph",{"Grid",{n,n,n}}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Grid",{n,n,n}},"AlmostHamiltonian"],{n,10}]

Table[Piecewise[{{True,Mod[n,2]==1&&n>1}},False],{n,10}]==seq

Grid k×m×n

Entity["Graph",{"Grid",{k,m,n}}]["AlmostHamiltonian"]

DeleteCases[Sort@Flatten[Table[{
{k,m,n},
GraphData[{"Grid",{k,m,n}},"AlmostHamiltonian"],
Piecewise[{{True,Mod[k m n,2]==1}},False]
},{n,5},{m,n},{k,m}],2],
{_,x_,x_}]

HalvedCube

seq=Table[GraphData[{"HalvedCube",n},"AlmostHamiltonian"],{n,10}]

Hanoi

seq=Table[GraphData[{"Hanoi",n},"AlmostHamiltonian"],{n,5}]

Helm

seq=Table[GraphData[{"Helm",n},"AlmostHamiltonian"],{n,3,20}]

Hypercube

Entity["Graph",{"Hypercube",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Hypercube",n},"AlmostHamiltonian"],{n,0,10}]

Keller

Entity["Graph",{"Keller",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Keller",n},"AlmostHamiltonian"],{n,5}]

King n×n

seq=Table[GraphData[{"King",{n,n}},"AlmostHamiltonian"],{n,20}]

King m×n

Entity["Graph",{"King",{m,n}}]["AlmostHamiltonian"]

DeleteCases[Flatten[Table[{
{m,n},
GraphData[{"Knight",{m,n}},"AlmostHamiltonian"],
XXX
},{n,10},{m,n}],1],{_,x_,x_}]

Knight n×n

Entity["Graph",{"Knight",{n,n}}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Knight",{n,n}},"AlmostHamiltonian"],{n,20}]

Table[Piecewise[{{True,Mod[n,2]==1&&n>3}},False],{n,20}]==seq

Knight m×n

Entity["Graph",{"Knight",{m,n}}]["AlmostHamiltonian"]

DeleteCases[Flatten[Table[{
{m,n},
GraphData[{"Knight",{m,n}},"AlmostHamiltonian"],
False
},{n,10},{m,n}],1],{_,x_,x_}]

Ladder

Entity["Graph",{"Ladder",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Ladder",n},"AlmostHamiltonian"],{n,20}]

LadderRung

seq=Table[GraphData[{"LadderRung",n},"AlmostHamiltonian"],{n,20}]

LucasCube

seq=Table[GraphData[{"LucasCube",n},"AlmostHamiltonian"],{n,15}]

MengerSponge

seq=Table[GraphData[{"MengerSponge",n},"AlmostHamiltonian"],{n,3}]

MoebiusLadder

Entity["Graph",{"MoebiusLadder",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"MoebiusLadder",n},"AlmostHamiltonian"],{n,3,25}]

Mycielski

Entity["Graph",{"Mycielski",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Mycielski",n},"AlmostHamiltonian"],{n,11}]

Odd

Entity["Graph",{"Odd",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Odd",n},"AlmostHamiltonian"],{n,7}]

Pan

seq=Table[GraphData[{"Pan",n},"AlmostHamiltonian"],{n,3,20}]

Path

Entity["Graph",{"Path",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Path",n},"AlmostHamiltonian"],{n,20}]

PathComplement

seq=Table[GraphData[{"PathComplement",n},"AlmostHamiltonian"],{n,20}]

Pell

seq=Table[GraphData[{"Pell",n},"AlmostHamiltonian"],{n,9}]

Prism

Entity["Graph",{"Prism",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Prism",n},"AlmostHamiltonian"],{n,3,25}]

Queen n×n

seq=Table[GraphData[{"Queen",{n,n}},"AlmostHamiltonian"],{n,20}]

Rook n×n

seq=Table[GraphData[{"Rook",{n,n}},"AlmostHamiltonian"],{n,20}]

RookComplement n×n

seq=Table[GraphData[{"RookComplement",{n,n}},"AlmostHamiltonian"],{n,20}]

SierpinskiCarpet

seq=Table[GraphData[{"SierpinskiCarpet",n},"AlmostHamiltonian"],{n,4}]

SierpinskiGasket

seq=Table[GraphData[{"SierpinskiGasket",n},"AlmostHamiltonian"],{n,5}]

SierpinskiTetrahedron

seq=Table[GraphData[{"SierpinskiTetrahedron",n},"AlmostHamiltonian"],{n,6}]

Spoke n×n

seq=Table[GraphData[{"Spoke",{n,n}},"AlmostHamiltonian"],{n,5}]

StackedBook

seq=Table[GraphData[{"StackedBook",{n,n}},"AlmostHamiltonian"],{n,10}]

StackedPrism

seq=Table[GraphData[{"StackedPrism",{n,n}},"AlmostHamiltonian"],{n,3,5}]

Star

Entity["Graph",{"Star",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Star",n},"AlmostHamiltonian"],{n,25}]

Sun

seq=Table[GraphData[{"Sun",n},"AlmostHamiltonian"],{n,3,20}]

Sunlet

seq=Table[GraphData[{"Sunlet",n},"AlmostHamiltonian"],{n,3,20}]

TorusGrid n×n

seq=Table[GraphData[{"TorusGrid",{n,n}},"AlmostHamiltonian"],{n,3,20}]

Transposition

Entity["Graph",{"Transposition",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Transposition",n},"AlmostHamiltonian"],{n,6}]

Trapezohedron

Entity["Graph",{"Trapezohedron",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Trapezohedron",n},"AlmostHamiltonian"],{n,3,20}]

Triangular

seq=Table[GraphData[{"Triangular",n},"AlmostHamiltonian"],{n,2,20}]

TriangularGrid

seq=Table[GraphData[{"TriangularGrid",n},"AlmostHamiltonian"],{n,0,20}]

TriangularHoneycombAcuteKnight

seq=Table[GraphData[{"TriangularHoneycombAcuteKnight",n},"AlmostHamiltonian"],{n,20}]

TriangularHoneycombBishop

seq=Table[GraphData[{"TriangularHoneycombBishop",n},"AlmostHamiltonian"],{n,20}]

TriangularHoneycombObtuseKnight

seq=Table[GraphData[{"TriangularHoneycombObtuseKnight",n},"AlmostHamiltonian"],{n,20}]

TriangularHoneycombQueen

seq=Table[GraphData[{"TriangularHoneycombQueen",n},"AlmostHamiltonian"],{n,20}]

TriangularHoneycombRook

seq=Table[GraphData[{"TriangularHoneycombRook",n},"AlmostHamiltonian"],{n,20}]

TriangularSnake

seq=Table[GraphData[{"TriangularSnake",n},"AlmostHamiltonian"],{n,1,20,2}]

Web

seq=Table[GraphData[{"Web",n},"AlmostHamiltonian"],{n,3,20}]

Wheel

Entity["Graph",{"Wheel",n}]["AlmostHamiltonian"]

seq=Table[GraphData[{"Wheel",n},"AlmostHamiltonian"],{n,4,20}]

WheelComplement

seq=Table[GraphData[{"WheelComplement",n},"AlmostHamiltonian"],{n,4,20}]

WhiteBishop n×n

seq=Table[GraphData[{"WhiteBishop",{n,n}},"AlmostHamiltonian"],{n,2,20}]

Zebra n×n

seq=Table[GraphData[{"Zebra",{n,n}},"AlmostHamiltonian"],{n,20}]