You are on page 1of 70

EULERIAN GRAPHS,

DE BRUIJN GRAPHS
AND SEQUENCES
1

EULERIAN GRAPHS

Definitions

A walk is trail, if for all. An Euler trail (Euler circuit) of a


graph G is a trail that traverses every edge only once.

Note: We call a closed trail a circuit when we do not specify the


first vertex but keep the list in the cyclic order
An Euler tour of G is a closed Euler trail.
A connected graph G is an Eulerian if it has an Euler tour.
An Euler path is a path that uses every edge of a graph
exactly once.
3

Note: An Euler path starts and ends at different vertices while an


Euler circuit starts and ends at the same vertex.
An even graph is a graph with degree all even.
A vertex is odd [even] when its degree is odd [even].
A maximal path in a graph G is a path P in G that is not
contained in a longer path.
When a graph is finite, no path can extend forever, so
maximal (non-extemdible) paths exist.

Example of Euler Path


1. Euler path: BBADCDEBC
2. Euler path:CDCBBADEB

Example of Euler Circuit

11
10

2
3

7
6

8
4
5

Euler Circuit: ABCFGHCGEDFA


6

Lemma: If every vertex of G has degree at least 2, then G


contains a cycle.(1.2.25)
Proof:
Let P a maximal path in G , and let u be an endpoint in P. Since
P is a maximal ( cannot be extended), every vertex adjacent to u
must already be in P. Since u has a degree at least two, there is
an edge e extending from u to some other vertex v in P, where e
is not in P. The edge e together with the section of P from u to v
completes a cycle.

Theorem 1. A graph G is Eulerian if and only


if it has at most one nontrivial component
and its vertices all have even degree.
Proof:
Necessity. Suppose that G has an Eulerian circuit C. Each passage of C
through a vertex uses two incident edges and the first edge is paired
with the last at the first vertex. Hence every vertex has even degree.
Also, two edges can be in the same trail only when they lie in the same
component, so there is at most one non trivial component.
8

Sufficiency. Assuming that the condition holds, we obtain an


Eulerian circuit using induction on the nember of edges, m.
Basis step: m=0. A closed trail consisting of one vertex suffices.

Induction step m >0.


When even degrees, each vertex in the nontrivial component
of G has degree at least 2.
By Lemma 1.2.25, the the nontrivial component has a cycle C
Let G be the graph obtained from G by deleting E(C)
Since C has 0 or 2 edges at each vertex, each component of G
is also an even graph.
9

Continuation of Induction step m >0.


Since each component is also connected and has fewer than
m edges, we can apply the induction hypothesis to conclude
that each component of G has an Eulerian Circuit.
To combine these into an Eulerian circuit of G, we traverse
C, but , but when a component of G is entered for the first
time we detour along an Eulerian Circuit of component.
This circuit ends at the vertex where we began the detour.
When we have completed the traversal of C, we have
completed an Eulerian circuit of G.
10

The Handshaking Theorem or The Hand Shaking


Lemma. In every graph, the sum of the degrees of
all vertices equals twice the number of edges.
If there are n vertices , with degrees, and there are e edges,
then
Or, equivalently,

11

If n people shake hands, and the i th person shakes hands di


times, then the total number of handshakes that take place is

How come? Each handshake involves two people, so the


number
counts every handshake twice.

12

The Number of Odd Vertices


The number of edges in a graph is
an integer.

which must be

Therefore,
must be an even number.
Therefore, the numbers
must include an even number
of odd numbers.
Every graph has an even number of odd vertices.

13

Theorem 2. A connected graph has an Euler


trail if and only if it has 0 or 2
vertices of odd degree.

14

Proof:
If G has an Euler trail , thenas in the proof of Theorem1 ,
each vertex has an even degree.
Assume then that G is connected and has at most two
vertices of odd degree. If G has no vertices of odd degree then,
by Theorem 1, G has an Euler trail.

15

Otherwise by the handshaking lemma, every graph


has an even number of vertices with odd degree and
therefore G has exactly two vertices, say u and v. Let H
be a graph obtained form G by adding the vertex w, and
the edges uw and vw. In H every vertex has an even

degree, and hence it has Euler tour, say . Here


the
beginning part is an Euler trail of G.

16

All the vertices of the graph below have an even degree. By


Theorem 1, it is an Euler Graph and by Theorem 2 it has an
Euler trail( Euler Circuit).
Euler Trail( Euler
Circuit):
BEDABEFCB

4
1

17

7
8

The graph on the left has 2


vertices of odd degrees. So,
by Theorem 2, it has an
Euler trail. However, it is
not an Euler graph. It is just
a semi-Eulerian Graph.
Euler Trail: ECDFABCF

18

FLEURYS
ALGORITHM
19

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.

20

