Data Structures and Algorithms

*Euler Tours*

*executive summary*

An Euler tour is a walk in a graph that visits every edge *exactly *once.

We discover necessary and sufficient conditions for when a graph admits an Euler Tour, and devise an algorithm to construct such a tour.

__link to companion notes__ · play on Mathigon

1

1

2

1

2

3

1

2

3

4

1

2

3

4

5

1

2

3

4

5

6

1

2

3

4

5

6

7

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

1

2

3

4

5

6

7

8

9

Work through the exercises in the Mathigon lesson

about the Bridges of Königsberg

Graphs Recap

Model *relationships *between *entities*.

Graphs

*Common graphical representation: points & lines*

Graphs can be...

Directed or Undirected

Vertex- and/or Edge-weighted

Simple or... not*

*graphs that are not simple are usually called *multigraphs*

Colored, temporal, hyper, etc.

Graphs: Terminology

Vertices & Edges

Vertices are *adjacent *if there is an edge between them; and they are the *endpoints *of said edge.

An edge is *incident *to its endpoints.

The *(out)-neighbors *of a vertex X are all the vertices Y such that (X,Y) is an edge.

The *degree *of a vertex is the number of neighbors it has.

A **walk** is a sequence of edges

\(e_1, \ldots, e_{n-1}\)

such that there exists a sequence of vertices

\(v_1, \ldots, v_n\)

for which \(e_i = (v_i, v_{i+1})\)

for all \(1 \leqslant i \leqslant n-1\).

An (closed/open) **Euler Tour **of a graph \(G\)

is a (closed/open) walk

that contains every edge *exactly *once

(i.e, no repeats and no omissions).

If a graph \(G\) has:

(a) more than two vertices of odd degree, or

(b) exactly one vertex of odd degree, then

it **does not** have an Euler Tour of any kind

(closed or open).

**What we discovered**

If a graph \(G\) has:

(a) exactly two vertices of odd degree, or

(b) no vertex of odd degree, then

**does it** have an Euler Tour of *some* kind

(closed or open)?

**Food for thought**

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*Only if. *If \(G\) has a closed Eulerian walk, then all vertices of \(G\) must have even degree.

Let \(W\) be a closed Euler walk that starts and ends at \(S\).

Note that \(W\) visits each vertex a certain number of times.

Let \(A \neq S\) be a vertex and assume we visited \(A\) exactly \(a\) times.

This means we entered \(A\) exactly \(a\) times, and we left \(A\) exactly \(a\) times.

As we assumed \(W\) was a walk, we had to do this using different edges,

so we used \(2a\) edges.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*Only if. *If \(G\) has a closed Eulerian walk, then all vertices of \(G\) must have even degree.

On the other hand, \(W\) contains **all** edges of \(G\),

so \(A\) cannot have any additional edges.

Therefore the degree of \(A\) is \(2a\).

This shows that the degree of any vertex

other than the starting point \(S\) of \(W\) is even.

The starting vertex is also the ending vertex,

so it is visited some \(2t\) times + start + end = \(2t+2\); also even.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

Will you get stuck at this point?

**NO**

Can we conclude that we have an Euler Tour?

Say we encounter the vertex that we started from.

Then we do have a closed walk.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

Take any vertex \(S\), and start walking along an edge \(e_1\), to the other endpoint \(A_1\)

of that edge, then walk along any new edge \(e_2\) that starts in \(A_1\).

Continue, using **new** edges at each step, until a closed walk \(C_1\) is formed.

As \(G\) is finite, such a closed walk will always be formed.

The first closed walk will be formed when we first revisit a vertex already visited.

We cannot get stuck at some vertex before completing a closed walk (why?).

If \(C_1=G\), then we are done.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

If not, then choose a vertex \(V\) in \(C_1\) so that \(C_1\) does not contain all edges adjacent to \(V\).

Let us now omit all edges of \(C_1\) from \(G\).

We get a graph in which again all vertices have even degree.

Starting at \(V\), let us take another closed walk \(C_2\) in the remaining graph.

If \(C_1=G\), then we are done.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

We can then unite \(C_1\) and \(C_2\) into **one closed walk** in \(G\).

Indeed, if we start walking by \(C_1\), we can stop at \(V\), walk through \(C_2\), then complete our walk by using the remaining part of \(C_1\).

If the new walk \(C_1 \cup C_2\) contains all edges of \(G\), we are done.

If not, then let us omit \(C_1 \cup C_2\) from \(G\),

and find a new closed walk \(C_3\) in the remaining graph.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

Since \(G\) is finite, this procedure has to stop after a finite # of steps.

Therefore, after a finite number of steps,

\(C_1 \cup C_2 \cup \cdots \cup C_k\)

will be a closed walk containing all edges of \(G\). 🎉

In this graph,

every vertex has

even degree;

yet there is no closed

Euler tour.

**Theorem. **A graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's try to prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

If \(C_1=G\), then we are done.

If not, then choose a vertex \(V\) in \(C_1\) so that \(C_1\) does not contain all edges adjacent to \(V\).

Let us now omit all edges of \(C_1\) from \(G\).

We get a graph in which again all vertices have even degree.

Starting at \(V\), let us take another closed walk \(C_2\) in the remaining graph.

**Theorem. **A *connected *graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

If a walk does not touch any vertex twice, then we call it a path.

**Definition.** If the graph \(G\) has the property that

**for any two vertices** \(x\) and \(y\), one can find a path from \(x\) to \(y\),

then we say that \(G\) is a *connected graph*.

**Theorem. **A *connected *graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

If \(C_1=G\), then we are done.

If not, then choose a vertex \(V\) in \(C_1\) so that \(C_1\) does not contain all edges adjacent to \(V\).

Let us now omit all edges of \(C_1\) from \(G\).

We get a graph in which again all vertices have even degree.

Starting at \(V\), let us take another closed walk \(C_2\) in the remaining graph.

**Theorem. **A *connected *graph \(G\) has a closed Eulerian walk if and only if all vertices of \(G\) have even degree.

**Let's prove this:**

*If. *All vertices of \(G\) have even degree \(\implies\) \(G\) has a closed Eulerian walk.

Let us assume that there is no such vertex \(V\).

As \(C_1\) contains less edges than \(G\), and supposedly \(C_1\) contains all edges adjacent to all vertices it contains, there must be a vertex \(A\) that is not in \(C_1\).

However, \(G\) is a connected graph, so there must be a path connecting \(A\) to some vertex in \(C_1\), say \(B\).

Start walking on this path \(p\) from \(A\) to \(B\).

When you hit a vertex in \(C_1\) [may be \(B\) or not] for first time on \(p\),

you will reach it via an edge not in \(C_1\).

__Food for Thought__

What about graphs with exactly two vertices of odd degree (say \(x\) and \(y\))?

Can you adapt this proof to show the existence of an open Euler tour that starts at \(x\) and ends at \(y\)?

__Food for Thought__

What about directed graphs?

Can you adapt this proof to show

the existence of an closed Euler tour if

every vertex has equal indegree and outdegree?