Top Banner
Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION
51

Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Dec 28, 2015

Download

Documents

Roderick Cook
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-1 Copyright © 2005 Pearson Education, Inc.

SEVENTH EDITION and EXPANDED SEVENTH EDITION

Page 2: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Copyright © 2005 Pearson Education, Inc.

Chapter 14

Graph Theory

Page 3: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Copyright © 2005 Pearson Education, Inc.

14.1

Graphs, Paths and Circuits

Page 4: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-4 Copyright © 2005 Pearson Education, Inc.

Definitions

A graph is a finite set of points called vertices (singular form is vertex) connected by line segments (not necessarily straight) called edges.

Loop is an edge that connects a vertex to itself.

A B

C D

Loop

Edge

Vertex

Not a vertex

Page 5: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-5 Copyright © 2005 Pearson Education, Inc.

Example: Map

The map shows the states that make up part of the Midwest states from Weather Underground, Inc. Construct a graph to show the states that share a common border.

Michigan

Ohio

Indiana

Kentucky

West Virginia

Page 6: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-6 Copyright © 2005 Pearson Education, Inc.

Solution

Each vertex will represent one of the states.

If two states share a common border, connect the respective vertices with an edge.

Page 7: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-7 Copyright © 2005 Pearson Education, Inc.

Solution continued

Michigan

Ohio

Indiana

Kentucky

West Virginia

MI

OHIN

KY WV

Page 8: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-8 Copyright © 2005 Pearson Education, Inc.

Definitions

The degree of a vertex is the number of edges that connect to that vertex.

A vertex with an even number of edges connected to it is an even vertex.

A vertex with an odd number of edges connected to it is an odd vertex.

MI, OH, and WV are even vertices

IN, KY are odd vertices

MI

OHIN

KY WV

Page 9: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-9 Copyright © 2005 Pearson Education, Inc.

Definitions

A path is a sequence of adjacent vertices and edges connecting them.

C, D, A, B is an example of a path.

A circuit is a path that begins and ends at the same vertex.

A, C, B, D, A forms a circuit.

A B

C D E

Page 10: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-10 Copyright © 2005 Pearson Education, Inc.

Definitions

A graph is connected if, for any two vertices in the graph, there is a path that connects them.

Examples of disconnected graphs.

A

B C

D

GH

JK

Page 11: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-11 Copyright © 2005 Pearson Education, Inc.

Definitions continued

A bridge is an edge that if removed from a connected graph would create a disconnected graph.

A

B C

D

bridge GH

JK

bridge

Page 12: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Copyright © 2005 Pearson Education, Inc.

14.2

Euler Paths and Euler Circuits

Page 13: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-13 Copyright © 2005 Pearson Education, Inc.

Definitions

An Euler path is a path that passes through each edge of a graph exactly one time.

An Euler circuit is a circuit that passes through each edge of a graph exactly one time.

The difference between an Euler path and an Euler circuit is that an Euler circuit must start and end at the same vertex.

Page 14: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-14 Copyright © 2005 Pearson Education, Inc.

Examples

Euler path Euler circuit

Page 15: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-15 Copyright © 2005 Pearson Education, Inc.

Example: Euler Path and Circuits

For the graphs shown, determine if an Euler path, an Euler circuit, neither, or both exist.

A BC

D

A B C

D E

The graph has many Euler circuits, each of which is also an Euler path. This graph has no odd vertices. One example is A, D, B, C, D, B, A.

The graph has an Euler path but it does not have an Euler circuit. One Euler path is E, C, B, E, D, B, A, D. Each path must begin or end at vertex D or E.

Page 16: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-16 Copyright © 2005 Pearson Education, Inc.

Euler’s Theorem

For a connected graph, the following statements are true: 1. A graph with no odd vertices (all even vertices) has at

least one Euler path, which is also an Euler circuit. An Euler circuit can be started at any vertex and it will end at the same vertex.

2. A graph with exactly two odd vertices has at least one Euler path but not Euler circuits. Each Euler path must begin at one of the two odd vertices, and it will end at the other odd vertex.