Algorithms
There are many types of problems that can be solved by simply
following a set of procedural rulesvery specific rules like when
you get to this point, do this, ... after you finish this, do that, and
so on. Given a specific problem X, an algorithm for solving X is
a set of procedural rules that, when followed, always lead to
some sort of solution to X. X need not be a mathematics
problemalgorithms are used, sometimes unwittingly, in all
walks of life:

21

Algorithms
directions to find someones house, the instructions for
assembling a new bike, or a recipe for baking an apple pie are all
examples of real-life algorithms. A useful analogy is to think of
the problem as a dish we want to prepare and the algorithm as a
recipe for preparing that dish. In mathematics, algorithms are
either formula driven (you just apply the formula or formulas to
the appropriate inputs) or directive driven (you must follow a
specific set of directives).

22

Fleurys 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.

23

Fleurys 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, as
illustrated in
Fig.
5-18.

24

Fleurys 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-be-traveled 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.

25

FLEURYS ALGORITHM FOR FINDING AN EULER


CIRCUIT (PATH)

Preliminaries. Make sure that the graph is connected


and either (1) has no odd vertices (circuit) or (2) has just
two odd vertices (path).
Start. Choose a starting vertex. [In case (1) this can be
any vertex; in case (2) it must be one of the two odd
vertices.]

26

FLEURYS ALGORITHM FOR


FINDING AN EULER CIRCUIT (PATH)
Intermediate steps. At each step, if you have a choice,
dont choose a bridge of the yet-to-be-traveled part of
the graph. However, if you have only one choice, take it.
End. When you cant travel any more, the circuit (path)
is complete. [In case (1) you will be back at the starting
vertex; in case (2) you will end at the other odd vertex.]

27

Fleurys Algorithm Bookkeeping


In implementing Fleurys algorithm it is critical to separate the
past (the part of the graph that has already been traveled) from
the future (the part of the graph that still needs to be traveled).
While there are many different ways to accomplish this (you are
certainly encouraged to come up with one of your own), a fairly
reliable way goes like this: Start with two copies of the graph.
Copy 1 is to keep track of the future; copy 2 is to keep track of
the past.

28

Fleurys Algorithm Bookkeeping


Every time you travel along an edge, erase the edge from copy 1,
but mark it (say in red) and label it with the appropriate number
on copy 2. As you move forward, copy 1 gets smaller and copy 2
gets redder. At the end, copy 1 has disappeared; copy 2 shows
the actual Euler circuit or path.

29

Example 5.20

Implementing Fleurys Algorithm

The graph in Fig. 5-19(a) is a very simple graph it would be


easier to find an Euler circuit just by trial-and-error than by using
Fleurys algorithm. Nonetheless, we will do it using Fleurys
algorithm. The real purpose of
the example is to see the algorithm at
work.Each step of the algorithm is
explained in Figs. 5-19(b) through (h).
30

Example 5.20

Implementing Fleurys Algorithm

Start: We can pick any starting point we want. Lets say we start at
F.

31

Example 5.20

Implementing Fleurys Algorithm

Step 1: Travel from F to C. (Could have also gone from F to D.)

32

Example 5.20

Implementing Fleurys Algorithm

Step 2: Travel from C to D. (Could have also gone to A or to E.)

33

Example 5.20

Implementing Fleurys Algorithm

Step 3: Travel from D to A. (Could have also gone to B but not to


F DF is a bridge!)

34

Example 5.20

Implementing Fleurys Algorithm

Step 4: Travel from A to C. (Could have also gone to E but not to B


AB is a bridge!)

35

Example 5.20

Implementing Fleurys Algorithm

Step 5: Travel from C to E. (There is no choice!)

36

Example 5.20

Implementing Fleurys Algorithm

Steps 6, 7, 8, and 9: Only one


way to go
at each step.

37

Example 5.21

Fleurys Algorithm for Euler Paths

We will apply Fleurys algorithm to the graph in Fig. 5-20.

38

Example 5.21

Fleurys Algorithm for Euler Paths

Since it would be a little impractical to show each step of the


algorithm with a separate picture as we did in Example 5.20, you
are going to have to do some of the work. Start by making two
copies of the graph.

Start. This graph has two odd vertices, E and J. We can pick
either one as the starting vertex. Lets start at J.

39

Example 5.21

Fleurys Algorithm for Euler Paths

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.)

Step 2. From K we have three choices (B, L, or H). Any of these


choices is OK. Say we choose B. (Now erase KB from copy 1
and mark and label KB with a 2 on copy 2.)
40

Example 5.21

Fleurys Algorithm for Euler Paths

Step 3. From B we have three choices (A, C, or J). Any of these


choices is OK. Say we choose C. (Now erase BC from copy 1
and mark and label BC with a 3 on copy 2.)

Step 4. From C we have three choices (D, E, or L). Any of these


choices is OK. Say we choose L. (EMLthats shorthand for
erase, mark, and label.)
41

