Advanced maths

Hamiltonian cycle count calculator with a vertex cycle witness

Count vertex-spanning round trips in a small undirected network, with rotations and reverse traversals treated as the same cycle.

Your numbers

Vertices are labeled consecutively from 1 through this number, including isolates.
One u,v row per edge; unordered pairs must be unique.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Count vertex-spanning round trips in a small undirected network, with rotations and reverse traversals treated as the same cycle. The answer includes one explicit cycle when the count is positive. This is useful when route variety matters: one cheapest traveling-salesperson tour does not reveal how many feasible tours the network supports.

THE FORMULAF(S,v)=Σ F(S∪{w},w) over unvisited neighbors w; F(V,v)=1 if {v,1}∈E, else 0; cycles=F({1},1)/2.

A worked example

K4: fixing vertex 1 gives 3!=6 rooted tours. Identifying each with its reverse gives 3 cycles, including 1–2–3–4–1.

Good to know

Simple undirected graph, 3–13 vertices; exact integer subset DP. Rotations and reversals identified; no directed, weighted or parallel-edge cycle counts.

What qualifies as a complete cycle

A Hamiltonian cycle uses every declared vertex exactly once before returning to its starting vertex. Every consecutive pair, including the final return leg, must be an entered edge; the drawing alone never supplies an omitted connection.

Isolated vertices remain part of the problem even when they do not appear in an edge row. A disconnected graph, or a vertex of degree below two, cannot support a Hamiltonian cycle under the simple-graph convention used here.

Hamiltonian cycle count calculator with a vertex cycle witness worked exampleCount complete vertex cycles1234K4: 6 rooted tours ÷ 2 = 3 cycles
K4: fixing vertex 1 gives 3!=6 rooted tours. Identifying each with its reverse gives 3 cycles, including 1–2–3–4–1.

Compare this with the Euler path and circuit calculator from a graph edge list. Euler routes visit every edge; Hamiltonian cycles constrain vertex visits.

Why rotations and reversals disappear

Writing 1–2–3–4–1 and 2–3–4–1–2 describes the same closed route with a different starting position. Fixing vertex one at the beginning removes these rotational copies before any counting takes place.

Traversing the route backward gives a second rooted ordering. For undirected simple graphs with at least three vertices, every rooted cycle has a distinct reverse, so the rooted count is divided by two exactly once.

Following the subset recurrence

A counting state records a visited vertex subset and the last vertex of a path beginning at vertex one. Extending the state appends an adjacent unvisited vertex; different prefixes reaching the same state share the remaining subproblem.

When every vertex has been visited, the state contributes one only if the endpoint reconnects to the root. This terminal test is essential: a path through all vertices can exist even when a closed tour does not.

Checking the four-vertex example

The default graph contains all six edges on four vertices. Starting at vertex one leaves six possible orders for the remaining three vertices, and every such order closes because all required edges are present.

Pairing each ordering with its reversal leaves three undirected cycles. One witness is 1–2–3–4–1. This directly checks both the counting convention and the requirement that a displayed witness uses genuine graph edges.

Reading zero and positive answers

A positive count certifies at least that many distinct undirected cycles under the stated equivalence. The displayed witness is one member of that collection; it is not a listing of every cycle or a claim that the cycle is shortest.

A zero answer comes from a completed exact recurrence, rather than a failed random search. Removing an edge may reduce the count without eliminating every cycle, so the count offers more information than a yes-or-no Hamiltonicity test.

Keeping the graph input precise

Declare three through thirteen vertices, labeled consecutively from one. Enter each undirected pair once. Self-loops and repeated unordered pairs are rejected because otherwise edge identity would introduce a different multigraph counting problem.

No distances or travel times are used. To model one-way movement, repeated visits, service restrictions or weighted route optimization, use a solver designed for those constraints rather than interpreting this count as a transport schedule.

Understanding the exactness boundary

Subset dynamic programming is exponential in the vertex count, which explains the deliberately small input cap. At thirteen vertices the complete-graph answer is 12 factorial divided by two, or 239,500,800, comfortably within exact integer range.

The result is an exact count for the entered simple graph, not a probability that a physical route remains available. Missing or incorrectly modeled connections change the mathematical problem before the counting algorithm begins.

A few questions, answered

Does changing the first vertex change the count?

No. Fixing vertex one removes rotational copies; choosing any other fixed root gives the same undirected count.

Are clockwise and anticlockwise routes separate?

No. A route and its reversal are identified because every edge is undirected.

Does a zero count rule out a Hamiltonian path?

No. A spanning path can exist without an edge reconnecting its endpoints.

Can I enter parallel edges?

No. This calculator uses a simple graph and counts vertex cycles, without parallel-edge identities.

Find your calculator

Start typing to explore the library.