• No results found

Euler Paths and Euler Circuits

N/A
N/A
Protected

Academic year: 2022

Share "Euler Paths and Euler Circuits"

Copied!
66
0
0

Loading.... (view fulltext now)

Full text

(1)

Euler Paths and Euler Circuits

AnEuler path is a path that uses every edge of a graph exactly once.

AnEuler circuit is a circuit that uses every edge of a graph exactly once.

I An Euler path starts and ends atdifferent vertices.

I An Euler circuit starts and ends at the samevertex.

(2)

Euler Paths and Euler Circuits

B

C

E D A

B

C

E D A

An Euler path: BBADCDEBC

(3)

Euler Paths and Euler Circuits

B

C

E D A

B

C

E D A

Another Euler path: CDCBBADEB

(4)

Euler Paths and Euler Circuits

B

C

E D A

B

C

E D A

An Euler circuit: CDCBBADEBC

(5)

Euler Paths and Euler Circuits

B

C

E D A

B

C

E D A

Another Euler circuit: CDEBBADC

(6)

Euler Paths and Euler Circuits

Is it possible to determine whether a graph has an Euler path or an Euler circuit, without necessarily having to find one explicitly?

(7)

The Criterion for Euler Paths

Suppose that a graph has an Euler path P.

For every vertex v other than the starting and ending vertices, the path P entersv the samenumber of times that it leaves v (say s times).

Therefore, there are 2s edges having v as an endpoint. Therefore, all vertices other than the two endpoints of P must be even vertices.

(8)

The Criterion for Euler Paths

Suppose that a graph has an Euler path P.

For every vertex v other than the starting and ending vertices, the path P enters v the samenumber of times that it leaves v (say s times).

Therefore, there are 2s edges having v as an endpoint. Therefore, all vertices other than the two endpoints of P must be even vertices.

(9)

The Criterion for Euler Paths

Suppose that a graph has an Euler path P.

For every vertex v other than the starting and ending vertices, the path P enters v the samenumber of times that it leaves v (say s times).

Therefore, there are 2s edges having v as an endpoint.

Therefore, all vertices other than the two endpoints of P must be even vertices.

(10)

The Criterion for Euler Paths

Suppose that a graph has an Euler path P.

For every vertex v other than the starting and ending vertices, the path P enters v the samenumber of times that it leaves v (say s times).

Therefore, there are 2s edges having v as an endpoint.

Therefore, all vertices other than the two endpoints of P must be even vertices.

(11)

The Criterion for Euler Paths

Suppose the Euler path P starts at vertex x and ends at y .

Then P leaves x one more time than it enters, and leaves y one fewer time than it enters.

Therefore,the two endpoints of P must be odd vertices.

(12)

The Criterion for Euler Paths

Suppose the Euler path P starts at vertex x and ends at y .

Then P leaves x one more time than it enters, and leaves y one fewer time than it enters.

Therefore,the two endpoints of P must be odd vertices.

(13)

The Criterion for Euler Paths

Suppose the Euler path P starts at vertex x and ends at y .

Then P leaves x one more time than it enters, and leaves y one fewer time than it enters.

Therefore,the two endpoints of P must be odd vertices.

(14)

The Criterion for Euler Paths

The inescapable conclusion (“based on reason alone!”):

If a graph G has an Euler path, then it must have exactly two odd vertices.

Or, to put it another way,

If the number of odd vertices in G is anything other than 2, then G cannot have an Euler path.

(15)

The Criterion for Euler Circuits

I Suppose that a graph G has an Euler circuit C .

I For every vertex v in G , each edge having v as an endpoint shows up exactly once in C .

I The circuit C entersv the same number of times that it leavesv (say s times), so v has degree 2s.

I That is, v must be an even vertex.

(16)

The Criterion for Euler Circuits

I Suppose that a graph G has an Euler circuit C .

I For every vertex v in G , each edge having v as an endpoint shows up exactly once in C .

I The circuit C entersv the same number of times that it leavesv (say s times), so v has degree 2s.

I That is, v must be an even vertex.

(17)

The Criterion for Euler Circuits

I Suppose that a graph G has an Euler circuit C .

I For every vertex v in G , each edge having v as an endpoint shows up exactly once in C .

I The circuit C entersv the same number of times that it leavesv (say s times), so v has degree 2s.

I That is, v must be an even vertex.

(18)

The Criterion for Euler Circuits

I Suppose that a graph G has an Euler circuit C .

I For every vertex v in G , each edge having v as an endpoint shows up exactly once in C .

I The circuit C entersv the same number of times that it leavesv (say s times), so v has degree 2s.

I That is, v must be an even vertex.