Example 5.21

Fleurys Algorithm for Euler Paths

Step 5. From L we have three choices (E, G, or K). Any of


these choices is OK. Say we choose K. (EML.)

Step 6. From K we have only one choice to H. We choose H.


(EML.)

42

Example 5.21

Fleurys Algorithm for Euler Paths

Step 7. From H we have three choices (G, I, or J). We


should not choose G, as
HG is a bridge of the
yet-to-be-traveled part
of the graph (see Fig. 521).

43

Example 5.21

Fleurys Algorithm for Euler Paths

Step 7. Either of the other two choices is OK. Say we


choose J.
(EML.)

44

Example 5.21

Fleurys Algorithm for Euler Paths

Step 8. From J we have three choices (A, B, or I), but we


should not choose I, as JI has just become a bridge. Either of the
other two choices is OK. Say we choose B. (EML)

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.

45

Example 5.21

Fleurys Algorithm for Euler Paths

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.

The completed Euler path (one of hundreds of possible ones) is


shown in Fig. 5-22.

46

Example 5.21

Fleurys Algorithm for Euler Paths

47

DE BRUIJN
GRAPHS AND
SEQUENCES
48

De Bruijn Graphs
A graph is a an ordered pair G = (V;E) where V is a set of vertices
called nodes, together with a set E of edges which are pairs of
nodes.
Directed graphs, graphs whose edges are an ordered pair of nodes.
A subgraph, G = (V ;E), of a graph G = (V;E), is a graph on a
subset V of V with the property that every edge e E with
endpoints in V is also in E.

49

Directed multigraph G(V, E) consists of set of vertices, V


and
multiset of directed edges, E
Otherwise, like a directed graph
Nodes indegree = # incoming edges
V = { a, b, c, d }
Nodes outdegree = # outgoing edges
E = { (a, b), (a, b), (a, b), (a, c), (c, b) }
De Bruijn graph is a directed multigraph

50

A (1 n) is called a successor of node (1 n) if there is


an edge from (1 n) to (1 n). Likewise, (1 n) is
said to be a predecessor of (1 n).
Two nodes are adjacent nodes if there is an edge between them and
that two edges are adjacent edges if they share a common node.
A De Bruijn graph is a directed graph with dn nodes labeled by ntuples over a d-character alphabet (denoted by juxtaposition). The
edges are defined to be ordered pairs of the form ((1 n), (2
n n+1)) where n+1 is any character in the alphabet.
We will denote the De Bruijn graph (d, n)
(Note: d=n-1)
51

Successor

Predecessor

Node

52

Few basic properties of De Bruijn graphs:


1)
The number of nodes in B(d, n) is dn since each n-tuple is a node.
2) The number of edges in B(d, n) is dn+1 since there are nodes and out-degree
of d on each node.
3) Every node in B(d, n) has out-degree d since every successor of (1 n)
has the form (2 3 n ) and there are d choices for .
4) Every node in B(d, n) has in-degree d since if we examine the predecessors
of (1 n) we see that they will be those which look like (1 n-1)
with any of the d choices for .
5) Since the edges are defined explicitly, we see that the graph B(d, n) is unique
for fixed d and n.

Example: Construct the De Bruijn Graph of :


A={A,B} , B(2,3)
Since d=2, n=3 the number of nodes is .
So, the graph to be constructed has 4 nodes or vertices.
The combinations that can be made from S={A,B} =
AA,AB,BB,BA or AAABBBBA
The n-tuples or 3-tuples are:
(n-1)-tuples (nodes) or d:
54

Constructed Graph:
3.

2.

1.

AA

AA, AA

5.

AA AA, AA AB, AB BB, BB BB

AA, AA AA, AB

4.

AA AA, AA AB, AB BB

6.

AA AA, AA AB, AB BB, BB BB, BB BA

Note: When graphing the De Bruijn, there is an edge connecting between the left and the right
nodes.
55

DE BRUIJN
SEQUENCES
56

A De Bruijn Sequence B(d,n) is a


cylic sequence of an alphabet A (that
consists of d elements ) in which
EVERY possible subsequence of
length n appears as a sequence of
consecutive letters EXACTLY once.

57

De Bruijn cycles

1.4.25

Application:
There are 2n binary strings of length n.
Is there a cyclic arrangement of 2 n binary digits such that the 2 n
strings of n consecutive digitals are all distinct?
Example: For n =4, (0000111101100101) works.

0000 0001 0011 0111 1111 1110 1101 1011


1

0
0

0
1

0
1
Graph Theory

0
Ch. 1. Fundamental Concept

1
58

De Bruijn cycles

1.4.25

We can use such an arrangement to keep track of the position


