eulerian graphs, de bruijn graphs and sequences

Post on 02-Dec-2015

13 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Graph Theory

TRANSCRIPT

1

EULERIAN GRAPHS, DE BRUIJN GRAPHS

AND SEQUENCES

2

EULERIAN GRAPHS

3

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.

4

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.

5

1. Euler path: BBADCDEBC

2. Euler path:CDCBBADEB

Example of Euler Path

Example of Euler Circuit

6

1

2

3 7

56

4

8

9

10

11

Euler Circuit: ABCFGHCGEDFA

7

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.

8

Theorem 1. A graph G is Eulerian if and only if it has at m ost 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.

9

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

10

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.

11

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,

12

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.

13

The Number of Odd Vertices

The number of edges in a graph is which must be an integer.

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.

14

Theorem 2. A connected graph has an Euler trail if and only if it has 0 or 2 vertices of odd degree.

15

Proof:

If G has an Euler trail , then as 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.

16

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

17

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

1

2

4

35

6

7

8

Euler Trail( Euler Circuit):

BEDABEFCB

18

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

2

3

4

5

6

7

8

Euler Trail: ECDFABCF

19

FLEURY’S ALGORITHM

20

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.

Algorithms

There are many types of problems that can be solved by simply following a set of procedural rules–very 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 problem–algorithms are used, sometimes unwittingly, in all walks of life:

21

Algorithms

directions to find someone’s 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

Algorithms

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 Fleury’s algorithm can be paraphrased by that old piece of folk wisdom: Don’t burn your bridges behind you.

23

Fleury’s Algorithm

In graph theory the word bridge has a very specific meaning–it is the only edge connecting two separate sections (call them

24

Fleury’s Algorithm

A and B) of a graph, as illustrated in Fig.5-18.

Thus, Fleury’s 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

Fleury’s Algorithm

■ 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.]

FLEURY’S ALGORITHM FOR FINDING AN EULER CIRCUIT (PATH)

26

27

■ Intermediate steps. At each step, if you have a choice, don’t 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 can’t 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.]

FLEURY’S ALGORITHM FOR FINDING AN EULER CIRCUIT (PATH)

28

In implementing Fleury’s 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.”

Fleury’s Algorithm Bookkeeping

29

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.

Fleury’s Algorithm Bookkeeping

30

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 Fleury’s algorithm. Nonetheless, we will do it using Fleury’s algorithm. The real purpose of

Example 5.20 Implementing Fleury’s Algorithm

the example is to see the algorithm at work.Each step of the algorithm is explained in Figs. 5-19(b) through (h).

Start: We can pick any starting point we want. Let’s say we start at F.

31

Example 5.20 Implementing Fleury’s Algorithm

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

32

Example 5.20 Implementing Fleury’s Algorithm

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

33

Example 5.20 Implementing Fleury’s 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 Fleury’s 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 Fleury’s Algorithm

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

36

Example 5.20 Implementing Fleury’s Algorithm

Steps 6, 7, 8, and 9: Only one way to goat each step.

37

Example 5.20 Implementing Fleury’s Algorithm

We will apply Fleury’s algorithm to the graph in Fig. 5-20.

38

Example 5.21 Fleury’s 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.

39

Example 5.21 Fleury’s Algorithm for Euler Paths

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

■ Step 1. From J we have five choices, all of which are OK. We’ll randomly pick K. (Erase JK on copy 1, and mark and label JK with a 1 on copy 2.)

40

Example 5.21 Fleury’s Algorithm for Euler Paths

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

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

41

Example 5.21 Fleury’s Algorithm for Euler Paths

■ Step 4. From C we have three choices (D, E, or L). Any of these choices is OK. Say we choose L. (EML–that’s shorthand for erase, mark, and label.)

42

■ Step 5. From L we have three choices (E, G, or K). Any of these choices is OK. Say we choose K. (EML.)

Example 5.21 Fleury’s Algorithm for Euler Paths

■ Step 6. From K we have only one choice– to H. We choose H. (EML.)

43

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

Example 5.21 Fleury’s Algorithm for Euler Paths

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

44

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

Example 5.21 Fleury’s Algorithm for Euler Paths

choose J. (EML.)

45

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

Example 5.21 Fleury’s Algorithm for Euler Paths

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

46

■ Step 14 through 21. Not to belabor the point, let’s 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 5.21 Fleury’s Algorithm for Euler Paths

The completed Euler path (one of hundreds of possible ones) is shown in Fig. 5-22.

47

Example 5.21 Fleury’s Algorithm for Euler Paths

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

Node’s indegree = # incoming edges

Node’s outdegree = # outgoing edges

De Bruijn graph is a directed multigraph

50

V = { a, b, c, d }E = { (a, b), (a, b), (a, b), (a, c), (c, b) }

● 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 n-tuples 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

52

Successor Predecessor

Node

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.

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:

54

Example: Construct the De Bruijn Graph of :A={A,B} , B(2,3)

(n-1)-tuples (nodes) or d:

55

Constructed Graph:

AA AA, AAAA AA, AA AB, AB BBAA, AA AA, AB

AA AA, AA AB, AB BB, BB BBAA 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.

1. 2. 3.4.

5.6.

56

DE BRUIJN SEQUENCES

57

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.

Graph Theory Ch. 1. Fundamental Concept 58

De Bruijn cycles 1.4.25

• Application:– There are 2n binary strings of length n. – Is there a cyclic arrangement of 2n binary digits such that the 2n

strings of n consecutive digitals are all distinct? – Example: For n =4, (0000111101100101) works.

0000 0001 0011 0111 1111 1110 1101 1011 …

0 00

0

1

11

10

0

11

0

0

1

1

Graph Theory Ch. 1. Fundamental Concept 59

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 60

De Bruijn cycles 1.4.25

• To obtain such a circular arrangement, – define a digraph Dn whose vertices are the binary (n-

1)-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 61

De Bruijn cycles 1.4.25

0 00

0

1

1

110

0

11

0

0

1

1

0

0 0

0

0

0

0

0

1

1

1

1 1 1

1

1

001

000

100

010 101

011

110

111

a b

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.

Below we show D4..

Graph Theory Ch. 1. Fundamental Concept 62

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 63

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 64

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.

001

101

011

110

111

Graph Theory Ch. 1. Fundamental Concept 65

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.

0

0 0

0

0

0

0

0

1

11 1 1

1

1

001

000

100

010 101

011

110

111

a b1

1

Graph Theory Ch. 1. Fundamental Concept 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: 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.

0

0 0

0

0

0

0

0

1

1

1

1 1 1

1

1

001

000

100

010 101

011

110

111

a b

Graph Theory Ch. 1. Fundamental Concept 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

• The successive earlier labels (looking backward) must have been an-2,…..,a1 in order. – because we delete the front and shift the reset to

obtain the reset of the name at the head

0

0 0

0

0

0

0

0

1

1

1

1 1 1

1

1

001

000

100

010 101

0 1 1

110

111

a b

Graph Theory Ch. 1. Fundamental Concept 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: 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.

0

0

1

0

0

0

0

0

1

1

1

1 1 1

1

1

001

000

100

010 101

011

110

111

a b

0

1

Graph Theory Ch. 1. Fundamental Concept 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: 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

011 0

011 1

Distinct vertex label

Distinct labels onout-going edges

Graph Theory Ch. 1. Fundamental Concept 70

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.

top related