3. A graph with more than two odd vertices has neither an Euler path nor an Euler circuit.

Page 17: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-17 Copyright © 2005 Pearson Education, Inc.

Example: Using Euler’s Theorem

Use Euler’s theorem to determine whether an Euler path or an Euler circuit exists in the figures shown from the previous example.

Page 18: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-18 Copyright © 2005 Pearson Education, Inc.

Example: Using Euler’s Theorem continued The graph has no odd

vertices (all vertices are even). According to item 1, at least one Euler circuit exists.

An Euler circuit can be determined by starting at any vertex. The Euler circuit will end at the vertex from which is started. Remember that each Euler circuit is also an Euler path.

A BC

D

Page 19: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-19 Copyright © 2005 Pearson Education, Inc.

Example: Using Euler’s Theorem continued There are 3 even vertices

(A, B, C) and two odd vertices (D, E). Based on item 2, we conclude that since there are exactly two odd vertices, at least one Euler path exists but no Euler circuits exists. Each Euler path must begin at one of the odd vertices and end at the other odd vertex.

A B C

D E

Page 20: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-20 Copyright © 2005 Pearson Education, Inc.

Example

In section 14.1, example 1, we discussed some of the states that make up the Midwest region of the weather map from Weather Underground. We drew a graph that showed the states that share a common border. One of the researchers wants to visit each state within the mapped region. To plan the most efficient trip, the researcher wishes to travel between these states and cross each common state border exactly one time. a) Is it possible to travel among the states and cross

each common state border exactly one time?

b) If it is possible, can he start and end in the same state?

Page 21: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-21 Copyright © 2005 Pearson Education, Inc.

Solution

We are looking for an Euler path, you must use each edge exactly one time.According to item 2, the graph has at least one Euler path but no Euler circuits. Therefore, yes, it is possible to travel among these states and cross each common border exactly one time.

There is not an Euler circuit, so the researcher cannot start and end in the same state.

MI

OHIN

KY WV

Page 22: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-22 Copyright © 2005 Pearson Education, Inc.

Fleury’s Algorithm

To determine an Euler path or an Euler circuit: 1. Use Euler’s theorem to determine

whether an Euler path or an Euler circuit exists. If one exists, proceed with steps 2-5.

2. If the graph has no odd vertices (therefore has an Euler circuit, which is also an Euler path), choose any vertex as the starting point. If the

graph has exactly two odd vertices (therefore

has only an Euler path), choose one of the two odd vertices as the starting point.

Page 23: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-23 Copyright © 2005 Pearson Education, Inc.

Fleury’s Algorithm continued

3. Begin to trace the edges as you move through the graph. Number the edges as you trace them. Since you can’t trace any edges twice in Euler paths and Euler circuits, once an edge is traced consider it “invisible.”

4. When faced with a choice of edges to trace, if possible, choose an edge that is not a bridge (i.e., don’t create a disconnected graph with your choice of edges).

5. Continue until each edge of the entire graph has been traced once.

Page 24: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-24 Copyright © 2005 Pearson Education, Inc.

Example

Use Fluery’s algorithm to determine an Euler circuit.

There is at least one Euler circuit since there are no odd vertices.

Start at any vertex to determine an Euler circuit.

AB

C

D

E

FG

Page 25: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-25 Copyright © 2005 Pearson Education, Inc.

Example continued

Start at C. Choose either CB or CD.

Continue to trace from vertex to vertex around the outside of the graph.

AB

C

D

E

FG

1

23

4

5

6

7

8

9

10

start here

Page 26: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Copyright © 2005 Pearson Education, Inc.

14.3

Hamilton Paths and Hamilton Circuits

Page 27: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-27 Copyright © 2005 Pearson Education, Inc.

Definitions

A Hamilton path is a path that contains each vertex of a graph exactly once.

A Hamilton circuit is a path that begins and ends at the same vertex and passes through all other vertices of the graph exactly one time.

Page 28: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-28 Copyright © 2005 Pearson Education, Inc.

Example: Hamilton Path

