• No results found

Euler Paths and Euler Circuits

N/A
N/A
Protected

Academic year: 2020

Share "Euler Paths and Euler Circuits"

Copied!
36
0
0

Loading.... (view fulltext now)

Full text

(1)

Euler Paths & Circuits

Hamilton Paths & Circuits

(2)

Euler Paths

(3)

Review from last lesson

▪ adjacent vertices – vertices that are connected directly and

thus share at least one edge

▪ path – a sequence of adjacent vertices and the edges connecting them, denoted by a list of vertices in order

▪ circuit – a path that begins and ends at the same vertex

path: A,B,F,G,H,M

circuit:

A,B,F,G,L,K,J,E,A

(4)

Definitions

▪ Euler path – a path that travels through every edge of a

graph once and only once.

▪ Euler circuit – a circuit that travels through every edge of a

graph once and only once.

OR – a Euler path that begins and ends at the

same vertex.

So, if the graph is traversable then it has a Euler path!

Every Euler circuit is an Euler path

(5)

Euler’s Rules of Traversability

1. A graph with all even vertices is traversable.

One can start at any vertex and end at same

vertex.

2. A graph with two odd vertices is traversable.

One must start at one odd vertex and

end at the other odd vertex.

3. A graph with more than two odd vertices is

NOT traversable.

NOTE: Rules are only for

connected

graphs.

Euler

Circuit

Euler

Path

(6)

Example

Find the Euler path or circuit, if any.

Even

(2)

Even

(4)

Odd

(3)

Even

(4)

Odd

(3)

2. A graph with two odd vertices is

traversable. One must start at

one odd vertex and end at the

other odd vertex.

(7)

Example

Find the Euler path or circuit, if any.

2. A graph with two odd vertices is

traversable. One must start at

one odd vertex and end at the

other odd vertex.

Euler Path

A

B

C

E

D

Euler Path: C,B,A,E,B,D,E,C,D

Euler Path: C,B,A,E,B,D,E,C

Euler Path: C,B,A,E,B,D

Euler Path: C,B,A,E,B

Euler Path: C,B,A,E

Euler Path: C,B,A

Euler Path: C,B

Euler Path: C

Euler Path:

(8)

Example

Find the Euler path or circuit, if any.

2. A graph with two odd vertices is

traversable. One must start at

one odd vertex and end at the

other odd vertex.

Euler Path

3

2

4

1

6

7

5

8

(9)

Example

Find the Euler path or circuit, if any.

Even

(4)

Even

(2)

Even

(4)

Even

(2)

Even

(2)

Even

(4)

Even

(2)

1. A graph with all even vertices is

traversable. One can start at any

vertex and end at same vertex.

(10)

Example

Find the Euler path or circuit, if any.

A

B

C

E

D

F

G

Euler Circuit:

Euler Circuit: A

Euler Circuit: A,B

Euler Circuit: A,B,C

Euler Circuit: A,B,C,G

Euler Circuit: A,B,C,G,E

Euler Circuit: A,B,C,G,E,C

Euler Circuit: A,B,C,G,E,C,D

Euler Circuit: A,B,C,G,E,C,D,E

Euler Circuit: A,B,C,G,E,C,D,E,F

Euler Circuit: A,B,C,G,E,C,D,E,F,G

Euler Circuit: A,B,C,G,E,C,D,E,F,G,A

1. A graph with all even vertices is

traversable. One can start at any

vertex and end at same vertex.

(11)

Example

Find the Euler path or circuit, if any.

1

2

6

8

7

9

3

Number the Euler Circuit at each step.

1. A graph with all even vertices is

traversable. One can start at any

vertex and end at same vertex.

Euler Circuit

5

(12)

Example

Find the Euler path or circuit, if any.

Even

(4)

Odd

(3)

Odd

(3)

Odd

(3)

Odd

(3)

3. A graph with more than two odd vertices is NOT

traversable.

(13)

Example

Find the Euler path or circuit, if any.

Euler Circuit

1

10

7

14

5

6

2

4

13

12

9

8

Number the Euler Circuit at each step.

(14)

Example

Find the Euler path or circuit, if any.

Euler Path: B, L, D, O, L, O, D, K, O, B, K

What if the Euler path or

(15)

▪ connected graph – a graph in which there is at least one

path connecting any two vertices

▪ disconnected graph – a graph in which there is no path connecting any two vertices

▪ bridge – an edge that, if removed, would make a connected

graph into a disconnected graph

disconnected graph

edge BG is a bridge

(16)

How do we find the

Euler path or Euler circuit?

Fleury’s Algorithm