(19)

The Criterion for Euler Circuits

The inescapable conclusion (“based on reason alone”):

If a graph G has an Euler circuit, then all of its vertices must be even vertices.

Or, to put it another way,

If the number of odd vertices in G is anything other than 0, then G cannot have an Euler circuit.

(20)

Things You Should Be Wondering

I Does every graph withzero odd vertices have an Euler circuit?

I Does every graph withtwo odd vertices have an Euler path?

I Is it possible for a graph have justone odd vertex?

(21)

How Many Odd Vertices?

(22)

How Many Odd Vertices?

Odd vertices

(23)

How Many Odd Vertices?

6 8

2 4 8

6

Number of odd vertices

(24)

The Handshaking Theorem

The Handshaking Theorem says that

In every graph, the sum of the degrees of all vertices equals twice the number of edges.

If there are n vertices V1, . . . , Vn, with degrees d1, . . . , dn, and there are e edges, then

d1+ d2+ · · · + dn−1+ dn = 2e

Or, equivalently,

e = d1+ d2+ · · · + dn−1+ dn 2

(25)

The Handshaking Theorem

Why “Handshaking”?

If n people shake hands, and the ith person shakes hands di times, then the total number of handshakes that take place is

d1+ d2+ · · · + dn−1+ dn

2 .

(How come? Each handshake involves two people, so the number d1+ d2+ · · · + dn−1+ dn counts every handshake twice.)

(26)

The Number of Odd Vertices

I The number of edges in a graph is d1 + d2+ · · · + dn

2 which must be an integer.

I Therefore, d1+ d2+ · · · + dn must be an even number.

I Therefore, the numbers d1, d2, · · · , dn must include an even number of odd numbers.

I Every graph has an even number of odd vertices!

(27)

The Number of Odd Vertices

I The number of edges in a graph is d1 + d2+ · · · + dn

2

which must be an integer.

I Therefore, d1+ d2+ · · · + dn must be an even number.

I Therefore, the numbers d1, d2, · · · , dn must include an even number of odd numbers.

I Every graph has an even number of odd vertices!

(28)

The Number of Odd Vertices

I The number of edges in a graph is d1 + d2+ · · · + dn

2

which must be an integer.

I Therefore, d1+ d2+ · · · + dn must be an even number.

I Therefore, the numbers d1, d2, · · · , dn must include an even number of odd numbers.

I Every graph has an even number of odd vertices!

(29)

The Number of Odd Vertices

I The number of edges in a graph is d1 + d2+ · · · + dn

2

which must be an integer.

I Therefore, d1+ d2+ · · · + dn must be an even number.

I Therefore, the numbers d1, d2, · · · , dn must include an even number of odd numbers.

I Every graph has an even number of odd vertices!

(30)

Back to Euler Paths and Circuits

Here’s what we know so far:

# odd vertices Euler path? Euler circuit?

0 No Maybe

2 Maybe No

4, 6, 8, . . . No No

1, 3, 5, . . . No such graphs exist!

Can we give a better answer than “maybe”?

(31)

Euler Paths and Circuits — The Last Word

Here is the answer Euler gave:

# odd vertices Euler path? Euler circuit?

0 No Yes*

2 Yes* No

4, 6, 8, . . . No No

1, 3, 5, No such graphs exist

*Provided the graph is connected.

Next question: If an Euler path or circuit exists, how do you find it?

(32)

Euler Paths and Circuits — The Last Word

Here is the answer Euler gave:

# odd vertices Euler path? Euler circuit?

0 No Yes*

2 Yes* No

4, 6, 8, . . . No No

1, 3, 5, No such graphs exist

*Provided the graph is connected.

Next question: If an Euler path or circuit exists, how do you find it?

(33)

Bridges

Removing a single edge from a connected graph can make it disconnected. Such an edge is called abridge.

(34)

Bridges

Removing a single edge from a connected graph can make it disconnected. Such an edge is called abridge.

(35)

Bridges

Removing a single edge from a connected graph can make it disconnected. Such an edge is called abridge.

(36)

Bridges

Loops cannot be bridges, because removing a loop from a graph cannot make it disconnected.

delete loop e e

(37)

Bridges

If two or more edges share both endpoints, then removing any one of them cannot make the graph disconnected. Therefore, none of those edges is a bridge.

edges

A C

D B

multiple delete

(38)

Bridges

If two or more edges share both endpoints, then removing any one of them cannot make the graph disconnected. Therefore, none of those edges is a bridge.

edges

A C

D B

multiple delete

(39)

Finding Euler Circuits and Paths

“Don’t burn your bridges.”

(40)