Graph (a) shown has Hamilton path A, B, C, E, D. The graph also has Hamilton path C, B, A, D, E. Can you find some others?

Graph (b) shown has Hamilton path A, B, C, F, H, E, G, D. The graph also has Hamilton path G, D, E, H, F, C, B, A. Can you find some others?

Page 29: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-29 Copyright © 2005 Pearson Education, Inc.

Example: Hamilton Circuit

Graph (a) shown has Hamilton circuit A, B, D, G, E, H, F, C, A.

A Hamilton circuit starts and ends at the same vertex.

Graph (b) shown has Hamilton circuit A, B, C, E, D, A.

Can you find another?

Page 30: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-30 Copyright © 2005 Pearson Education, Inc.

Definition

A complete graph is a graph that has an edge between each pair of its vertices.

Page 31: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-31 Copyright © 2005 Pearson Education, Inc.

Example: Finding Hamilton Circuits

Determine a Hamilton circuit for the complete graph shown.

One solution is

A, G, F, E, C, D, B, A

A B C

EFG

D

Page 32: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-32 Copyright © 2005 Pearson Education, Inc.

Number of Unique Hamilton Circuits in a Complete Graph The number of unique Hamilton circuits in a

complete graph with n vertices is (n 1)! where

(n 1)! = (n 1)(n 2)(n 3)…(3)(2)(1)

Page 33: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-33 Copyright © 2005 Pearson Education, Inc.

Example: Number of Hamilton Circuits

How many unique Hamilton circuits are there in a complete graph with the following number of vertices?

a) 4 b) 9

a) 4 = (4 1)! = 4•3•2•1 = 24 b) 9 = (9 1)! = 8•7•6•5•4•3•2•1

= 40,320

Page 34: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-34 Copyright © 2005 Pearson Education, Inc.

The Brute Force Method of Solving Traveling Salesman Problems To determine the optimal solution:

1. Represent the problem with a complete, weighted graph.

2. List all possible Hamilton circuits for this graph. 3. Determine the cost (or distance) associated

with each of these Hamilton circuits. 4. The Hamilton circuit with the lowest (or shortest

distance) is the optimal solution.

Page 35: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-35 Copyright © 2005 Pearson Education, Inc.

Example: Brute Force Method

Find a minimum Hamilton circuit for the complete, weighted graph shown.

List all the Hamilton circuits.

Since there are 4 vertices there are (4 1)! = 3! = 6 possible circuits.

A B

CD

6

1282

2

6

Page 36: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-36 Copyright © 2005 Pearson Education, Inc.

Example: Brute Force Method continued

A B

CD

6

1282

2

6

2661262A, D, C, B, A

2421282A, D, B, C, A

226862A, C, D, B, A

2

2

2

Fourth Leg

248122A, C, B, D, A

22686A, B, D, C, A

266126A, B, C, D, A

TotalThird Leg

Second Leg

First

Leg

Circuit

The minimum amount for the graph would be 22.

Page 37: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-37 Copyright © 2005 Pearson Education, Inc.

Nearest Neighbor Method of Determining an Approximate Solution to a Traveling Salesman Problem To approximate a optimal solution:

1. Represent the problem with a complete, weighted graph.

2. Identify the starting vertex. 3. Of all the edges attached to the starting vertex,

choose the edge that has the smallest weight. This edge is generally either the shortest distance or the lowest cost. Travel along this edge to the second vertex.

Page 38: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-38 Copyright © 2005 Pearson Education, Inc.

Nearest Neighbor Method of Determining an Approximate Solution to a Traveling Salesman Problem continued

4. At the second vertex, choose the edge that has the smallest weight that does not lead to a vertex already visited. Travel along this edge to the third vertex.

5. Continue this process, each time moving along the edge with the smallest weight until all vertices are visited.

6. Travel back to the original vertex.

Page 39: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-39 Copyright © 2005 Pearson Education, Inc.

Example: Nearest Neighbor