of a rotating drum.
One drum has 2n rotational positions.
A band around the circumference is split into 2n portions that
can be coded 0 or 1.
Sensors read n consecutive portions.
If the coding has the property specified above, then the
position of the drum is determined by the string read by the
sensors.

Graph Theory

Ch. 1. Fundamental Concept

59

De Bruijn cycles

1.4.25

To obtain such a circular arrangement,


define a digraph Dn whose vertices are the binary (n1)-tuples.
Put an edge from a to b if the last n-2 entries of a
agree with the first n-2 entries of b.
Label the edge with the last entry of b.

Graph Theory

Ch. 1. Fundamental Concept

60

De Bruijn cycles

1.4.25

Below we show D4..

Put an edge from a to b if the last n-2 entries of a


agree with the first n-2 entries of b.
Label the edge with the last entry of b.

0
1

Graph Theory

011

001

000

0
1

1
100

Ch. 1. Fundamental Concept

101

010
0

1
0

111
0

110

61

De Bruijn cycles

1.4.25

We next prove that Dn is Eulerian and show how an Eulerian circuit yields the desired
circular arrangement.

Graph Theory

Ch. 1. Fundamental Concept

62

Theorem. The digraph Dn of Application 1.4.25 is Eulerian, and the edge labels on
the edges in any Eulerian circuit of Dn form a cyclic arrangement in which the
2n consecutive segments of length n are distinct. 1.4.26

Proof:
We show
first that Dn is Eulerian.
Then the labels on the edges in any Eulerian circuit
of Dn form a cyclic arrangement in which the 2n
consecutive segments of length n are distinct.
Graph Theory

Ch. 1. Fundamental Concept

63

Theorem. The digraph Dn is Eulerian 1.4.26


Proof: 1/2

Every vertex has out-degree 2


because we can append a 0 or a 1 to its name to obtain the name
of a successor vertex.

Similarly, every vertex has in-degree 2,


because the same argument applies when moving in reverse and
putting a 0 or a 1 on the front of the name.
011

001

101

Graph Theory

Ch. 1. Fundamental Concept

111

110

64

Theorem. The digraph Dn is Eulerian 1.4.26

Proof: 2/2
Also, Dn is strongly connected,
because we can reach the vertex b=(b1,..,bn-1) from any
vertex by successively follows the edges labeled b1,
..,bn-1.

Thus Dn satisfies the hypotheses of Theorem 1.4.24


and is Eulerian.
a

001

1
0

000
0

Graph Theory

0
1 1

011

1
1

100
Ch. 1. Fundamental Concept

0
0

1
101

010

111
0

110

65

Theorem. The labels on the edges in any Eulerian circuit of Dn form a cyclic
arrangement in which the 2n consecutive segments of length n are distinct.
1.4.26

Proof: 1/4
Let C be an Eulerian circuit of Dn. Arrival at vertex
a=(a1,..,an-1) must be along an edge with label an-1
because the label on an edge entering a vertex agrees
with the last entry of the name of the vertex.
a

001

1
0

000
0

Graph Theory

0
1

011

1
1

100
Ch. 1. Fundamental Concept

0
0

1
101

010

111

0
110

66

Theorem. The labels on the edges in any Eulerian circuit of Dn form a cyclic
arrangement in which the 2n consecutive segments of length n are distinct.
1.4.26

Proof: 2/4
The successive earlier labels
have been an-2,..,a1 in order.

(looking backward)

must

because we delete the front and shift the reset to


obtain the reset of the name at the head
a

001

1
0

000
0

Graph Theory

0
1

011

1
1

100
Ch. 1. Fundamental Concept

0
0

1
101

010

111

0
110

67

Theorem. The labels on the edges in any Eulerian circuit of Dn form a cyclic
arrangement in which the 2n consecutive segments of length n are distinct.
1.4.26

Proof: 2/4
If C next uses an edge with label an, then the list
consisting of the n most recent edge labels at that time
is a1,..an.
a

001

1
0

000

0
1 1

100
Graph Theory

1
0
0

Ch. 1. Fundamental Concept

b
1

1
101

010
0

011

111

0
110
68

Theorem. The labels on the edges in any Eulerian circuit of Dn form a cyclic
arrangement in which the 2n consecutive segments of length n are
distinct. 1.4.26

Proof: 3/4
Since
the 2n-1 vertex labels are distinct, and
the two out-going edges have distinct labels, and
we traverse each edge exactly once

Distinct vertex
label

011 0
011 1

Graph Theory

Ch. 1. Fundamental Concept

Distinct labels on
out-going edges
69

Theorem. The labels on the edges in any Eulerian circuit of Dn form a cyclic
arrangement in which the 2n consecutive segments of length n are
distinct. 1.4.26

Proof: 4/4
We have shown that the 2n strings of length n in the
circular arrangement given by the edge labels along C
are distinct.

Graph Theory

Ch. 1. Fundamental Concept

70

You might also like