Eulerian Walks
Conditions for a Eulerian Walk
If there exists a Eulerian walk, then all but at most two vertex degrees must be even.
Only the start and end vertices can have an uneven number of edges. As we start (and end) there, we didn’t mark an edge coming in (going out). Thus they have can have one incident edge more.
The proof idea for this is that every vertex we pass by must have an even number of incident edges, as we come and go the same number of times.
Degree of vertex in a walk
For a walk we define the degree of a vertex to be the number of edges in incident to (with repetitions counted)
If an edge is used more than once in a walk, then could be bigger than .
Closed Eulerian Walks
A walk is closed if it starts and ends with the same vertex . A path is a walk without repeated vertices.
Closed Walk degree
A walk is closed if and only if is even.
Each occurence of in the inner part of the walk increases by 2 (in and out) and thus doesn’t affect the parity. Thus can only be even if it occurs once and the start and once at the end at least, i.e. .
Therefore, a closed Eulerian walk is a walk that visits every edge once.
Closed Eulerian Walk conditions in closed graph
A connected graph has a closed Eulerian walk if and only if all vertex degrees are even.
Proof:
- In a closed walk, by our previous theorem all edge degrees are even. If is Eulerian, then the degrees are the same as in the graph (because we visit each edge only once) for all .
- The other direction will need an algorithm that outputs a solution if all vertex degrees are equal. Algorithm to find a Eulerian Path
Even vertex degrees in Eulerian Walk
In a (non-closed) Eulerian Walk, the same holds if we account for the two edges with odd degrees. By adding a new vertex connecting both of them, we make the problems the same. This new edge makes both of their degrees even…
Hamiltonian Path
In comparison to Eularian paths which can be found in , Hamiltonian paths can only be found by brute-force search (another problem).
Graph properties
Handshake Lemma
For every graph ,
Proof idea: Suppose every vertex distributes a coin to each of it’s incident edges. Then each edge has two coins one from each endpoint, thus the sum of the vertex degrees is twice the number of edges.
Algorithm to find a closed Eulerian Path
The first step to find a closed Eulerian path is to be able to find closed walks in a connected graph.
If we can find multiple, we can exploit any common edges to merge them together.
We iteratively compute closed walks until every edge is used once and then merge them to a closed Eulerian walk.
def walk(u):
if exists_unmarked_edge(u, v):
mark(u, v)
walk(v)We start at , walking . Every edge gets marked once, as we check before marking. The walk ends in a vertex such that all incident edges are marked (as we only stop once there are no more incident edges).
We call the walk() function starting with different vertices, never undoing the marking. At the end, we’ll have all closed walks.
We claim that ALL-EVEN “every vertex is incident to an even number of unmarked edges” is an invariant of walk(). Furthermore, the walk marked by walk(u) is closed.
Proof: If is closed, then is even for all vertices , thus ALL-EVEN holds as we only reduced unmarked edges by an even number.
Assume ends in . Before the walk ALL-EVEN held, and thus had an even number of unmarked edges. After running walk(u) now has no unmarked edges, as the walk ends there. Hence is even. Thus walk(u) marked a walk , as all vertices have an even number of edges in the walk.
we can partition the edges of any graph without odd degree vertices into a collection of closed walks by repeatedly running the walk function on vertices with unmarked edges.
We can then merge these together to create one Eulerian walk.
Faster Algorithm
We can use backtracking and recursive functions to make this more efficient. Now, we iterate over all vertices to start our walk routine.
Z = list()
def euler_walk(u):
for edge (u, v) in E incident to u:
if (u, v) not marked:
mark(u, v)
euler_walk(v)
Z.append(u)
Because we only go back to the last vertex with a still unmarked edge, we can use a single call of euler_walk to find all the closed walks.
def Euler(G):
Z = list()
euler_walk(u0 in G) # u0 here is arbitrary
return ZAdjacency Matrix Runtime
is a graph with vertices and edges.
The adjacency matrix of is defined as

Runtimes:
- Test if for , is as it’s simply array lookup.
- Enumerating the neighbors is , as we need to check the entire column/row.
Euler(G) can be implemented in using an adjacency matrix.
- As each recursive call to
euler_walk(u)is bounded by to iterate through the adjacency matrix - We have a maximum of calls to
euler_walk(as there are at most edges and minimum ).
Adjacency List Runtime
An adjacency list represents the graph as a list of vertices, each cell of which contains the indices of the neighbours of that vertex: 
Runtimes:
- We can test for the existence of an edge in time
- Given a vertex we can enumerate the neighbours in time
This data-structure is more suited to our function euler_walk as it’s faster for the enumeration of the neighbours.
Running time to enumerate all edges of in adjacency list
The runtime to enumerate all edges of given its adjacency list representation is
As enumerating the neighbours of a single vertex takes time , the total runtime is: And using the handshake lemma, that comes out to
Without the term, we might have been tempted to conclude , but for graphs with way more vertices than edges that is false.
As each euler_walk takes (plus the ops carried out in euler_walk(u0)), we can say that it runs in .
The initialisation of the adjacency matrix takes .
Thus the total runtime is .
Correctness
Euler(G)computes a closed Eulerian WalkFor a connected graph without odd degree vertices,
Euler(G)computes a closed Eulerian walk.
Proof: To prove this we will use the recursion tree of the euler_walks and the tortoise and the hare analogy.
We note that each edge of is represented precisely by one edge in . Since euler_walk traverses an edge only if it hasn’t been travelled before, each edge appears only once in . As is connected, it also appears at least once in . Thus each edge is exactly once in .
The hare walks from the root to the first leaf, then back up to the first intersection and down to the second leaf, until it walks from the last leaf to the root again. Then it has traversed every edge of exactly twice. The tortoise waits at the first leaf for the hare, then walks up to the first intersection and jumps immediately to the second leaf, until it’s at the last leaf then to the root. Thus it walks every edge exactly once, and has thus completed a Eulerian walk.
Cycle Detection
If a non-repeating walk exists (i.e. an Eulerian Path), then that walk must be a cycle. If a cycle exists, we are guaranteed to find it with our algorithm.
Remarks from the Exercise Sheet 8
Cut Vertex
If a vertex of degree is not a cut vertex, then it must lie on a cycle.
Remarks from the Exercise Sheet 9
Bipartite Grpah
A graph is bipartite if and only if it does not contain any cycles of odd length.