• No results found

Euler Paths & Circuits Hamilton Paths & Circuits

N/A
N/A
Protected

Academic year: 2020

Share "Euler Paths & Circuits Hamilton Paths & Circuits"

Copied!
36
0
0

Loading.... (view fulltext now)

Full text

(1)

Euler Paths & Circuits

Hamilton Paths & Circuits

(2)

Euler Paths

and Euler Circuits

(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

NOTE 1: An edge can be part of a path only once.

(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

(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? YES

Is the graph traversable? YES

Where do we start? ANYWHERE

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.

(18)

Hamilton Paths

and Hamilton Circuits

(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 these

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

(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

(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 vertices are

even. Thus the graph has an

(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

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

(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 them

(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

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

Brute Force Method… calculate every possibility and see which is best.

(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 the smallest

(35)

Example

Use the Nearest Neighbor Method to approximate

the solution to the weighted graph below.

A

B

C

D

E

128

114

180

147

195

145

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

Our analysis, which is based on new evidence assembled for this study, describes the level of fees charged by veterinary surgeons for standard veterinary services and assesses the

Ten years into the reign of Thorin the First, son of Thráin the Old, the King resolved to remove the royal house of Durin’s folk from Erebor to abide in the Grey Mountains.. At the

Step 1: Draw the configuration diagram.. • Problem 11: For the mechanism shown in figure link 2 rotates at constant angular velocity of 1 rad/sec construct the velocity polygon

In 2008, the City of Hamilton and Clean Air Hamilton hosted the fifth biennial Upwind Downwind Conference: Climate Change & Healthy Cities on February 25 th and 26 th , 2008,

Using 2012 Kentucky workers’ compensation FROI data, the aims of this study were to: (1) identify and characterize differences in injury types between workers in short-haul

Euler Path: a path that travels through every edge of a connected graph once and only once and starts and ends at different vertices... Figure 6.3.2:

GO Slim Term Specific Evaluation of Sequence Features In order to clarify the differences in the prediction performance of different functional terms, we calculated the

80-1006 that local agencies retain discretion concerning destruction of emails relating to the conduct of the public’s business that are prepared, owned, used or retained by