Euler Circuits
Euler Circuits
Euler Circuits!
Topics in Contemporary Mathematics!
MA 103!
Summer II, 2013!
2!
Content!
Euler Circuit Problems!
What Is a Graph? !
Graph Concepts and Terminology!
Graph Models!
Eulers Theorems!
Fleurys Algorithm!
Eulerizing Graphs!
3!
4!
Routing Problems!
What is a routing problem? To put it in the most general way, routing
problems are concerned with finding ways to route the delivery of
goods and/or services to an assortment of destinations. !
The goods or services in question could be packages, mail,
newspapers, pizzas, garbage collection, bus service, and so on. !
The delivery destinations could be homes, warehouses, distribution
centers, terminals, and the like.
5!
6!
7!
Example
8!
Example!
Walking the Hood!
9!
Example
Being a practical person, the security guard would like the answers to two
questions: !
(1)Is it possible to start and end at S, cover every block of the
neighborhood, and pass through each block just once?!
(2)If some of the blocks will have to be covered more than once, what is
an optimal route that covers the entire neighborhood?!
Optimal here means with the minimal amount of walking.
10!
Example
11!
Example
A photographer needs to drive across each bridge once for the photo
shoot. Moreover, since there is a $25 toll (the locals call it a
maintenance tax) every time an out-of-town visitor drives across a
bridge, the photographer wants to minimize the total cost of his trip and
to recross bridges only if it is absolutely necessary. !
What is the optimal (cheapest) route for him to follow?!
12!
Example
Childs Play!
The Figure on the next slide shows a few simple line drawings. The name
of the game is to trace each drawing without lifting the pencil or
retracing any of the lines. !
These kinds of tracings are called unicursal tracings. (When we end in the
same place we started, we call it a closed unicursal tracing; when we start
and end in different places, we call it an open unicursal tracing.) !
13!
Example
Childs Play!
14!
What Is a Graph?
Euler circuit problems can all be tackled by means of a single unifying
mathematical conceptthe concept of a graph.
The most common way to describe a graph is by means of a picture.
The basic elements of such a picture are:!
a set of dots called the vertices of the graph and
a collection of lines called the edges of the graph. !
On the surface, thats all there is to itlines connecting dots! Below the
surface there is a surprisingly rich theory. Lets explore a few basic
concepts first.
15!
Example
16!
Example
17!
Example
18!
Example
19!
Example
20!
Example
21!
Example
Relationship Graphs
22!
Example
Relationship Graphs
23!
Example
Pure Isolation
24!
Example
Pictures Optional
Suppose you are given the following information about a graph: The
vertex set is V = {A, D, L, and R}, and the edge set is!
E = {AD, AL, AL, AR, AR, DL, DR}.!
But where is the picture? You are told that if you really want a picture,
you can make up your own. Thats fine, but where should you place the
vertices? What should the edges look like?!
Good news: These issues are irrelevant! You have total freedom to place
the vertices anywhere you please, and as long as you connect the right
pairs of vertices, you can connect them any way you like!!
25!
Example
Pictures Optional
26!
Example
Pictures Optional
While they may look like two totally different pictures to the casual
observer, they both describe the same vertex set V = {A, D, L, and R}
and the same edge set E = {AD, AL, AL, AR, AR, DL, DR}.
27!
Important Point
We think of a graph as a picture consisting of dots and lines, but the
picture is just a visual representation of a more abstract idea: a set of
objects (represented by the vertices of the graph) and a relationship
among pairs of objects (represented by the edges of the graph.) !
All one needs to describe these two things are a vertex setV and an
edge set E. A picture is nice but not essential. !
Thus, if we simply give the vertex set isV = {A, D, L, and R}, and the
edge set isE = {AD, AL, AL, AR, AR, DL, DR}. we have defined a
graph.!
28!
GRAPH
A graph is a structure consisting of a
set of objects (the vertex set) and a list
describing how pairs of objects are
related (the edge set). Relations among
objects include the possibility of an
object being related to itself (a loop) as
well as multiple relations between the
same pair of objects (multiple edges).
29!
Terminology
In this section we will introduce some important concepts and
terminology that are associated with graph theory.!
30!
Example
Adjacency
We say that two vertices in a graph are adjacent if they are joined by
an edge. !
Vertices A and B are adjacent and so are vertices B and C. Vertices C and
D are not adjacent, and neither are vertices A and E. !
31!
Example
Degree of a Vertex
32!
Example
Degree of a Vertex
33!
Example
Paths and circuits both describe trips along the edges of a graph. !
The only real difference between a path and a circuit is that: !
a circuit is a closed trip (the trip ends back at the starting point),
whereas a path is an open trip (the starting and ending points are
different). !
In this context, by a trip (be it a path or a circuit), we mean a sequence
of adjacent edges with the property that an edge can be traveled just
once.
34!
Example
is 3.
35!
Example
A, B, C, A, D,
36!
Example
A, C, B, E, E,
37!
Example
The first two passes are fine, since there are two edges connecting B and!
38!
Example
39!
Example
A graph is connected if you can get from any vertex to any other
vertex along a path. Essentially, this means that the graph is all in one
piece. !
The graph shown
in here is a
connected graph.!
40!
Example
Whereas the graphs
shown in here is a
disconnected
graphs.
41!
42!
Example
43!
Example
44!
Example
The removal of just one edge from a connected graph can sometimes
make the graph disconnected. An edge whose removal makes a
connected graph disconnected is called a bridge. !
45!
46!
Example
Much like Euler paths, we can also define Euler circuits. An Euler
circuit is a circuit that travels through every edge of a connected graph.
Being a circuit, the trip must end where it started and travel along every
edge of the graph once and only once.!
A connected graph cannot have both an Euler path and an Euler circuitit
can have one or the other or neither.!
47!
Example
48!
49!
Example
The graph shown here has neither an Euler path nor an Euler circuit. (We will learn
how to tell that a graph has neither an Euler path nor an Euler circuit later.)!
50!
Modeling
Certain types of problems can be conveniently rephrased as graph
problems.!
The notion of using a mathematical concept to describe and solve a
real-life problem is one of the oldest and grandest traditions in
mathematics. It is called modeling.!
51!
52!
53!
54!
55!
56!
57!
58!
A mail carrier
has to deliver
mail in the
same
Sunnyside
neighborhood. !
Example
The difference between the mail carriers route and the security guards
route is that the mail carrier must make two passes through blocks with
houses on both sides of the street and only one pass through blocks with
houses on only one side of the street; !
and where there are no homes on either side of the street, the mail
carrier does not have to walk at all.!
Example
Recall that unlike the security guard, the mail carrier must make two
passes through every block that has homes on both sides of the street(she
has to physically place the mail in the mailboxes), must make one pass
through blocks that have homes on only one side of the street, and does
not have to walk along blocks where there are no houses. !
Example
Euler s Theroems
In this section we are going to develop the basic theory that will allow
us to determine if a graph has an Euler circuit, an Euler path, or
neither. !
This is important because, as we saw in the previous section, what are
Euler circuit or Euler path questions in theory are real-life routing
questions in practice. !
The three theorems we are going to see next (all thanks to Euler) are
surprisingly simple and yet tremendously useful. !
Example
Example
Example
Example
Example
Child s Play
Example
Childs Play
Here is another graph from the childs play example. This graph is
connected and!
has exactly two odd vertices (C and D).!
By Eulers path theorem,the graph has
an Euler path (open unicursal tracing).
Moreover, we now know that the path
has to start at C and end at D, or vice
versa.!
Example
This graph has four odd!
vertices (A, B, C, and D), !
Child s Play
Example
Child s Play
The full power of Eulers theorems is best appreciated when the graphs
get bigger. !
This graph is not
extremely big, but we can
no longer eyeball an
Euler circuit or path. !
Example
Child s Play
On the other hand, a quick check of the degrees of the vertices shows that
K and I are odd vertices and all the rest are even. !
An open unicursal tracing is
possible as!
long as we start it at K or
I (and end it at the !
other one). Starting anyplace else
will lead to a dead end. Good to
know!!
EULER S SUM OF
DEGREES THEOREM
The sum of the degrees of all the
vertices of a graph equals twice the
number of edges (and therefore is an
even number).
A graph always has an even number
of odd vertices.
Algorithms
When the graph has an Euler circuit or path, how do we find it?!
For small graphs, simple trial-and-error usually works fine, but real-life
applications sometimes involve graphs with hundreds, or even
thousands, of vertices. !
In these cases a trial-and-error approach is out of the question, and
what is needed is a systematic strategy that tells us how to create an
Euler circuit or path. In other words, we need an algorithm.
Fleury s Algorithm
We will now turn our attention to an algorithm that finds an Euler
circuit or an Euler path in a connected graph. Technically speaking,
these are two separate algorithms, but in essence they are identical, so
they can be described as one.!
The idea behind Fleurys algorithm can be paraphrased by that old
piece of folk wisdom: Dont burn your bridges behind you.!
Fleury s Algorithm
In graph theory the word bridge has a very specific meaningit is the
only edge connecting two separate sections (call them A and B) of a
graph.
Fleury s Algorithm
Thus, Fleurys algorithm is based on a simple principle: !
To find an Euler circuit or an Euler path, bridges are the last edges you
want to cross. !
Our concerns lie only on how we are going to get around the yet-to-betraveled part of the graph. Thus, when we talk about bridges that we
want to leave as a last resort, we are really referring to bridges of the
to-be-traveled part of the graph. !
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Start: We can pick any starting point we want. Lets say we start at F.!
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Example
Implementing Fleury s
Algorithm
Example
Example
Start. This graph has two odd vertices, E and J. We can pick either
one as the starting vertex. Lets start at J.!
Example
Step 1. From J we have five choices, all of which are OK. Well
randomly pick K. (Erase JK on copy 1, and mark and label JK with a 1
on copy 2.)!
Example
Example
Example
should not
choose G, as
HG is a bridge
of the yet-to-betraveled part of
the graph (see
Fig. 5-21).
Example
choose
J. (EML.)
Example
Step 9 through 13. Each time we have only one choice. From
B we have to go to A, then to J, I, H, and G.!
Example
Step 14 through 21. Not to belabor the point, lets just cut
to the chase. The rest of the path is given by G, F, E, D, C, E, G, L, E.
There are many possible endings, and you should find a different
one by yourself.
Example
Exhaustive Routes
We will use the term exhaustive route to describe a route that
travels along the edges of a graph and passes through each and every
edge of the graph at least once.!
Exhaustive Routes
Such a route could be an Euler circuit (if the graph has no odd
vertices) or an Euler path (if the graph has two odd vertices), but for
graphs with more than two odd vertices, an exhaustive route will have
to recross some of the edges. This follows from Eulers theorems.!
We are interested in finding exhaustive routes that recross the fewest
number of edges. Why? !
Exhaustive Routes
In many applications, each edge represents a unit of cost. !
The more edges along the route, the higher the cost of the route. In an
exhaustive route, the first pass along an edge is a necessary expense,
part of the requirements of the job. !
Any additional pass along that edge represents a wasted expense
(these extra passes are often described as deadhead travel). !
Thus, an exhaustive route that minimizes cost (optimal exhaustive
route) is one with the fewest number of deadhead edges.!
Eulerizing Graphs
We are now going to see how the theory developed in the preceding
sections will help us design optimal exhaustive routes for graphs with
many (more than two) odd vertices. !
The key idea is that we can turn odd vertices into even vertices by
adding duplicate edges in strategic places. This process is called
eulerizing the graph.
Example
Covering a 4 by 4
Street Grid
Example
Covering a 4 by 4
Street Grid
Open Route
In some situations we need to find an exhaustive route, but there is no
requirement that it be closedthe route may start and end at different
points. !
In these cases we want to leave two odd vertices on the graph
unchanged and change the other odd vertices into even vertices by
duplicating appropriate edges of the graph.!
Semi-eulerization
This process is called a semi-eulerization of the graph. !
When we strategically choose how to do this so that the number of
duplicate edges is as small as possible, we can obtain an optimal
exhaustive open route. !
In this case the route will start at one of the two odd vertices and end
at the other one. !
Example
Parade Route
Lets consider once again the 4 by 4 street grid. Imagine that your job is
to design a good route for a Fourth of July parade that must pass through
each of the 40 blocks of the street grid. !
The key is that when routing a parade, you do
not want the parade to start and end in the
same place. !
In fact, for traffic control it is usually
desirable to keep the starting and ending
points of a parade as far from each other as
possible.!
Example
Parade Route
The fire department has added one additional requirement to the parade
route: The parade has to start at B. !
Your task, then, is to find a semi-eulerization of the graph that leaves B
and one more odd vertex unchanged!
Example
Parade Route
Example
Parade Route
Example
Example
Example
The graph has four odd vertices (R, L, B, and D), so some bridges are
definitely going to have to be recrossed.!
Example
How many and which ones depends on the other parameters of the
problem. (It costs $25 in toll fees to cross a bridge, so the baseline cost
for crossing the 11 bridges is $275. !
Each recrossing is at an additional cost of $25.) The following are a few
of the possible scenarios one might have to consider.
Each one requires a different eulerization and will result in a different
route.!
Example
The photographer needs to start and end his trip in the same
place. This scenario requires an optimal eulerization of the
graph.!
This is not hard to do,
and an optimal route
can be found for a cost
of $325.!
Example
The photographer has the freedom to choose any starting and ending
points for his trip. In this case we can find an optimal semi-!
eulerization of the
graph, requiring only
one duplicate edge. Now
an optimal route is
possible at a cost of
$300.!
Example
The photographer has to start his trip at B and end the trip at L. In this
case we must find a semi-eulerization of the graph where B and L remain
as odd vertices and R and D!
become even vertices. It is possible
to do this with just two duplicate
edges and thus find an optimal
route that will cost $325. !
Example
Example
The graph has 18 odd vertices, shown in red. We now know that the name
of the game is to find an optimal eulerization of this graph. !
In this case the odd vertices pair
up beautifully, and the optimal
eulerization requires only nine !
duplicate edges, shown here.!
Example
All the answers to the security guards questions can now be answered: An
optimal route will require nine deadhead blocks.!
The actual route can be found
using trial and error or Fleurys
algorithm.!
Example
A slightly different problem is the one facing the mail carrier delivering
mail along the streets of the Sunnyside subdivision.!
Much to the mail carriers
pleasant surprise, in the graph
that models her situation all the
vertices are even.!
Example
This means that the optimal route is an Euler circuit, which can be found
once again using Fleurys algorithm (or trial and error if you!
prefer). This mail carrier will not
have to deadhead.!