▪ Check that the graph is connected.

▪ Check that the graph is traversable using Euler’s Rules.

▪ Choose a starting point based on Euler’s Rules.

▪ After each edge is traveled over, erase it to create a reduced graph. You may want to show the erased edge as a dotted line.

▪ When you have a choice between two edges, never take the bridge of a reduced graph. Travel over a bridge only when there is no other alternative.

▪ Continue until you get to the appropriate vertex and the entire graph has been traversed.

(17)

Example

Find the Euler path or circuit, if any.

Is the graph connected?Is the graph traversable?Where do we start?ANYWHERYESYES E

If you have the choice

between two edges, never take the bridge.

Neither is a bridge. Go A to D

Erase (make dotted) and number the edge that is

traveled over. # 1

1

If you have the choice

between two edges, never take the bridge.

None are a bridge. Go D to C.

Erase (make dotted) and number the edge that is

traveled over. # 2

2

If you have the choice

between two edges, never take the bridge.

CA is bridge – don’t cross it. The others are not

bridges. Go C to F.

Erase (make dotted) and number the edge that is traveled over.

# 3

3

If you have the choice

between two edges, never take the bridge.

FE is bridge – don’t cross it. The others are not

bridges. Go F to D.

Erase (make dotted) and number the edge that is

traveled over. # 4

4

If you have the choice

between two edges, never take the bridge.

There is no choice. Go D to B.

5

Erase (make dotted) and number the edge that is traveled over.

# 5

If you have the choice

between two edges, never take the bridge.

There is no choice. Go B to F.

Erase (make dotted) and number the edge that is traveled over.

# 6

6

If you have the choice

between two edges, never take the bridge.

There is no choice. Go F to E.

Erase (make dotted) and number the edge that is

traveled over. # 7

7

If you have the choice

between two edges, never take the bridge.

There is no choice. Go E to C.

Erase (make dotted) and number the edge that is

traveled over. # 8

8

If you have the choice

between two edges, never take the bridge.

There is no choice. Go C to A.

Erase (make dotted) and number the edge that is traveled over.

# 9

9

The entire graph has now been traversed. DONE!

If you have more than one

choice

that is not a bridge, take either.

BOTH WILL WORK to find different

(18)

Hamilton Paths

and Hamilton

(19)

Euler paths and circuits cover every edge of a

graph. These are useful in optimizing routes

for applications like garbage collection, where

each street (edge) only needs to be traversed

once but a particular intersection (vertex)

may be crossed more than once.

What about optimizing routes for applications

like FedEx or UPS in package delivery? For

(20)

Definitions

▪ Hamilton path – a path that travels through every

vertex of

a graph once and only once.

▪ Hamilton circuit – a Hamilton path that begins and ends at

the same vertex and passes through all

other vertices exactly once.

This is not the same as being traversable. In fact, every edge does not even have to be crossed.

NOTE: Euler’s Rules of Traversability do not help

(21)

Example

Examine the graph below.

3. A graph with more than two odd vertices is NOT

traversable.

Is there a Euler path or

circuit? No, there is

neither.

Is there a Hamilton path

or circuit? Let’s try…

Yes, there is a Hamilton

path.

and a Hamilton circuit.

Just as with the Euler type, if there is a Hamilton circuit there must be a Hamilton

(22)

Example

Examine the graph below.

Is there a Hamilton path

or circuit? Let’s try…

Yes, there is a Hamilton

path.

but NO Hamilton

circuit.

Notice that all the

(23)

Definition

▪ Complete graph – a graph that has an edge between each

pair of its vertices

NOTE: This is not the same as a connected graph. In a connected graph, all the vertices connect through some path which may travel over several edges. In a complete graph, there is a direct line, or edge,

between each pair of vertices.

Complete Graph Rule

Every complete graph with 3 or more vertices has a Hamilton circuit.

Complete Graph Rule

Every complete graph with 3 or more vertices has a Hamilton circuit. (Thus it also has a Hamilton path.)

Complete Graph Rule

(24)

Example

(25)

Example

These are complete graphs:

(26)

Example

Find a Hamilton circuit:

A

B

C

D

E

One possibility: A, B, C, D, E,

A

What about finding a different

one?

B, C, D, E, A, B is the SAME

CIRCUIT!

B, C, D, E, A, B ?

There are actually (

n

-1)! circuits in a complete

graph with

n

vertices. To avoid duplication

when listing them, the book always starts with

A

” only.

(27)

Example

Find a Hamilton circuit:

A

B

C

D

E

One possibility: A, B, C, D, E,

A

What about finding a different

one? A, C, E, B, D, A