Finding Euler Circuits and Paths

Problem: Find an Euler circuit in the graph below.

A

B

E F

C D

(41)

Finding Euler Circuits and Paths

There are two odd vertices, A and F. Let’s start at F.

A

B

E F

C D

(42)

Finding Euler Circuits and Paths

Start walking at F. When you use an edge, delete it.

A

B

E F

C D

(43)

Finding Euler Circuits and Paths

Path so far: FE

A

B

E F

C D

(44)

Finding Euler Circuits and Paths

Path so far: FEA

A

B

E F

C D

(45)

Finding Euler Circuits and Paths

Path so far: FEAC

A

B

E F

C D

(46)

Finding Euler Circuits and Paths

Path so far: FEACB

A

B

E F

C D

(47)

Finding Euler Circuits and Paths

Up until this point, the choices didn’t matter.

But now, crossing the edge BA would be a mistake, because we would be stuck there.

The reason is that BA is a bridge. We don’t want to cross (“burn”?) a bridge unless it is the only edge available.

(48)

Finding Euler Circuits and Paths

Up until this point, the choices didn’t matter.

But now, crossing the edge BA would be a mistake, because we would be stuck there.

The reason is that BA is a bridge. We don’t want to cross (“burn”?) a bridge unless it is the only edge available.

(49)

Finding Euler Circuits and Paths

Up until this point, the choices didn’t matter.

But now, crossing the edge BA would be a mistake, because we would be stuck there.

The reason is that BA is a bridge. We don’t want to cross (“burn”?) a bridge unless it is the only edge available.

(50)

Finding Euler Circuits and Paths

Path so far: FEACB

A

B

E F

C D

(51)

Finding Euler Circuits and Paths

Path so far: FEACBD.

A

B

E F

C D

(52)

Finding Euler Circuits and Paths

Path so far: FEACBD. Don’t cross the bridge!

A

B

E F

C D

(53)

Finding Euler Circuits and Paths

Path so far: FEACBDC

A

B

E F

C D

(54)

Finding Euler Circuits and Paths

Path so far: FEACBDC Now we have to cross the bridge CF.

A

B

E F

C D

(55)

Finding Euler Circuits and Paths

Path so far: FEACBDCF

A

B

E F

C D

(56)

Finding Euler Circuits and Paths

Path so far: FEACBDCFD

A

B

E F

C D

(57)

Finding Euler Circuits and Paths

Path so far: FEACBDCFDB

A

B

E F

C D

(58)

Finding Euler Circuits and Paths

Euler Path: FEACBDCFDBA

A

B

E F

C D

(59)

Finding Euler Circuits and Paths

Euler Path: FEACBDCFDBA

A

B

E F

C D

(60)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices. 2. If there are 0 odd vertices, start anywhere. If there are 2

odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge. 4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(61)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices.

2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge. 4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(62)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices.

2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge. 4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(63)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices.

2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge.

4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(64)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices.

2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge.

4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(65)

Fleury’s Algorithm

To find an Euler path or an Euler circuit:

1. Make sure the graph has either 0 or 2 odd vertices.

2. If there are 0 odd vertices, start anywhere. If there are 2 odd vertices, start at one of them.

3. Follow edges one at a time. If you have a choice between a bridge and a non-bridge,always choose the non-bridge.

4. Stop when you run out of edges.

This is called Fleury’s algorithm, and it always works!

(66)

Fleury’s Algorithm: Another Example

G

K L

J M

H E

A

F C

B D

N O P

Q

References

Related documents

Formally, this modification changes the definition of low(v) to the smallest starting time among all vertices in the same strong component as v that v can reach by a path of tree

Theorem 1.5 For every vertex v of an f -critical graph G, v is adjacent to at least 2f (v) f -maximum vertices and G contains at least three f -maximum vertices.. There are some

The inclusive edge (vertex, mixed) connectivity of a vertex v is the minimum number of edges (vertices, graph elements) whose removal yields a subgraph in which v is a

Case 1. We find a vertex v such that T ∪ {v} are the vertices of a complete graph on seven vertices and each edge is colored green and blue except at most three edges. We find a

By a related argument, we can see that the number of different ways of prepending or inserting the vertex v into a path P is bounded above by the number of vertices of P that

The single-source shortest path problem, in which we have to find shortest paths from a source vertex v to all other vertices as veins in the body veins

The discover edges form a spanning tree of the cc For each vertex v at level I, the path of the BSF. tree T between s and v has I edges and any other path of G between s and v has

According to this definition, the colour of a vertex V , that is the number of edges through V admitting V as i-th vertex, is determined by the geometric structure of the graph around