Eulerian Circuits and Trails
A walk that uses every edge of a graph exactly once is an Euler trail; if it starts and ends at the same vertex, it is an Euler circuit. Euler's theorem: a connected graph has an Euler circuit if and only if every vertex has even degree, and has an Euler trail but no circuit if and only if exactly two vertices have odd degree.
Every time a trail passes through a vertex without stopping there, it uses up two of that vertex's edges, one arriving and one leaving, so a vertex can only be such a pass-through point an even number of times. A circuit never stops, so every vertex contributes an even number of trail-edges there: every degree must be even. A trail that is not a circuit has exactly two special vertices, its start and its end, each contributing one unmatched edge, so only those two may be odd. This matches the handshake lemma from Graphs and Degrees (Topic 1): the number of odd-degree vertices is always even, so and are the only possibilities Euler's theorem can act on. The sharp part, proved in Why It Works, is that this simple local counting condition is not just necessary but sufficient: once every degree is even and the graph is connected, no global obstruction can block a circuit.
In the complete graph on (all edges), every vertex has degree , which is even, and the graph is connected, so Euler's theorem guarantees a circuit. One alternates between the outer -cycle and the pentagram of long diagonals:
Check: the ten edges used, in order, are — exactly the ten unordered pairs from , each appearing once, and the walk returns to where it started.
Delete edge from on , leaving . The degree sequence is and : exactly two odd vertices, so Euler's theorem promises a trail from to , not a circuit. One is
which uses — all five edges once, starting and ending at the two odd vertices.
Now restore edge , so every vertex of has degree . Four vertices of odd degree is already too many: Euler's theorem allows at most two. So has neither an Euler circuit nor an Euler trail, no matter how the six edges are ordered — some vertex other than a start or an end would need an odd number of trail-edges at it, which no trail can give it.
Checking only "are all degrees even?" without checking connectivity. Two disjoint triangles and give every vertex degree , which is even, yet there is no Euler circuit: a single trail cannot jump between the two pieces, since no edge joins them. Euler's theorem requires the graph to be connected; the degree condition alone is not enough.
The "kite" graph has a triangle plus a pendant edge . Does it have an Euler trail? If so, find one.
Show the answerHide the answer
Degrees are , , : exactly two odd vertices, and , so a trail exists between them. One is , using — all four edges once. The trail runs from to .
The Bridges of Konigsberg
The city of Königsberg had two river banks (, ) and two islands (, ), joined by seven bridges: two between and , two between and , and one each for –, –, –. The question: could a walker cross every bridge exactly once? Modeled as a graph, this is exactly the question of Section 1: does the multigraph have an Euler trail?
This is the problem that started graph theory, in 1736. Euler's insight was to throw away the map entirely and keep only which landmasses each bridge joins — turning a geography puzzle into the degree-counting question of the previous section. He showed the answer was no, and in doing so found the general rule stated there: a multigraph has an Euler trail only when at most two vertices have odd degree, counting each bridge (even a parallel one) separately. A multigraph is treated exactly like an ordinary graph for this theorem, except that parallel edges each contribute their own unit to both endpoints' degree.
Count the bridges at each landmass: (two to , one to ), , (two to , two to , one to ), . All four degrees are odd — far more than the two Euler's theorem allows. So no walk, however clever, can cross every bridge exactly once. This is Euler's actual conclusion: the walk is impossible.
Suppose the eastern – bridge washes out, leaving six bridges. Now and , while and are unchanged: exactly two odd vertices, and . An Euler trail now exists, for instance
which uses the remaining bridges once each.
Instead of removing a bridge, suppose the city adds new ones to make a circuit possible. All four landmasses are odd, so at least two new bridges are needed (each new bridge can fix the parity of at most two vertices). Adding – and a second – bridge does it: , , , — all even, and the graph is still connected, so by Euler's theorem a circuit exists. One is
using all nine bridges, , exactly once and returning to .
Collapsing the two parallel – bridges (or the two parallel – bridges) into a single edge, as if the multigraph were an ordinary graph. That mistake gives , , , — only two odd vertices — and wrongly suggests a trail exists. Each physical bridge is its own edge and must be counted on its own, even when two bridges join the same pair of landmasses.
Suppose instead a storm destroys both the – bridge and the – bridge. Does the remaining network admit an Euler walk?
Show the answerHide the answer
Removing those two bridges drops from to , from to , and from to ; is unchanged. Odd vertices: and — exactly two, so a trail exists between them, such as using the five remaining bridges. An Euler walk exists, from to .
Hamiltonian Cycles
A Hamiltonian cycle visits every vertex of a graph exactly once and returns to its start; a Hamiltonian path visits every vertex exactly once without returning. Unlike Euler's theorem, no simple test on the degrees alone decides whether a graph has one — deciding Hamiltonicity is one of the fundamental hard (NP-complete) problems of computer science.
The two questions sound alike — trace the graph exhaustively — but they count different things: an Euler trail is a condition on edges, which are local to a vertex and so add up into a clean parity rule. A Hamiltonian cycle is a condition on vertices, but the obstruction to visiting them all is global: a single awkward vertex, or an imbalance far from where you are looking, can make the whole cycle impossible, and there is no known way to check this by scanning degrees one vertex at a time. That asymmetry is why this section can only give examples and the next section gives sufficient (not exact) conditions: strong partial answers are the best that is known.
The triangular prism has two triangles and joined by the matching — vertices, edges, every degree . Going around one triangle, crossing over, and returning around the other gives
using the edges and visiting all vertices exactly once.
Two triangles and share only the vertex (the "bowtie"), giving and all other degrees . Vertex is a cut vertex: removing it disconnects from , since those pairs have no other connection. A Hamiltonian cycle, minus any one of its vertices, must leave the rest joined by a single path — but deleting splits the other four vertices into two disconnected pairs, which no path can do. So the bowtie has no Hamiltonian cycle, even though every vertex has degree .
Split vertices into and , joined by all possible edges between the two sides (none within a side) — the complete bipartite graph . Every edge crosses between and , so any cycle must alternate sides, , and alternating sides forces the cycle to have even length. A Hamiltonian cycle here would need length (all vertices), which is odd — impossible. So , despite every vertex having degree or more, has no Hamiltonian cycle; the obstruction is the unequal split , not a shortage of edges.
Assuming that enough edges, or high enough degrees, must force a Hamiltonian cycle. is a counterexample: it has edges and minimum degree , yet no Hamiltonian cycle exists, because the obstruction (an odd total split unevenly across a bipartition) has nothing to do with how many edges there are. High connectivity helps, as the next section shows, but no amount of density alone can substitute for the right structural check.
A square has a triangular roof: is joined to and . Does this -vertex graph have a Hamiltonian cycle?
Show the answerHide the answer
Yes: uses edges — all of them edges of the graph — and visits every vertex exactly once before closing back to . The cycle is .
Dirac's and Ore's Theorems
Dirac's theorem: if a graph has vertices and every vertex has degree , it has a Hamiltonian cycle. Ore's theorem, which implies Dirac's: if for every pair of non-adjacent vertices , the graph has a Hamiltonian cycle.
These are sufficient, not necessary, conditions: a dense enough graph is forced to have a Hamiltonian cycle, even though sparser graphs can have one too. Ore's version is strictly more useful, since it only restricts pairs that are already missing an edge, letting isolated low-degree vertices through so long as their non-neighbors compensate; Dirac's theorem is the special case where EVERY vertex clears the bar, so every pair, adjacent or not, automatically sums to at least . Both explain the previous section's exactly: with , two vertices on the size- side are non-adjacent with degree sum , so Ore's hypothesis fails for that pair — consistent with having no Hamiltonian cycle, though it does not prove the absence by itself. The proofs, which explain why density alone forces a cycle, are in Why It Works.
Take vertices and join every pair except the three "opposite" pairs — the octahedron graph, edges. Every vertex is missing only its one opposite, so for all , and : Dirac's condition holds. Indeed is a Hamiltonian cycle, since consecutive labels are never apart (never an opposite pair).
Let be mutually adjacent (a ), and add one more vertex joined only to and — vertices, edges. Then , well below , so Dirac's theorem says nothing. But the only non-adjacent pairs are , each with degree sum : Ore's condition holds for every non-adjacent pair, so a Hamiltonian cycle is guaranteed. One is
using edges , all present, and visiting all vertices.
Revisit () from the previous section. Its only non-adjacent pairs sit within a single side. Two vertices on the -side have degree sum : fine. But two vertices on the -side have degree sum : this pair violates Ore's hypothesis, so the theorem simply does not apply — it neither confirms nor (on its own) rules out a Hamiltonian cycle. The direct parity argument from Section 3 is what actually proves has none; Ore's theorem only explains why no density argument could have shortcut that proof.
Treating Dirac's or Ore's theorem as an if-and-only-if. The cycle graph (for any ) is a Hamiltonian cycle by definition, yet every vertex has degree , far below : Dirac's hypothesis fails completely, but the conclusion is still true. A failed hypothesis gives no information either way; only a satisfied hypothesis guarantees the cycle.
The Petersen graph has vertices, each of degree . Does Dirac's theorem guarantee it has a Hamiltonian cycle?
Show the answerHide the answer
No: Dirac's theorem needs every degree , but every vertex here has degree , so the hypothesis fails and the theorem gives no conclusion at all. (It happens that the Petersen graph truly has no Hamiltonian cycle — one of the most famous such graphs — but that has to be shown directly, not from Dirac's theorem.) The answer is .
Gray Codes and Tours
A (cyclic) Gray code on bits lists all bit-strings so that consecutive strings — including the last back to the first — differ in exactly one bit. This is exactly a Hamiltonian cycle on the hypercube graph , whose vertices are the -bit strings, joined by an edge whenever they differ in one bit.
Gray codes matter outside graph theory too — rotary position encoders and error-resistant digital counters use them so that a single misread bit changes the reading by only one step, not an unpredictable jump. The question "does have a Hamiltonian cycle?" could be attacked with Dirac's theorem ( is -regular on vertices, and only for tiny , so Dirac's theorem is useless here for large ), but a direct, explicit construction works for every : the reflected binary Gray code, built recursively by writing the code for bits twice, prefixing to the first copy and to the reverse of the second. Reversing the second copy is exactly what keeps the one-bit-change property across the "seam" in the middle, and matching it back to the start of the first copy keeps the whole thing cyclic.
The cube graph has vertices (the -bit strings), each of degree (flip any one of bits), edges. Building from by the reflect-and-prefix rule: prefix to , then prefix to reversed (), giving
Each consecutive pair differs in exactly one bit (check : only the leftmost bit changes), and the last, , differs from the first, , in exactly one bit too — a genuine Hamiltonian cycle on .
Apply the same rule once more. Prefixing to every string of gives the first codewords; reversing to and prefixing gives the last :
This lists all strings of bits exactly once, consecutive strings always differ in one bit (the rule guarantees it at every step, including the jump from to , which only flips the leftmost bit), and the last, , differs from the first, , in one bit as well.
Assuming any sequence of one-bit flips that never immediately repeats a string will eventually cover all of them. Starting from and flipping greedily,
every step changes one bit and no string repeats, yet this path is stuck: from , the only one-bit flips reach , all already visited, and is never reached at all. A valid one-bit-flip path can dead-end long before covering every vertex; only a systematic rule like the reflect-and-prefix construction is guaranteed to reach all strings.
For the Gray code , treated as a cycle (not just a list), how many bits apart are the first and last codewords?
Show the answerHide the answer
The first codeword is and the last is ; they differ only in the leftmost bit, so the Hamming distance is . This is exactly what makes a Hamiltonian cycle on rather than just a Hamiltonian path: the construction closes up because the two halves it is built from, and , meet at matching endpoints on both seams.
Why It Works
Necessity was shown in Section 1: in any trail, every visit to a vertex other than its two ends uses up exactly two edges there, so only the two end-vertices (one, if it is a circuit, where they coincide) can have an odd number of trail-edges; all other vertices must be even. For sufficiency, let be connected with every degree even, and let be a trail in of maximum length (such exists since is finite). First, must be a circuit: if it ended at start, every time passed through it used two of 's edges, plus one more to arrive the last time, an odd total; but is even, so some edge at is still unused, and appending it would make longer, contradicting maximality. So is a circuit. Suppose does not use every edge of . Since is connected, some vertex on has an edge not in (otherwise the unused edges would form a separate component). Walking from back to , then crossing and continuing, extends to a longer trail unless immediately dead-ends — but the same even-degree argument at the far end of shows the walk can always be continued (and, since is finite, must eventually return to close a circuit through the unused edges, which splices into at ). This contradicts maximality, so already uses every edge: is an Euler circuit. For the trail case (exactly two odd vertices ): add a phantom edge ; every degree is now even, so by the circuit case there is an Euler circuit of , and deleting the edge from it leaves an Euler trail of from to .
Let have vertices with for every non-adjacent pair . Adding an edge to can only increase degrees, so this condition still holds for any graph on the same vertices. Suppose, for contradiction, that has no Hamiltonian cycle. Add edges to , one at a time, keeping the graph non-Hamiltonian, until no more can be added without creating one; call the result . is not complete (else would trivially be Hamiltonian for ), so some pair is still non-adjacent in , and by maximality has a Hamiltonian cycle. That cycle must use the edge (otherwise it would already be a Hamiltonian cycle of ), so deleting from it leaves a Hamiltonian path of , . Let and ; since are non-adjacent, and exactly (every neighbor of other than is some with , and symmetrically for ). Both , so if they were disjoint, ; but , so . Take in both: is adjacent to and is adjacent to . Then
is a Hamiltonian cycle of , using only the original path edges together with and — never the added edge . This contradicts being non-Hamiltonian, so the assumption that has no Hamiltonian cycle was false.
If every vertex of (on vertices) has degree , then for ANY two vertices — adjacent or not — . In particular this holds for every non-adjacent pair, which is exactly Ore's hypothesis; Ore's theorem then gives a Hamiltonian cycle. So Dirac's theorem is the special case of Ore's where the degree bound is enforced on every vertex individually rather than only on non-adjacent pairs.