(28)

Definition

▪ Weighted graph – a complete graph whose edges have

numbers, or weights, attached to themThe “Traveling Salesman Problem” is a famous

(29)

Example

A sales director lives in City A and must fly to the

regional offices in B, C, and D. There are direct

flights between each pair of cities. He will return

home at the end of the business trip. The chart

below shows the airfares for all possible flights.

A B C D

A * $

190

$ 124

$ 157 B $ 190 * $

126 155$ C $ 124 $

126

* $ 179 D $ 157 $

155 179$ *

COMPLETE GRAPH HAMILTON

(30)

Example

A sales director lives in City A and must fly to the

regional offices in B, C, and D. There are direct

flights between each pair of cities. He will return

home at the end of the business trip. The chart

below shows the airfares for all possible flights.

A B C D

A * $

190

$ 124

$ 157 B $ 190 * $

126 155$ C $ 124 $

126

* $ 179 D $ 157 $

155 179$ *

A

B

C

D

How can the visits be scheduled

in the cheapest possible way?

Need a weighted

(31)

Example

A sales director lives in City A and must fly to the

regional offices in B, C, and D. There are direct

flights between each pair of cities. He will return

home at the end of the business trip. The chart

below shows the airfares for all possible flights.

A B C D

A * $

190

$ 124

$ 157 B $ 190 * $

126 155$ C $ 124 $

126

* $ 179 D $ 157 $

155 179$ *

A

B

C

D

How can the visits be scheduled

in the cheapest possible way?

190

124

157

126

155

(32)

Example

A sales director lives in City A and must fly to the

regional offices in B, C, and D. There are direct

flights between each pair of cities. He will return

home at the end of the business trip. The chart

below shows the airfares for all possible flights.

A

B

C

D

How can the visits be scheduled

in the cheapest possible way?

190

124

157

126

155

179

List all circuits.

(33)

A

B

C

D

How can the visits be scheduled

in the cheapest possible way?

190

124

157

126

155

179

List all circuits.

A, B, C, D, A

A, B, D, C, A

A, C, B, D, A

A, C, D, B, A

A, D, B, C, A

Example

A, D, C, B, A

Find total weights.

= 190

= 190 + 155 + 179 + 124

= 648

= 124 + 126 + 155 + 157 =

562

= 124 + 179 + 155 + 190 =

648

= 157 + 155 + 126 + 124

= 562

= 157 + 179 + 126 + 190

= 652

For $ 562 can travel either:

A, C, B, D, A

A, D, B, C, A

Notice these

are reversed

.

(34)

A

B

C

D

190

124

157

126

155

179

Example

Another way to find the correct route…

Nearest Neighbor Method

From the starting point, choose the edge with the

smallest weight. Continue choosing the edge with the

smallest weight without going back to a previous

vertex.

A

can move to

B

,

C

, or

D

.

Which has smallest weight?

C

124

C

can move to

B

or

D

.

Which has smallest weight?

B

+ 126

B

can only move to

D

D

.

+ 155

D

can only return to

A

A

.

+ 157 = 562

NOTE: The Nearest Neighbor Method only approximates

(35)

Example

Use the Nearest Neighbor Method to approximate

the solution to the weighted graph below.

A

B

C

D

E

128

1

1

180

4

1

4

7

195

14

5

116

169

194

115

A

C

E

D

B

A

114

+ 115

+ 194 + 145 + 180

= 748

Optimal solution is A, E, C, B, D, A (or its reverse) for

(36)

Homework

From the Cow book

10.7 pg 549 # 1 – 6 all 15.1 pg 786 # 1 – 47 odd

15.2 pg 796 # 1 – 39 odd

References

Related documents

Purpose – This study aims to examine organizational factors (i.e. top management support, training and education, enterprise-wide communication) that may influence the

Relevant studies were extracted into a qualitative synthesis table and categorised according to the following items: author, title, year of publication, journal, study design,

Berdasarkan masalah tersebut, maka perlu dilakukan penelitian respon ketahanan dan kandungan senyawa fenol enam varietas kedelai terhadap penyakit busuk pangkal

International Working Group and advisory board meetings to review the revised draft Global Scientific Strategy and feedback from consultations. Planning of the launch

Vendor Registration Form Flowing Wells School District..

Using a binary erasure version of the multiple descriptions (MD) problem to model the P2P network, the thesis presents coding schemes based on systematic MDS (maximum distance

The genotypes of the bulk virus populations passaged in MDCK-V2 cells and selected by cell sorting (populations VS1 to VS6) were analyzed by deep sequencing of virion RNA on