An appliance repair man must repair four appliances at the locations shown in the graph. The estimated travel time (in minutes) is shown between the four locations. The repair man wants to visit the four locations in an order that takes the least amount of time. Use the nearest neighbor algorithm to find an approximate solution to the problem.

Page 40: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-40 Copyright © 2005 Pearson Education, Inc.

Example: Nearest Neighbor continued

Choose a starting vertex. Let’s choose vertex A.

Choose the edge that has the smallest weight. Either AD or AB, lets choose AD (9).

At D choose the edge that has the smallest weight DE (5).

C

B

A

E

D

18

8 13

4

7

6

9

7

3

8

start here

2nd

vertex

Page 41: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-41 Copyright © 2005 Pearson Education, Inc.

Example: Nearest Neighbor continued

Continue moving along the edge with the smallest weight.

Circuit would be: A, D, E, B, C, A

8 + 4 + 3 + 9 + 13 = 37 This route would take about

37 minutes.

C

B

A

E

D

18

8 13

4

7

6

9

7

3

8

start here

2nd

vertex

Page 42: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-42 Copyright © 2005 Pearson Education, Inc.

Example: Nearest Neighbor continued

Other circuits and weights.

3 + 9 + 6 + 13 + 18 = 49E, B, D, C, A, EE

4 + 3 + 8 + 13 + 6 = 34D, E, B, A, C, DD

6 + 4 + 3 + 8 + 13 = 34C, D, E, B, A, CC

3 + 4 + 6 + 13 + 8 = 34B, E, D, C, A, BB

Total WeightCircuitStarting Vertex

Page 43: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Copyright © 2005 Pearson Education, Inc.

14.4

Trees

Page 44: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-44 Copyright © 2005 Pearson Education, Inc.

Definitions

A tree is a connected graph in which each edge is a bridge.

A spanning tree is a tree that is created from another graph by removing edges while still maintaining a path to each vertex.

Page 45: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-45 Copyright © 2005 Pearson Education, Inc.

Examples

Graphs that are trees. Graph that are not trees.

Page 46: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-46 Copyright © 2005 Pearson Education, Inc.

Example: Determining Spanning Trees

Determine two different spanning trees for the graph shown.

A

B

C

E F H

D G

A

B

C

E F H

D GA

B

C

E F H

D G

Page 47: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-47 Copyright © 2005 Pearson Education, Inc.

Minimum-cost spanning tree

A minimum cost spanning tree is the least expensive spanning tree of all spanning trees under consideration.

Page 48: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-48 Copyright © 2005 Pearson Education, Inc.

Kruskal’s Algorithm

To construct the minimum-cost spanning tree from a weighted graph:

1. Select the lowest-cost edge on the graph. 2. Select the next lowest-cost edge that does not

form a circuit with the first edge. 3. Select the next lowest-cost edge that does not

form a circuit with the previously selected edges. 4. Continue selecting the lowest-cost edges that doe

not form circuits with the previously selected edges.

5. When a spanning tree is complete, you have the minimum-cost spanning tree.

Page 49: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-49 Copyright © 2005 Pearson Education, Inc.

Example: Kruskal’s Algorithm

Use Kruskal’s algorithm to determine the minimum spanning tree for the weighted graph shown. The numbers along the edges represent dollars.

A

B

C

G

D

E

F

12

11

10

5

22

14

4

17

22

18

Page 50: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-50 Copyright © 2005 Pearson Education, Inc.

Solution

Pick the lowest-cost edge of the graph, edge CD which is $4.

Next we select the next lowest-cost edge that does not form a circuit, we select edge CG which is $5.

A

B

C

G

D

E

F

12

11

10

5

22

14

4

17

22

18

Page 51: Slide 14-1 Copyright © 2005 Pearson Education, Inc. SEVENTH EDITION and EXPANDED SEVENTH EDITION.

Slide 14-51 Copyright © 2005 Pearson Education, Inc.

Solution continued

Continue selecting edges, being careful not to form a circuit.

The total cost would be $12 + $10 + $5 + $14 +$18 + $4 = $63.

A

B

C

G

D

E

F

12

11

10

5

22

14

4

17

22

18