Eulerian
Building on the graph theory foundations, three traversal questions about a graph illustrate strikingly different computational landscapes:
- PATH. Given two vertices \(s\) and \(t\), is \(t\) reachable from \(s\)?
- Eulerian cycle. Can every edge be traversed exactly once in a closed walk?
- Hamiltonian cycle. Can every vertex be visited exactly once in a closed walk?
PATH is solved in polynomial time by breadth-first search. Eulerian admits, for connected graphs, a degree-parity test (Euler's theorem below). Hamiltonian, despite its surface similarity to Eulerian, is NP-complete. The remainder of this page develops the contrast between the latter two. PATH reappears when we study walks on graphs and network flow. The notion of polynomial time used here is formalized in our study of time complexity.
The Eulerian concept originates from Leonhard Euler's 1736 analysis of the Seven Bridges of Königsberg, widely considered the birth of graph theory. We adopt the strict simple-graph setting from the graph definition. The original Königsberg problem involves a multigraph (parallel bridges between landmasses), which lies outside this setting. Collapsing the parallel edges would not help, because it changes the vertex degrees and hence the answer.
Convention. Throughout this page we use three operational notions of traversal. A walk in \(G\) is a sequence of vertices \(v_0, v_1, \ldots, v_k\) with each consecutive pair \(v_{i-1} v_i\) an edge of \(G\). Vertices and edges may repeat. A trail is a walk in which no edge repeats (vertices may still repeat). A walk or trail is closed if \(v_0 = v_k\). These notions receive a formal definition in walks and trails. The operational descriptions above suffice here.
A graph is Eulerian if it contains an Eulerian cycle (also called an Euler tour). An Eulerian cycle is a closed walk that traverses every edge exactly once. (Vertices may be revisited. Only the no-edge-repetition constraint is required, so an Eulerian cycle is in fact a closed trail covering all of \(E\).)
A graph is semi-Eulerian if it contains an Eulerian path (also called an Eulerian trail) with two distinct endpoints. Such a path is a trail that traverses every edge exactly once but does not close up. By this convention, the Eulerian and semi-Eulerian classes are disjoint.
A connected graph is Eulerian if and only if every vertex has even degree.
- Graph 1 (the 4-cycle \(C_4\)) is Eulerian, since every vertex has degree 2.
- Graph 2 (the path \(A\!-\!B\!-\!C\)) is semi-Eulerian. It admits an Eulerian path \(A \to B \to C\) but no Eulerian cycle, with exactly two odd-degree vertices \(A\) and \(C\).
- Graph 3 (two triangles sharing the vertex \(A\)) is Eulerian, since \(A\) has degree 4 and the other vertices have degree 2.
These small cases match the theorem's degree-parity criterion and exhibit three kinds of behavior: Eulerian, semi-Eulerian, and Eulerian with a revisited vertex. Having checked the theorem on examples, we now prove it in general.
The forward direction below is a local pairing argument at each vertex of the cycle, in the same double-counting spirit as the handshaking lemma. The converse is constructive and produces an explicit algorithm. This argument is due to Carl Hierholzer (1873), who showed that the procedure of greedily extending a closed trail and then splicing in further closed sub-trails terminates with an Eulerian cycle. Euler himself proved only the necessity direction in 1736, and a proof of sufficiency waited 137 years. We present Hierholzer's argument in self-contained form.
(\(\Rightarrow\)) Suppose \(G\) admits an Eulerian cycle \(C\). Fix any vertex \(v\). Each visit to \(v\) along \(C\) consists of one entering edge paired with one leaving edge, and every edge incident to \(v\) appears in exactly one such pair (by the "every edge exactly once" property). Hence the edges incident to \(v\) split into pairs, so \(\deg(v)\) is even.
(\(\Leftarrow\)) Suppose \(G\) is connected and every vertex has even degree.
Boundary case. If \(|E| = 0\), then \(G\) consists of isolated vertices. Connectivity forces \(|V| = 1\), and the trivial walk at the single vertex (length 0) is vacuously an Eulerian cycle. Assume henceforth \(|E| \geq 1\), so by even-degree some vertex has degree \(\geq 2\).
Step 1 (closed trail at a chosen base vertex). Pick any vertex \(v_0\) with \(\deg(v_0) \geq 2\). Build a trail greedily. At each step, if the current endpoint has an unused incident edge, extend the trail along one such edge. The procedure must terminate because \(|E|\) is finite. We claim the trail terminates at \(v_0\).
Indeed, fix any intermediate vertex \(v \neq v_0\). Each full visit to \(v\) (entering and then leaving) uses exactly two incident edges of \(v\), so between visits an even number of them have been used. Immediately after entering \(v\) without yet leaving, the count is odd. Hence at any moment when the trail has just entered \(v\), an odd number of \(v\)-incident edges have been used. Since \(\deg(v)\) is even, at least one unused incident edge remains, and the trail can be extended. The trail therefore cannot terminate at any \(v \neq v_0\), so it closes at \(v_0\). Call this closed trail \(C\).
Step 2 (residual subgraph still has even degrees). Let \(G' = (V, E \setminus E(C))\) be the subgraph obtained by removing the edges of \(C\). For each \(v \in V(C)\), the closed trail \(C\) uses an even number of incident edges at \(v\) (each visit pairs an entry with an exit), so \(\deg_{G'}(v) = \deg_G(v) - (\text{even})\) remains even. Vertices outside \(V(C)\) have unchanged even degree.
Step 3 (existence of a splice point). If \(E(C) = E\), then \(C\) is the desired Eulerian cycle and we are done. Otherwise \(G'\) has at least one edge. Suppose for contradiction that no vertex of \(C\) has positive \(G'\)-degree. Then every \(G'\)-edge lies entirely in \(V(G) \setminus V(C)\). On the other hand, every edge of \(C\) has both endpoints in \(V(C)\) by the very definition of \(V(C)\) as the vertex set of \(C\). Since \(E(G) = E(G') \sqcup E(C)\), no edge of \(G\) connects \(V(C)\) to \(V(G) \setminus V(C)\). The existence of a \(G'\)-edge implies \(V(G) \setminus V(C) \neq \emptyset\), so no path in \(G\) joins a vertex of \(V(C)\) to a vertex of \(V(G) \setminus V(C)\), since such a path would have to use an edge between the two sets. This contradicts the fact that \(G\) is connected.
Hence some \(u \in V(C)\) satisfies \(\deg_{G'}(u) \geq 1\). Since \(\deg_{G'}(u)\) is even and positive, we have \(\deg_{G'}(u) \geq 2\). Apply Step 1 inside \(G'\) starting at \(u\) to obtain a closed trail \(C'\) in \(G'\) of length at least 2.
Step 4 (splice). The vertex \(u\) appears at least once on \(C\). We fix one such occurrence. Form a new closed walk by traversing \(C\) up to that occurrence of \(u\), then traversing all of \(C'\) (which begins and ends at \(u\)), then continuing along the remainder of \(C\). The result is a closed walk in \(G\) using exactly \(E(C) \cup E(C')\), a disjoint union (\(E(C')\) lies in \(G'\)), so no edge is repeated. The spliced walk is therefore a closed trail strictly longer than \(C\).
Termination. Replace \(C\) by the spliced trail and return to Step 2. Each iteration strictly increases the edge count of \(C\) by at least 2, and \(|E|\) is finite, so the procedure halts after finitely many iterations with \(E(C) = E\). At that point \(C\) is an Eulerian cycle.