Chapter 15: Introduction to Graph Theory - Cengage Learning

4 downloads 1516 Views 17MB Size Report
Nov 7, 2006 ... In Section 15.1, you will discover how graph theory is used to obtain optimal solutions for certain problems. 15.1 Introduction to Graph. Theory.
304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G1

C H A P T E R

15 Electrical engineers use concepts of graph theory in order to set up systems of computers and communication lines for businesses. In Section 15.1, you will discover how graph theory is used to obtain optimal solutions for certain problems.

Lester Lefkowitz/Corbis

15.1

Graph Theory How many airplane flights connect a given number of cities? How can we create a schedule for visiting these cities using an efficient and costeffective schedule? How many ways can you connect your company’s computers so they communicate with each other efficiently and inexpensively? These types of problems are extremely important and are sometimes called routing problems. A routing problem is one whose solution provides an efficient way of routing among different destinations and can be solved using special diagrams called graphs. The theory associated with these graphs (graph theory) is used to reach cost-effective solutions by individuals and businesses. In this chapter we study graphs and two types of routing problems: Euler and Hamilton circuits. The last section deals with trees, which are connected graphs that have no circuits.

Introduction to Graph Theory

15.2 Euler Paths and Euler Circuits 15.3 Hamilton Paths and Hamilton Circuits 15.4 Trees

Online Study Center For links to Internet sites related to Chapter 15, please access college.hmco.com/PIC/bello9e and click on the Online Study Center icon.

G1

304470_ch15_web_pG1-G45

G2

11/7/06

10:05 AM

Page G2

15 Graph Theory

Bridges, the Web, Maps, and Traveling

G START D

GE

IN

E

TT

15.1 Introduction to Graph Theory

Hulton-Deutsch Collection/Corbis

HUMAN SIDE OF MATH William Rowan Hamilton was an Irish mathematician and astronomer (1805–1865) who developed the theory of quaternions, a landmark in the development of algebra. Hamilton became interested in mathematics after a meeting in 1820 with Zerah Colburn, an American who could calculate mentally with fantastic speed. In 1823, he entered Trinity College and obtained the highest honors in both classics and mathematics. Even today, Hamiltonian mechanics is used commercially to determine the orbital trajectories of satellites.

As you recall from Chapter 8, the Bridges of Königsberg problem was solved by Leonhard Euler in 1736. The question was: Can we follow a route that would take us across each of the seven bridges of the Pregel River exactly once? Euler provided the conditions that are necessary and sufficient to permit such a stroll. Here is a more modern problem. Suppose you are given the task of deciding how to link 12 computers together. Since linking each of them to all the others is too expensive, you decide that each computer will be connected to three other computers in such a way that messages don’t have to pass through more than two of the computers on their way to their destination. How would you decide on the best way to connect these computers together? You can do it by representing each computer as a dot called a vertex and the connecting wires as lines or edges! We will tell you exactly how to do it later, but first let us start with some definitions.*

A. Graphs, Paths, and Circuits The reader should note that graphs as defined here are not the same as the graphs of functions as discussed in Chapter 7. Definition of a Graph

A graph is a collection of points called vertices and arcs or line segments called edges, that join pairs of vertices. A vertex may be an endpoint of any number of edges, or it may stand alone in a graph. The degree of a vertex is the number of edges that have it as a common endpoint.

When discussing a particular graph, it is often helpful to provide labels for the edges and vertices of the graph. We will label the edges of a graph with lowercase letters (a, b, c, . . .) and the vertices with uppercase letters (A, B, C, . . .). Typical graphs are depicted in Figure 15.1.

Looking Ahead Hamilton circuits have a wide range of applications in today’s business world and are one of the topics in this chapter.

F I G U R E 15 .1 *Adapted from www.cs.uidaho.edu/~casey931/mega-math/workbk/graph/grbkgd.html.

304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G3

G3

15.1 Introduction to Graph Theory

b

B a

c

d

e

A

f

E

D

F I G U R E 15 . 2

b

D

What are the degrees of each of the vertices in Figure 15.2? To find the degree of each vertex, we merely count the number of edges that meet the vertex. Thus, the degrees of vertices A, B, C, D, E, and F are 3, 3, 2, 4, 2, and  0, respectively.

F

c

a

EX AM P LE 1  Finding the Degrees of Vertices

Solution

g

A

An example of a graph with its labels is given in Figure 15.2.

C

B e

f

d

A graph that consists of some of the vertices and edges of another graph is called a subgraph. We emphasize that a subgraph must be a graph itself. In particular, each edge must join two vertices. Figure 15.3a shows a graph; two of its subgraphs are depicted in bold in Figures 15.3b and 15.3c. Thus, the subgraph in Figure 15.3b consists of the vertices B, C, and D and the edges d, e, and f. The subgraph in Figure 15.3c consists of the vertices A, B, C, and D and the edges b, c, and f. Suppose that V and W are vertices of a graph.

C

Definition of Path

(a)

A path from V to W is a sequence of edges in the graph for which b A a D

1. V is a vertex of the first edge of the sequence.

c

e f

B

2. W is a vertex of the last edge of the sequence.

d

3. starting at V, you can trace along each consecutive edge of the sequence without lifting your pencil.

C

(b) b A

c

a D

B e

f

d

Notice that consecutive edges of a path must have a common endpoint. Whenever we describe a path, we will enclose the sequence of edges in square brackets. For example, the sequence [a, b, c, d, b, e] in Figure 15.4a describes the path from A to D indicated. The sequence [a, b, c, d, i] indicated in Figure 15.4b does not define a path because edges d and i have no endpoint in common. Notice that edges may be traversed more than once in a given path (as in Figure 15.4a). A path that has no repeated edges is called a simple path. c

C

(c) A

c

d

E

B

A

d

E

B

F I G U R E 15 . 3

a

b

f

g

i

a

F

C

e C

b

f

g

i

e D

h

(a)

D

(b) F I G U R E 15 . 4

h

F

304470_ch15_web_pG1-G45

G4

11/7/06

10:05 AM

Page G4

15 Graph Theory

In rare cases, there will be some ambiguity when describing a path by listing successive edges. For instance, does the path [a, b] in Figure 15.5 start at vertex A and end at B, or vice versa? In such situations we will clarify the matter by specifying the intended order of the vertices or by indicating the intended order with arrows. Note that the path [a, b, c] in Figure 15.5 clearly starts at vertex A and ends at vertex C. D

C

a

c A

b

d

B e E

F I G U R E 15 . 5

A path that begins and ends at the same vertex is called a circuit. A circuit beginning and ending at the vertex A is said to be based at A. For example, the path [a, b, c, a] in Figure 15.6 is a circuit based at A, while the path [a, b, d] is not a circuit (the path begins at vertex A and ends at vertex B). A graph for which any two vertices can be joined by a path is said to be connected (otherwise, it is disconnected). In a visual sense, a graph is disconnected if there are any vertices for which we are required to lift our pencil in order to travel between them. Figure 15.7a depicts a connected graph, while Figure 15.7b is an example of a disconnected graph.

C

b

c

d

B a

Connected

A

Disconnected

(a)

(b) F I G U R E 15 . 7

F I G U R E 15 . 6

EX AM P LE 2  Identifying Paths and Circuits

For which of the graphs in Figure 15.8, parts (a), (b), and (c), does the sequence of edges a, b, c, d represent a path? A circuit? Which graphs are connected? A

a b

C c

d

D

A

a b

B

C

D

c

d

E

B

a

b

A

d

B

(a)

(b)

C E

F I G U R E 15 . 8

c

D

e

F

(c)

304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G5

15.1 Introduction to Graph Theory

G5

Solution

(a) Starting at C, we can trace along each of the edges listed in the sequence, ending at D, so the sequence defines a path from C to D. Since this path begins and ends at different vertices, it is not a circuit. The graph is connected. Indeed, it is quite simple to find a path between any pair of vertices. (b) Edges c and d have no endpoints in common, so the sequence does not define a path (or a circuit, for that matter). Observing that there is no way to reach vertex D from vertex C without leaving the graph, we conclude that the graph is disconnected. (c) The sequence [a, b, c, d] is a circuit based at A. The graph is disconnected. For example, there is no way to travel from vertex C to vertex E without lift ing our pencil. Online Study Center

To further explore graph theory, access link 15.1.1 on this textbook’s Online Study Center.

K1

A complete graph is one in which every pair of vertices is joined by exactly one edge. A complete graph with n vertices will be denoted by Kn. Complete graphs will be especially important in future applications (Section 15.3). The first five complete graphs are given in Figure 15.9 below.

K2

K3

K4

K5

F I G U R E 15 . 9

E X E R C I S E S 15 .1 A Graphs, Paths, and Circuits

2. A

B

C

D

E

F

In problems 1–4, find the degree of each vertex of the graph. 1.

A

D

E

B

C

304470_ch15_web_pG1-G45

G6

11/7/06

10:05 AM

Page G6

15 Graph Theory

3.

B

B

b

C

a A

c

A

D

D

j k

h

d

i

H

E

C g

4.

A

B

G

9. [a, b, c] H

C

G

D

F

f

10. [a, k, d, b]

11. [ j, d, k, a]

12. [a, b, i, g, f ]

13. [h, g]

14. [i, c, d, k, a, j, c, i]

15. [h, f, g]

16. [ f, i, b, k, e]

In problems 17–22, decide whether the graph pictured is connected or disconnected. 17.

F

e

18.

E

In problems 5–8, refer to the graph below. Decide whether the collection of vertices and edges listed in each problem determines a subgraph of the graph. C

e

19.

D

b A

B

d

a

f

20.

c F

g

E

5. Vertices {A, B, D}; edges {a, b, e} 6. Vertices {A, B, C, D}; edges {a, b, e} 7. Vertices {A, E, F}; edge {g}

For problems 21–26, determine whether the graph pictured is complete. Explain your reasoning.

8. Vertices {A, B, D, E}; edges {a, f, c}

21.

For problems 9–16, refer to the graph (above, right) and determine whether the given sequence of edges represents a path, a circuit, or neither. Explain your answers.

22.

304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G7

15.1 Introduction to Graph Theory

23.

24.

25.

29.

26.

G7

30.

In Other Words 31. Describe in your own words the difference between a connected graph and a disconnected graph. 32. Describe in your own words the difference between a circuit and a path.

A graph is said to be simple if each pair of vertices is joined by at most one edge. In problems 27–30, determine whether the graph pictured is simple. Explain your reasoning. 27.

28.

Using Your Knowledge Do you remember the problem in the Getting Started regarding linking 12 computers together? Can you solve it now? Here is a restatement of the problem. 33. Suppose you are given the task of deciding how to link 12 computers together. Since linking each of them to all the others is too expensive, we decide that each computer will be connected to three other computers in such a way that messages don’t have to pass through more than two of the computers on their way to their destination. How would you decide how to connect these computers together?

Research Questions 1. Who was the first mathematician to apply graph theory in solving a problem? Discuss the details of the application. 2. Write a brief report on William R. Hamilton’s contributions to graph theory. 3. In computer science, information is encoded in the form of bit strings. A bit string of length n is a sequence of n digits where each digit is either 0 or 1. For example, 110 and 101 are bit strings of length 3, whereas 10101 is a bit string of length 5. Due to interference, errors may occur when information (in the form of bit strings) is sent from one computer to another. It is important that these errors are detected and corrected. Write a report on the applications of graph theory to error-correcting codes. Sometimes these codes are also called Hamming codes.

304470_ch15_web_pG1-G45

G8

10:05 AM

Page G8

15 Graph Theory

15.2

G START

Another Bridge to Cross

As you recall, the great Swiss mathematician Leonhard Euler (1707–1783; pronounced “oiler”) was one of the first to recognize the utility of graph theory and put it to work for him in solving the famous Bridges of Königsberg problem (Section 8.6). Euler solved this problem by representing certain objects as vertices and representing the relationships between these objects as edges. In Euler’s case the vertices represented various land masses and the edges represented the bridges joining the islands and the mainland. Euler’s technique is a powerful tool for applying the mathematical theory of graphs to problems in the world around us. Time and again we will put this technique to work for us. 

D

GE

IN

Euler Paths and Euler Circuits

E

TT

11/7/06

A. Euler Paths and Circuits The reader should recognize that the definition of traversability given here is the same as that given in Section 8.6. As with ordinary circuits, a Euler circuit that begins and ends at vertex A is said to be based at A. Euler Paths, Circuits, and Traversability

A path that uses every edge of a graph once and only once is called an Euler path. An Euler circuit is an Euler path that begins and ends at the same vertex. A graph that has an Euler path (or circuit) is said to be traversable.

The Granger Collection Leonhard Euler (1707–1783).

EX AM P LE 1  Defining an Euler Path or Circuit

For which of the graphs in Figure 15.10, parts (a), (b), and (c), does the sequence of edges [a, b, c, d, e] define an Euler path? An Euler circuit? (a) B

b

C

(b) a

a

e

c

A

d

B

C b c

a D

d e

A

(c)

B

E

D

b

A

C e

c

F F I G U R E 15 .10

E

d

D

Solution

(a) The sequence [a, b, c, d, e] defines an Euler path from A to C. (b) Although every edge is listed, this sequence does not even define an ordinary path. (c) The sequence [a, b, c, d, e] describes an Euler circuit based at the vertex A. 

304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G9

15.2 Euler Paths and Euler Circuits

G9

EX AM P LE 2  Finding an Efficient Route

The Willamette River divides the city of Portland, Oregon, into two halves: the east and west sides. To travel between the two sides of the city, one must cross one of the eight bridges that span the river (see the map).

5

Portland 405

Jim Richardson/Corbis Willamette River, Portland, Oregon.

A bridge safety inspector has recently been hired by the city to ensure that each bridge is properly maintained. He intends to drive his car over each of the bridges once a day to inspect them visually. Since this is a time-consuming process, he would like to plan his route as efficiently as possible. In particular he would prefer to drive over each bridge exactly one time. How can graph theory aid the inspector in planning an efficient route? Solution

Following Euler’s technique, we construct a graph to represent the problem. In the graph, each of the two sides of the city is a vertex, and each bridge is an edge. To determine whether it is possible to drive over each bridge exactly one time, we must determine whether the graph in Figure 15.11 is traversable. In other words, does the graph have an Euler path, and if so, can we find one? We will  return to this question shortly.

F I G U R E 15 .11

B. Finding Euler Paths and Circuits We have seen that it is possible to represent real-world problems with graphs. Once we have represented a problem with a graph, finding a solution to the problem may sometimes involve finding an Euler path or circuit. Before we begin searching for an Euler path or circuit, it would be helpful to know if any exist. The traversability rules are just the tools we need for this, so we’ll review them now, restating them in the language of graph theory.

304470_ch15_web_pG1-G45

G10

11/7/06

10:05 AM

Page G10

15 Graph Theory

Traversability Rules

1. A connected graph with no vertices of odd degree is traversable. You can start at any point, and you will end up at that same point. In other words, a connected graph with no vertices of odd degree always has an Euler circuit. 2. A connected graph with exactly two vertices of odd degree is traversable. You must start at one of the odd vertices and end at the other. In other words, a connected graph with two vertices of odd degree always has an Euler path. 3. A graph with more than two vertices of odd degree is not traversable. In other words, no matter how hard we try, we will never be able to find an Euler path or circuit if our graph has more than two vertices of odd degree.

EX AM P LE 3  Deciding Whether Graphs Are Traversable

Determine whether each of the graphs in Figure 15.12, parts (a), (b), and (c), is traversable. F I G U R E 15 .12

(a)

A

(b)

B

B

C D

(c)

A C

E

F

G

D

E

F Solution

(a) Vertices A, B, D, and G have degree 2, vertex C has degree 4, and vertices E and F have degree 3. According to traversability rule 2, the graph is traversable because we have exactly two vertices of odd degree, E and F. In other words, there exists an Euler path that starts at vertex E and ends at vertex F (or vice versa). (b) Vertices C and E have degree 5, whereas vertex F has degree 3. According to traversability rule 3, the graph is not traversable because we have more than two vertices of odd degree. (c) Each vertex has degree 4. According to traversability rule 1, the graph is traversable because we have no vertices of odd degree. There is an Euler  circuit based at each of the vertices. EX AM P LE 4  Finding an Efficient Route

We return to the problem of finding an efficient route for the Portland bridge inspector in Example 2. Recall that we need to determine whether the graph in

304470_ch15_web_pG1-G45

11/7/06

10:05 AM

Page G11

15.2 Euler Paths and Euler Circuits

G11

Figure 15.13 has an Euler path. How can the traversability rules be used to make this determination? Solution

F I G U R E 15 .13

The graph in Figure 15.13 has two vertices. Each of these vertices has eight edges emanating from it. In other words, each vertex has degree 8. According to traversability rule 1, the graph has an Euler circuit (there are no vertices of odd degree). From this we conclude that there exists a route for our inspector using each of the bridges exactly one time. We will return to the process of actually  finding such a route in the next section. We’ve seen how to use the traversability rules to determine whether a graph is traversable, but these rules don’t provide us with a method for actually finding the particular path that traces out every edge. Using trial and error, we will eventually find an Euler path, but this is not a very efficient way to proceed, and if our graph is complicated, the search could take a very long time. What we would like is a process that, when applied, guarantees that we will find an Euler path (and preferably with a minimal amount of effort). Such a process is called an algorithm. Fortunately, when searching for Euler circuits, there is just such an algorithm. Before describing it, we need to introduce one more concept. Definition of a Bridge

A bridge is an edge in a graph that, when removed, creates a disconnected graph.

EX AM P LE 5  Locating Bridges

Locate the bridges in the graphs in Figure 15.14, parts (a), (b), and (c). (a)

(b)

(c)

b d

a

e

c F I G U R E 15 .14

Solution

(a) By removing the indicated edge as shown in Figure 15.15, we obtain a disconnected graph. (b) Edges d and e are bridges. Figure 15.16 on page G12 shows the result of removing edge e, while Figure 15.17 shows the result of removing edge d. F I G U R E 15 .15

304470_ch15_web_pG1-G45

G12

11/7/06

10:06 AM

Page G12

15 Graph Theory

F I G U R E 15 .16

F I G U R E 15 .17

(c) The graph has no bridges. It remains connected after removing any edge.

A

a

B

f

h F

Remember that we are currently interested in Euler circuits. This means that we intend to start at some vertex of our graph and travel along every edge once and only once until we return to our starting point. In the process, we will need to keep track of the edges we have already traced (otherwise, we might accidentally travel along an edge more than once!). We will do this by first replacing the edges we have already traveled over with dotted line segments or arcs. We will then remove them from the graph (see Example 6). Notice that the untraveled part of the graph is a subgraph of the original graph called the untraveled subgraph. Each time we trace along a new edge, we create a new untraveled subgraph.

D

d

b C

i

c



g F I G U R E 15 .18

e

E

j

EX AM P LE 6  Finding the Untraveled Subgraph

Consider the path [a, b, d] from A to D in Figure 15.18. What is the untraveled subgraph corresponding to this path? Solution

By replacing the edges indicated by dashed line segments, we obtain Figure 15.19a. The edges that remain (together with their endpoints) constitute the untraveled subgraph (Figure 15.19b).

(a)

(b) F I G U R E 15 .19



We now have all the tools needed to describe the algorithm for finding Euler circuits. The method is called Fleury’s algorithm, and the basic idea is as follows: First, notice that if a graph is disconnected, then it cannot have an Euler circuit. Consequently, for the remainder of this discussion we consider connected graphs only. We also need to decide whether the (connected) graph we are interested in even has an Euler circuit. Traversability rule 1 provides the answer: If every vertex of our graph has even degree, the graph is guaranteed to have an Euler circuit; if any one of the vertices of our graph has odd degree, no matter how hard we try, we will never be able to find an Euler circuit.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G13

G13

15.2 Euler Paths and Euler Circuits

Fleury’s Algorithm

Assume that the graph we are interested in has an Euler circuit. Pick any vertex as a starting point. This vertex will have an even number of edges extending from it. The basic idea behind Fleury’s algorithm can be summarized as “don’t cross a bridge until you have to.” In other words, from our starting point, we can trace along any edge to a new vertex as long as It is not a bridge.

or

It is a bridge but there is no other alternative.

In either case we have now arrived at a new vertex. Once again, we may have numerous choices as to which edge to trace along, and we may choose any of them as long as The edge is not a bridge for the untraveled subgraph or the edge is a bridge for the untraveled subgraph but there is no other alternative.

Online Study Center

To further explore Euler paths and Fleury’s algorithm, access link 15.2.1 on this textbook’s Online Study Center.

We now repeat this process, avoiding bridges for the untraveled subgraph whenever possible, until we eventually end up at our starting point, completing an Euler circuit as desired.

EX AM P LE 7  Using Fleury’s Algorithm

Determine whether each of the graphs in Figure 15.20, parts (a), (b), and (c), has an Euler circuit. If so, use Fleury’s algorithm to find one. (a)

a

A

B

(b)

(c)

C c

b f

d

c

b

b

A

h

B

a B

D

g

a i A D

e

j

g

d

j

E

i

c

d

C f

f F

e

e

E D

h

C

F I G U R E 15 . 2 0

Solution

(a) Since each vertex has even degree, traversability rule 1 tells us that the graph has an Euler circuit. (i) We will choose vertex A as our starting point (this choice is arbitrary; according to traversability rule 1, any vertex can serve as a starting point). Note that none of the edges meeting A are bridges. This means that we may choose any of them as the first edge of our circuit.

304470_ch15_web_pG1-G45

G14

11/7/06

10:06 AM

15 Graph Theory

A

f

D

d

c

e

(ii) We choose to proceed to vertex B along edge a. Note that edge b is a bridge for the untraveled subgraph (Figure 15.21a); however, we have no alternative but to travel along this edge until we reach vertex C. From C we have three options: Travel along edge c, d, or e.

B

a

b

(iii) Observing the untraveled subgraph (Figure 15.21b), we note that none of these edges are bridges and decide to travel along edge e until we arrive at vertex D. Though edge f is a bridge for the untraveled subgraph, there is no other option: We proceed to vertex A along edge f.

C

(a)

(iv) It is now clear that by traveling from A to C along edge d and returning to A along edge c, we complete an Euler circuit, [a, b, e, f, d, c], as desired.

A

f

D

d

c

e

(b) Since vertices B and E are of odd degree, the graph has no Euler circuit (it does, however, have an Euler path) according to traversability rule 2. (c) Every vertex has degree 4, so the graph has an Euler circuit.

C

(i) We pick A as our starting point and, noting that edge a is not a bridge, travel along edge a, arriving at B. We have three options for the next edge in our circuit: b, c, or g. Since none of these edges are bridges for the untraveled subgraph (see Figure 15.22a), we choose edge g arbitrarily and travel to vertex E.

(b) F I G U R E 15 . 21

a b

A

B

(ii) Once again we have three options: edge d, e, or f. Observing Figure 15.22b, we see that none of these edges is a bridge for the untraveled subgraph and decide to travel along f to D. The untraveled subgraph up to this point is given in Figure 15.22c.

c

(iii) Since edge i is not a bridge for this subgraph, we proceed back to A along i. With edges b or j as our options for the next edge, we check Figure 15.22d and determine that neither is a bridge for the untraveled subgraph.

g j

Page G14

E

i

d

f e D

h

C

(a)

j

B

j

i

E

c

d

c

d

b

A

B

E

i

b

A

b

A

E

j

e D h

(b)

h

c

d e

e D

B

C

D

C

(c)

h

C

(d) F I G U R E 15 . 2 2

(iv) We pick edge j and return to D. Our only option at this point is to travel to C along edge h. The untraveled subgraph at this point is provided in Figure 15.22e. From this subgraph we determine that edge c is a bridge, while edges d and e are not. We avoid c and travel along d to E. From the untraveled subgraph of Figure 15.22f it is clear how to proceed from

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G15

G15

15.2 Euler Paths and Euler Circuits

here: travel along the path given by the sequence of edges [e, c, b], which takes us back to our original starting point and completes the Euler circuit [a, g, f, i, j, h, d, e, c, b]. b

A

B

E

b

A

B

E

c

c

d a b c

e

e C

C

(e)

d

(f) F I G U R E 15 . 2 2 c o n t i n u e d



e

EX AM P LE 8  Finding an Efficient Route

f

We now return to the Portland bridge inspector. We have determined in Example 4 that the graph of Figure 15.13 has an Euler circuit (and, therefore, an inspection route that uses each bridge exactly once exists). Figure 15.23 depicts the same graph with labels added. Determine an efficient route for the inspector.

g h F I G U R E 15 . 2 3

Solution

With Fleury’s algorithm, a solution is easily found. Let us assume that the inspector starts out on the west side of the city. The circuit determined by the sequence [a, b, c, d, e, f, g, h] follows the rules of Fleury’s algorithm and pro vides his desired route.

E X E R C I S E S 15 . 2 A Euler Paths and Circuits

3.

In problems 1–4, determine whether the sequence of edges [a, b, c, d, e] is an Euler path, an Euler circuit, or neither. 1. A

B

b

2. A

b

b c

B

B

C

a d

a

e

c

a

e

c A

D

d

C

D

d

C

D e

304470_ch15_web_pG1-G45

G16

11/7/06

10:06 AM

Page G16

15 Graph Theory

4.

9.

b B

c

C

f a

10.

d

D

A

e

In problems 5–10, use the traversability rules to determine whether the following graphs have an Euler path, an Euler circuit, or neither. You do not need to actually find the path or the circuit. B Finding Euler Paths and Circuits

5.

According to the traversability rules, each of the graphs below has an Euler circuit. Use Fleury’s algorithm to find one for each graph. 11.

12. a

b

e

d

a

i

6.

c

b

h

e

g f

c

j

f g

d

13. b

d

f

c

e

g

a

7.

h

8. 14.

b a

c h

d m

g f

i

e

j l k

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G17

15.2 Euler Paths and Euler Circuits

15.

21.

g h

G17

22.

f e

E ul

b i

rR

e

c

d

ive

r

a Park

16.

c b j i

Online Study Center

h k a

g

To explore similar types of problems, access link 15.2.2 on this textbook’s Online Study Center.

d l

o

In Other Words

n m f

23. Describe the following terms in your own words: a. Traversable graph b. Euler circuit c. Euler path d. Bridge

e

17.

a h l

b

g i

f j

k

c

e d

18.

b

c

a

d

e f

Applications Design a traversable mail route for each of the given neighborhoods. 19.

24. Describe the Bridges of Königsberg problem in your own words.

20.

Using Your Knowledge The following definition will be needed in problems 25–28. A connected graph is planar if it can be drawn so that any two edges intersect only at vertices. For example, the graph in problem 9 is planar, whereas the graph in problem 10 is not planar. Notice that a planar graph divides the page into various regions so that you must cross over at least one edge to get from one region to another. For example, the graph in problem 1 divides the page into three regions: the two triangular regions “inside” and the single region “outside.” If G is a planar graph, the Euler characteristic of G is given by the formula X(G)  R  E  V where R is the number of regions, E is the number of edges, and V is the number of vertices.

Town Square

Town Triangle

25. Calculate X(G), where G is the graph in problem 1. 26. Calculate X(G), where G is the graph in problem 4. 27. Calculate X(G), where G is the graph in problem 5. 28. Calculate X(G), where G is the graph in problem 9.

304470_ch15_web_pG1-G45

G18

11/7/06

10:06 AM

Page G18

15 Graph Theory

Research Questions 1. Have you heard of the four-color problem? It concerns the minimum number of colors that are needed to color a map so that no two countries sharing a common border have the same color. It is a problem that troubled mathematicians for more than a century. It is also a problem to which graph theory can be applied. Write a brief report on the four-color problem. What does graph theory have to do with it? How was it finally solved? 2. The Euler characteristic is described prior to problem 25. What do you notice about the Euler characteristic of any planar graph (completing problems 25–28 will give you a clue)? Write a brief report on the Euler characteristic and how it can be used to solve many geometric problems. 3. Write a brief report on the history and the solution of the Bridges of Königsberg problem.

Hamilton Paths and Hamilton Circuits

IN

G START

The Traveling Hitchhiker

E

GE

D

TT

15.3

Have you been to Yellowstone Park? If you decide to park your car at one of the four entrances and visit certain locations in the park once and only once, can you do it? It depends on which locations you choose! If you go to Example 2, we will show you how a hiker did it, and then you can visit on your own.

A. Hamilton Paths and Circuits In Section 15.2 we considered the problem of finding paths or circuits that use each edge of a graph once. Now we will investigate a similar problem: Given a graph such as the one in Figure 15.24, can we find a path that meets each vertex once (and only once)? Such a path is called a Hamilton path. F I G U R E 15 . 2 4

Hamilton Circuit

A path that meets every vertex once and then returns to the starting point is called a Hamilton circuit.

As usual, if a Hamilton circuit begins and ends at vertex A, we say that the circuit is based at A. Figure 15.25 gives some examples of Hamilton paths, whereas Figure 15.26 provides examples of Hamilton circuits.

F I G U R E 15 . 2 5

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G19

15.3 Hamilton Paths and Hamilton Circuits

G19

F I G U R E 15 . 2 6

Naturally, we are led to the problem of determining whether a particular graph has a Hamilton path or circuit. In the case of finding Euler circuits, we had a rule for deciding whether a graph has an Euler circuit (the traversability rules) and a method for actually finding one (Fleury’s algorithm). Unfortunately, there is no efficient algorithm for finding Hamilton circuits. In fact, there is at present no theorem that provides necessary and sufficient conditions for determining whether a graph even has a Hamilton circuit. In other words, when faced with a particular graph, the only way to find a Hamilton circuit is by trial and error. Although there is no efficient algorithm for finding Hamilton circuits, this shouldn’t prevent us from attempting to find them. In many cases, finding a Hamilton circuit in a graph is quite simple. EX AM P LE 1  Finding a Hamilton Circuit

Find a Hamilton circuit in each of the graphs in Figure 15.27.

F I G U R E 15 . 2 7

Solution

Starting at any vertex and following the indicated edges in either direction completes a Hamilton circuit in each of the graphs, as shown in Figure 15.28. Of course, those are not the only ones. Can you find any others?

F I G U R E 15 . 2 8



Not surprisingly, the theory of Hamilton circuits has numerous applications to real life, as illustrated in Example 2.

304470_ch15_web_pG1-G45

G20

11/7/06

10:06 AM

Page G20

15 Graph Theory

EX AM P LE 2  Finding a Hamilton Circuit

A hiker plans to visit Yellowstone National Park, entering at the West Entrance. Beginning at Madison Junction, he would like to visit each of the locations indicated on the Yellowstone map (Figure 15.29) once and only once and then return to Madison Junction. Can the hiker accomplish this goal? Mammoth Hot Springs

Tower Junction

Mammoth Hot Springs Tower Junction

Madison Junction

Lake

Madison Junction

Norris Junction West Entrance

Canyon

Norris Junction

Canyon

Lake Bridge Bay

Bridge Bay

Old Faithful

Old Faithful West Thumb

West Thumb F I G U R E 15 . 3 0

F I G U R E 15 . 2 9

Solution

By now we know that this question can be restated in terms of graph theory. By representing each destination as a vertex and the roads joining them as edges (as in Figure 15.30), the hiker will be able to visit each destination once and only  once if we can find a Hamilton circuit on the graph. Can you find one?

B. Weighted Graphs Weighted graphs are useful in a number of branches of mathematics. Weighted Graph Corbis A geyser at Yellowstone.

A weighted graph is a graph for which each edge has a number called a weight associated to it.

A typical weighted graph is shown in Figure 15.31 on page G21.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G21

G21

15.3 Hamilton Paths and Hamilton Circuits

5 10

6

3

1

10

8

8 4 F I G U R E 15 . 31

Given a path (or circuit) in a weighted graph, the length of the path is the sum of the weights of each of its edges. Notice that for any path, the path obtained by reversing the order of the edges has the same length as the original path. We shall therefore not distinguish between the two. EX AM P LE 3  Finding the Length of a Path or Circuit

For each of the weighted graphs, Figures 15.32a and 15.32b, find the length of the path or circuit indicated (note that for circuits you may choose any vertex as a starting point). (a)

(b)

12

4

12

4 2

3

7 6

3

2

7

6 F I G U R E 15 . 3 2

Solution

To accomplish the task, we need only add the weights of each of the edges indicated. (a) The length is 4  2  7  13. (b) The length is 12  7  2  4  25.



When a mail carrier delivers mail, he or she would like to choose a route that involves the least amount of walking. When planning a vacation trip to multiple destinations, a travel agent will try to find the least expensive airline routes for a client. When a salesman plans a business trip to numerous cities, he would like to minimize the total distance he must travel. These are just a few examples of a famous (and quite difficult) problem in mathematics called the Traveling Salesman Problem. EX AM P LE 4  Finding an Efficient Route Henry Diltz/Corbis

Suppose a salesman lives in New York City. On his next business trip he would like to visit clients in Miami, Los Angeles, and Seattle in the most efficient manner. In particular, he would like to visit each city once and only once. He would also like to plan the most cost-effective trip. The airline that the salesman uses

304470_ch15_web_pG1-G45

G22

11/7/06

10:06 AM

Page G22

15 Graph Theory

offers service between each pair of cities. The prices for a one-way ticket (in either direction) are indicated on the map in Figure 15.33. Seattle 329 159

439 New York

209 Los Angeles

119 369 Miami

F I G U R E 15 . 3 3

Solution

As you can see, this situation can be clearly illustrated using the techniques of graph theory. Each destination is represented by a vertex and each flight by an edge joining the corresponding vertices. The cost of a one-way ticket between a pair of cities is the weight of the corresponding edge. Since the salesman would like to visit each destination once and only once before returning home, he will plan his trip by searching for a Hamilton circuit on the graph in Figure 15.34. In addition, he would like to choose the trip that costs the least. By tracing out each Hamilton circuit on the graph and calculating their lengths, we can deduce which route is optimal. As mentioned previously, reversing the order of any particular Hamilton circuit does not change the weight of the circuit. Thus, there are only three distinct Hamilton circuits to be considered. Seattle

329 209

439

159

F I G U R E 15 . 3 4

Los Angeles

New York

119

369

Miami

New York → Seattle → Miami → Los Angeles → New York Weight  329  439  369  209  1346 New York → Seattle → Los Angeles → Miami → New York Weight  329  159  369  119  976 New York → Los Angeles → Seattle → Miami → New York Weight  209  159  439  119  926 Since the third route has the least weight, $926, it is the solution to the Traveling  Salesman Problem.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G23

15.3 Hamilton Paths and Hamilton Circuits

G23

C. The Nearest-Neighbor Method As mentioned previously, there is no efficient algorithm for finding Hamilton circuits in a graph. But we have seen that in traveling salesman problems, finding such circuits is the key to obtaining a solution. In simple cases, a brute-force approach can be successfully employed (as was done in Example 4), but for complicated weighted graphs, the number of Hamilton circuits based at a given vertex may become so large that even high-speed computers could not perform the necessary calculations in our lifetime! Fortunately, in many cases there is an algorithm that will provide us with an approximate solution to a traveling salesman problem. This approximate solution, though not usually a circuit of shortest length, will have a length that is reasonably close to a Hamilton circuit of minimal length. Recall that the complete graph Kn is the graph with n vertices in which each pair of vertices is joined by exactly one edge. It is obvious that for any n, the complete graph Kn has a Hamilton circuit. In fact, it can be shown that for any vertex in Kn, there are (n  1)!/2 different Hamilton circuits based at that vertex. Thus, for large values of n, the number of Hamilton circuits for Kn is incredibly large. For example, the graph K10 has 181,440 different Hamilton circuits based at any given vertex! In such a situation, computing the lengths of all possible Hamilton circuits is not practical. This is precisely the reason that an efficient algorithm is desirable, even if the answer we obtain is only an approximate solution.

A

F I G U R E 15 . 3 5 K8 has 2520 different Hamilton circuits based at A.

EX AM P LE 5  Finding Hamilton Circuits A

Find all Hamilton circuits based at vertex A indicated in the complete graph K5 in Figure 15.36. Solution K5 F I G U R E 15 . 3 6

According to the formula given above, there will be [(5  1)!]/2  12 different Hamilton circuits (remember that a circuit in the reverse order is not counted separately). Therefore, the circuits given in Figure 15.37 on page G24 provide a complete listing of all distinct Hamilton circuits based at A.

304470_ch15_web_pG1-G45

G24

11/7/06

10:06 AM

Page G24

15 Graph Theory

A

A

A

A

A

A

A

A

A

A

A

A

F I G U R E 15 . 3 7



Even though complete graphs have a large number of Hamilton circuits, these are precisely the graphs we are interested in. We will consider complete weighted graphs (i.e., complete graphs with weights associated with each edge). It turns out that for such graphs there is a simple algorithm for producing a nearly minimal Hamilton circuit, one that has a relatively short length. In applications, this nearly minimal Hamilton circuit will be used as an approximate solution to traveling salesman problems. The algorithm is called the nearest-neighbor method. Nearest-Neighbor Method

1. Given a complete weighted graph, begin at the indicated starting point. If none is indicated, choose one at random. 2. In deciding which vertex to visit next, choose to travel along the edge with the smallest weight (the vertex at which we arrive is the “nearest” neighbor). If there is more than one edge of minimal weight, choose one at random. 3. From the new vertex, repeat this process: Choose to travel along the edge that has the smallest weight (don’t return to the previous vertex; we want a Hamilton circuit). If there is more than one edge of minimal weight, choose one at random.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G25

G25

15.3 Hamilton Paths and Hamilton Circuits

4. Continue in this fashion: From each new vertex, travel to an unvisited vertex along the edge of least weight, choosing an edge at random if there is more than one edge of minimal weight. 5. Once every vertex has been visited, return to the starting point along the edge with smallest weight. Once again, if there is more than one edge of minimal weight, choose one at random. The circuit that has been traced out is a nearly minimal Hamilton circuit.

EX AM P LE 6  Using the Nearest-Neighbor Method

For each of the graphs in Figures 15.38a and 15.38b, use the nearest neighbor method to find a nearly minimal Hamilton circuit based at vertex A. What is the weight of the circuit you found? (a)

(b)

E 8 3

D

5

A

8 4

2

B

3

6

6 4

B 6

2

7

10

3

E

3 3

4

4

6

7

A 1

F

D 5

C

9

3 C

F I G U R E 15 . 3 8

Solution

E 8

7 3

A

D

5 1

8 4

B

3

4

6

(a) F I G U R E 15 . 3 9

C

(a) (i) Among the edges emanating from vertex A in the graph on the left, the edge joining A and B has the least weight, so this will be the first edge of our circuit. Since we cannot return to vertex A at this point, we consider the other three edges that meet B and determine that the edge joining B and D has the least weight. This edge is the second of our circuit. (ii) From D we need only consider the edges that proceed to C and E (the other edges would take us to vertices that we have already visited). Since the edge that joins C and D has the smaller weight, we use this as the third edge of our circuit. (iii) At this point we have no choice but to continue on to vertex E and then complete our circuit along the edge joining A and E. The actual circuit is given in Figure 15.39a. The weight of this circuit is 1  4  3  8  8  24 (b) (i) Among the edges emanating from A in Figure 15.39b on page G26, the edge joining A and D has the least weight and will, therefore, become the first edge of our circuit.

304470_ch15_web_pG1-G45

G26

11/7/06

10:06 AM

Page G26

15 Graph Theory

F 4

6 A

E

3 2

3

2

7

10

3

6

6 4

B

D 5

9

3

(ii) From D there are two edges of least weight along which we may proceed (remember, we cannot return to A): the edge joining C and D and the edge joining D and E. We choose at random the edge joining D and E as the second edge of our circuit. (iii) From E we will proceed to C because it is the edge of least weight emanating from E. From C we must proceed to F because the edge joining C and F has the least weight among edges along which we are allowed to travel. At this point there is no alternative: We continue on to vertex B and then return to starting point A. Figure 15.39b shows the circuit determined by the nearest-neighbor method. The weight of this circuit is 2  3  2  5  6  10  28

C

(b) F I G U R E 15 . 3 9 c o n t i n u e d



The nearest-neighbor method is an effective way to find an approximate solution to many traveling salesman problems, as shown in Example 7.

EX AM P LE 7  Using the Nearest-Neighbor Method

Suppose our salesman is based in Los Angeles. He needs to visit clients in Salt Lake City, Seattle, Denver, Dallas, Chicago, and New Orleans (Figure 15.40). We can assume, not unreasonably, that from any of the cities listed there is an airline flight to any of the other cities. We will also assume that the order in which he visits the cities does not matter. His only objective is to accomplish the trip as inexpensively as possible. The price of a one-way ticket between two cities (in either direction) is given in Figure 15.41. Seattle

Salt Lake City

Denver Chicago

Los Angeles Dallas New Orleans

F I G U R E 15 . 4 0

The first step is to represent this problem as a weighted graph. We have one vertex for each city and one edge for each pair of cities (representing the flight between two cities). Notice how the weight corresponding to an edge is the cost of a one-way ticket between the two cities. What we obtain is a complete weighted graph. Our goal now is to obtain an inexpensive travel itinerary for the salesman. We will use the nearest-neighbor method to accomplish this.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G27

G27

15.3 Hamilton Paths and Hamilton Circuits

Chicago 189

240 169

115

Seattle

Dallas

220 127

239

159

119 79

99 99

79

179

145

88

Los Angeles

Denver 345

89 99

118

Salt Lake City

130

New Orleans

F I G U R E 15 . 41

Online Study Center

To explore a similar example solved by the brute-force method and then giving a motivation for the nearest neighbor method, access link 15.3.2 on this textbook’s Oneline Study Center.

The salesman is based in Los Angeles, so this will be the initial vertex of our Hamilton circuit. The edge joining Los Angeles and Denver has the least weight and therefore, will be the first edge of the circuit. The next edge will be the one joining Salt Lake City and Denver because it has the least weight among edges that do not lead to Los Angeles. From Salt Lake City, the clear choice is to proceed to Dallas. The edge of least weight emanating from Dallas leads to the next destination: New Orleans. After a night on Bourbon Street, the salesman is ready for his next flight. Although the edges from New Orleans to Denver, Salt Lake City, and Los Angeles have smaller weight among the edges emanating from New Orleans, he goes to Chicago (remember, he wants to complete a Hamilton circuit). His final destination before returning to Los Angeles is Seattle—the only unvisited vertex. LA → Denver → SLC → Dallas → N.O. → Chi → Seattle → LA Weight: 88  89  79  79  145  189  159  828 The itinerary is shown on the first line, and the cost is $828.



304470_ch15_web_pG1-G45

G28

11/7/06

10:06 AM

Page G28

15 Graph Theory

E X E R C I S E S 15 . 3 6.

A Hamilton Paths and Circuits

6

In problems 1–4, determine whether the sequence of edges [a, b, c, d, e] represents a Hamilton path, a Hamilton circuit, or neither.

7

14

5 1

1.

2

c

7. b

8.

d

g

5

h

4

3

4

f 5

7 3

e

5

a

2. A

3

4

2

b

9. Find the lengths of all Hamilton circuits based at vertex A.

B

5

A e

a

c 3

4

5

d D

7

C f

5

3.

4. a

A e

10. Find the lengths of all Hamilton circuits based at vertex B.

B

B

5 a

f

d

b

j

A

c

e

C

5 D

B Weighted Graphs

In problems 5–8, determine the length of the indicated path or circuit. 5. 3

C The Nearest-Neighbor Method

In problems 11–16, use the nearest-neighbor method to find a nearly minimal Hamilton circuit based at the vertex A and find the length of the circuit (answers may vary). 11. A

2 4

5

12. A

6 4

2

3

8

7

c

h

d

E

5

g i

3

4

C

f D

B

b

6

3

9

2

2

5

6

5

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G29

15.3 Hamilton Paths and Hamilton Circuits

14. 2

19. 2

5 4

A 2

3

13

7 6

4 1

8

1

er

15

4 3

13.9

19

5

A

6

20.

17

1

2

Lake Hamilton

18.6

31.2 35.0

15 23.5

25

1

1

15.

9

Web It Exercises

1 5

8 2

Did you know that there are three common styles for lacing shoes? The idea is to find the shortest path from the top eyelet (or lace hole) on one side to the top eyelet on the other side, passing through every eyelet just once. What are the three common styles for lacing shoes, and which style do you use? Which style requires the shortest and which the longest length of lace? What is the connection between lacing shoes and the Traveling Salesman Problem? To answer these three questions, visit www.maa.org/mathland/mathtrek_2_8_99.html. In this section we studied the nearest-neighbor method, an algorithm for producing a nearly minimal Hamilton circuit. Find three other algorithms that produce a nearly minimal Hamilton circuit, and write the procedure used in each of them. (Hint: Go to http://www.ctl.ua.edu/math103/ for ideas.)

7 6

A

6

2 5

4

1 6

3

1

16.

5 7 3

3 7

7 6

A

3

5 4 10

1 11 5

In Other Words

2

In problems 17–20, use the nearest-neighbor method to find a delivery route of minimal length starting and ending at the indicated vertex so that each of the vertices is visited once and only once. 17.

18. 12

15

29 Central Park 19

Blue Lake

22

22. In your own words, explain what a Hamilton path is. What is the difference between a Hamilton path and a Hamilton circuit?

24. Describe the difference between an Euler circuit and a Hamilton circuit.

21

9

21. Describe the Traveling Salesman Problem in your own words.

23. Describe the nearest-neighbor method in your own words.

29

8

11

29.1 Riv Ga uss

13.

G29

17

Using Your Knowledge Lake Overneath

38

In this chapter we used the nearest-neighbor method to solve the Traveling Salesman Problem and other

304470_ch15_web_pG1-G45

G30

11/7/06

10:06 AM

Page G30

15 Graph Theory

related problems. In these problems we always started at one particular vertex and proceeded to find a nearly minimal Hamilton circuit. What happens if we try starting at a different vertex? Might we find an even shorter Hamilton circuit? Let’s find out! 25. Pick any vertex (other than A) on the graph in problem 11. Apply the nearest-neighbor method to find a nearly minimal Hamilton circuit based at the vertex you chose. Compare your answer with your result from problem 11. 26. Pick any vertex (other than A) on the graph in problem 12. Apply the nearest-neighbor method to find a nearly minimal Hamilton circuit based at

the vertex you chose. Compare your answer with the result from problem 12. 27. Pick any vertex (other than A) on the graph in problem 13. Apply the nearest-neighbor method to find a nearly minimal Hamilton circuit based at the vertex you chose. Compare your answer with the result from problem 13. 28. Pick any vertex (other than A) on the graph in problem 14. Apply the nearest-neighbor method to find a nearly minimal Hamilton circuit based at the vertex you chose. Compare your answer with the result from problem 14.

Research Questions 1. Recall that the number of Hamilton circuits for a complete graph with n vertices is (n  1)!/2. Go to the library (or the Internet) and find out why this is true. Write a brief report on your findings. 2. Go to the library (or the Internet) and find other interesting applications for Hamilton circuits. Write a brief report on your discoveries.

G START

The Trees and the Bees

D

GE

IN

Trees

E

TT

15.4

Do you know your roots? Have you ever worked on your family tree? What about the family tree for a male bee? What about for a female bee? Are they always different? For an answer, go to Collaborative Learning in Exercises 1.1 in the text. For a lot of trees, visit www.ee.surrey.ac.uk/Personal/R.Knott/ Fibonacci/fibnat.html#Rabbits.

A. Trees and Forests Recall that a graph is connected if, for any pair of vertices, there is a path joining them. Definition of a Tree

A tree is a connected graph in which there are no simple circuits. A graph that has no circuits but is not necessarily connected is called a forest.

EX AM P LE 1  Determining Trees and Forests

Determine whether each of the graphs, (a), (b), and (c), in Figure 15.42 is a tree, a forest, or neither.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G31

15.4 Trees

(a)

G31

(b)

(c)

The Auto Tree, Big Basin, California.

F I G U R E 15 . 4 2

Solution

(a) Neither

(b) Tree



(c) Forest

The unique path property is an important property that all trees have. TH EO R EM 15.1 Unique Path Property

For any two vertices in a tree, there is exactly one simple path joining them.

In Section 15.3 we discussed Hamilton circuits, which are circuits that meet every vertex of a graph. Spanning Tree

A spanning tree (or maximal tree) in a graph is a tree that meets every vertex of the graph.

EX AM P LE 2  Finding a Spanning Tree

Find a spanning tree for each of Figure 15.43, parts (a) and (b). (a)

(b)

F I G U R E 15 . 4 3

304470_ch15_web_pG1-G45

G32

11/7/06

10:06 AM

Page G32

15 Graph Theory

Solution

There are numerous spanning trees for each of the graphs. We have indicated one for each of the graphs (a) and (b) in Figure 15.44. (a)

(b)



F I G U R E 15 . 4 4

We have seen examples of graphs and their spanning trees. Naturally, we might wonder whether it is possible for a (connected) graph to have no spanning trees. The following theorem tells us that this cannot happen: TH EO R EM 15.2 Existence of Spanning Trees

Every connected graph has at least one spanning tree.

B. Labeled Graphs and Spanning Trees Suppose that we have a weighted graph. We know from Theorem 15.2 that this graph has at least one spanning tree (and may have many). The weight of a spanning tree in a labeled graph is the sum of the weights of each of the edges in the tree. A minimal spanning tree is a spanning tree with the least weight. 4

7

EX AM P LE 3  Finding a Minimal Spanning Tree

Find a minimal spanning tree in the complete weighted graph in Figure 15.45. 2 F I G U R E 15 . 4 5

Solution

The graph in Figure 15.45 has three distinct spanning trees, which are shown in Figures 15.46a to c. To find the minimal spanning tree, we simply compute the weight of each spanning tree and choose the one with minimal weight. (a) 4  7  11

(b) 4  2  6

(c) 2  7  9

Thus, the spanning tree in Figure 15.46b is minimal. (a)

(b) 4

7

2

(c) 4

7

2 F I G U R E 15 . 4 6

4

7

2 

Typically, a graph has many spanning trees, so attempting to find a minimal spanning tree by brute force (as we did in Example 3) would be a tedious

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G33

15.4 Trees

G33

exercise when the graph is complicated. Thankfully, there is an algorithm for finding a minimal spanning tree. Kruskal’s Algorithm

1. Start with the edge of least weight in the graph. If there is more than one, choose one of them at random. This is the first edge of a subgraph that we will use to form our minimal spanning tree. B 1

2. Out of the edges not yet selected, choose the edge of minimal weight (this edge does not have to share a vertex with the other edge). If there is more than one edge of minimal weight, choose one at random.

5 5

A

C

6 13

6 2

4

3

5

E

3. Out of the remaining edges, choose any edge of minimal weight as long as the subgraph of selected edges does not form a circuit. If there is more than one edge of minimal weight, choose one at random. 4. Repeat step 3 until the subgraph contains all vertices of the original graph.

D

F I G U R E 15 . 4 7

We will now illustrate Kruskal’s algorithm with an example.

B 1

5 EX AM P LE 4  Finding a Minimal Spanning Tree

5

A

C

6 13

6 2

4

3

Find a minimal spanning tree in the complete weighted graph given in Figure 15.47. Solution

We apply Kruskal’s algorithm as follows: E

5

1. The edge joining vertices A and B has weight 1, so we choose it as the first edge of our spanning tree.

D

F I G U R E 15 . 4 8

Online Study Center

To further explore Kruskal’s algorithm, access link 15.4.1 on this textbook’s Online Study Center.

C

2. The edge joining vertices A and D has weight 2 and will therefore be the next edge. 3. The edge joining vertices C and E has weight 3 and will therefore be the next edge. 4. Finally, the edge joining vertices C and D has weight 4 and will complete our  spanning tree, in Figure 15.48. Like Euler circuits and Hamilton circuits, spanning trees have numerous applications. We now discuss how Kruskal’s algorithm can be used to find efficient solutions to some real-world problems.

D

B

EX AM P LE 5  Finding a Subgraph

A

W F I G U R E 15 . 4 9

A farmer wants to install a new irrigation system for his farm, which is divided into four distinct plots of land as shown in Figure 15.49. The water is to be drawn from a well and fed to each of the four sprinkler systems by pipes. It is possible to connect any two points on the farm by pipe. To illustrate this, the farmer draws a graph with vertices representing the sprinkler

304470_ch15_web_pG1-G45

G34

11/7/06

10:06 AM

Page G34

15 Graph Theory

systems and the well, whereas the edges represent possible connecting pipes. He labels the vertices corresponding to the sprinklers A, B, C, and D and the vertex corresponding to the well W. It should not be surprising that the graph the farmer draws will be a complete graph (see Figure 15.50).

Corbis Anton’s farm.

PhotoDisc/Getty Images A farming irrigation system.

B

To ensure that water reaches each of the four sprinklers, the farmer needs to find a subgraph of the complete graph that is connected and meets each of the five vertices. For example, each of the subgraphs in Figure 15.51 would accomplish the task.

C

B A

C

B

C

D

W

A

D

A

D

F I G U R E 15 . 5 0

W

B

W

C

A

B

D

C

A

W

D

W F I G U R E 15 . 51

The farmer would like to design the irrigation system so that its cost is as low as possible, so he calculates the cost of connecting any two points with a pipe.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G35

15.4 Trees

62

B 38

45

25 A

The costs are indicated in Figure 15.52. Find the subgraph and the lowest possible cost for the irrigation system.

C 42

Solution

38

81 D

90 49

G35

54

Since it is unnecessary to have more than one source of water feeding any particular sprinkler, there need be only one path in the subgraph starting at vertex W and ending at any of the other vertices. In other words, the subgraph will be a tree, and since the tree will meet each of the vertices, it will be a spanning tree. Possible spanning trees are indicated in Figure 15.53.

W F I G U R E 15 . 5 2

B

C

A

B

D

A

D

W

B

W

C

A

C

B

D

C

A

W

D

W F I G U R E 15 . 5 3

62

B 38

45

42

25 A

C

To design the irrigation system with the lowest possible cost, the farmer needs to find a minimal spanning tree. To find the desired result, he applies Kruskal’s algorithm.

38

81 D

90 49

54 W

F I G U R E 15 . 5 4

1. The edge joining vertices B and W has minimal weight (25) and, therefore, will be the first edge of the spanning tree. 2. The edge joining vertices A and C and the edge joining vertices C and D both have minimal weight (38) among the remaining edges, and since no circuit is formed, each of these edges will be included in the spanning tree. 3. Adding the edge joining vertices B and D (42) completes the spanning tree in Figure 15.54. The total cost of the irrigation system is the weight of the spanning tree, that  is, 25  38  38  42  $143.

304470_ch15_web_pG1-G45

G36

11/7/06

10:06 AM

Page G36

15 Graph Theory

E X E R C I S E S 15 . 4 7.

A Trees and Forests

8.

In problems 1–4, determine whether the given graph is a tree or not. 1.

a b

2.

b

f

a

c

e c

d

d

9.

10.

e

3.

f

b

a

a

d

g

d

b

g

e l

c

h

f

h i k

j

c

4. B Labeled Graphs and Spanning Trees

In problems 11–16, use Kruskal’s algorithm to find a minimal spanning tree, and then find its weight. 11.

12. 6

In problems 5–10, specify the edges needed to determine a spanning tree in the given graph. (Answers may vary.) 5.

3 3

2 8

6

1

5

5

6.

f

d

c a

k f

2

4

13. 3 2

j

3

7 3

i

4 1

9

6 h

1

4

6

e

d g

4

4

c

e

a

6

b

b

2

7

1

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G37

15.4 Trees

14.

4 7

In Other Words

1 1

2

1

3 1

1

21. In your own words, describe a spanning tree.

2

4 4

9

2

7

4

1

11

1

22. Describe Kruskal’s algorithm in your own words.

4

8

23. Describe the unique path property in your own words.

2 7

2

15.

24. Describe in your own words the difference between a tree and a forest.

16. 2 4

2

4

4

1 7

5 8

6

Using Your Knowledge

6 3 8

3 3

2

8 6

3 3

7

5 4

In problems 17–18, use Kruskal’s algorithm to find a minimal spanning tree representing the most economical way to link the towns shown as vertices. The cost (in millions) of linking two towns is indicated by the number on the corresponding edge. 17.

18. Cayley’s R i

6.1

17

4.9 3.8 9.1 K ru sk R i v e al’ s r

7.8

C 59

55

ver

7 10 11

15

12.7

25. Amazon Telephone & Telegraph Company (AT&T) is beginning a project to bring telephone service to a remote area of the Amazon. The cost of laying line between towns is listed below (in millions), and the company wants to find the cheapest way to lay telephone line so that all the cities are connected. (The line must be run along the existing roads because of the huge cost and danger in running the line through the jungle.) Would either Euler or Hamilton circuits or paths help the company find the cheapest way to do this? Why or why not?

B

14

11.8

G37

11

Kruskal’s Forest 10

56 62

64 51

A

11

5.4

D

51 49

5

8

E 53

45

F 74

42 G

In problems 19–20, use the procedure of Example 5 to design an irrigation system of minimal cost. 19.

Source: Courtesy of Professor Larry Bowen, University of Alabama.

20. Web It Exercises 145

132 164

96 98

148

178 141

135

126

148

119

89

126

161

57

107

Recently, Center for Research and Parallel Computation (CRPC) researcher Bob Bixby (Rice University) and colleagues David Applegate (AT&T Bell Labs), Vasek Chvatal (Rutgers University), and William Cook (Bellcore) using a network of a SPARC 2, DEC Station 5000, SGI workstation, and others (a total of 50 workstations) determined an optimal route for a traveling salesman going through 3038 cities, a dramatic step beyond the old record of 2392 cities set by

304470_ch15_web_pG1-G45

G38

11/7/06

10:06 AM

Page G38

15 Graph Theory

M. Padberg and G. Rinaldi. Trace the origins of the Traveling Salesman Problem starting in the 1920s and going through the 1930s and 1940s. (Hint: Find

some information at http://softlib.rice.edu/CRPC/ newsletters/jan93/news.tsp.html and www.keck.caam .rice.edu/tsp/history.html.)

Research Questions 1. Theorem 15.2 states that every connected graph has at least one spanning tree. Go to the library (or the Internet) to find out why this is true. Write a brief report on your findings. 2. Write a brief report on other interesting applications of Kruskal’s algorithm.

Chapter 15 Summary Section

Item

Meaning

15.1

Graph

A collection of points, called vertices, and arcs or line segments, called edges, which join pairs of vertices

15.1

Vertex

A vertex may be an endpoint of any number of edges, or it may stand alone in a graph.

15.1

Degree of a vertex

The number of edges, which have the vertex as a common endpoint

15.1

Subgraph

A graph that consists of some of the vertices and edges of another graph

15.1

Path

A sequence of edges that can be traced along without lifting the pencil

15.1

Circuit based at A

A path that begins and ends at the vertex A

15.1

Connected graph

A graph for which any two vertices can be joined by a path

15.1

Complete graph

A graph in which every pair of vertices is joined by exactly one edge

15.1

Kn

A complete graph with n vertices

15.2

Euler path

A path that uses every edge of a graph once and only once

15.2

Euler circuit

An Euler path that begins and ends at the same vertex

15.2

Traversable graph

A graph that has an Euler path (or circuit)

15.2

Bridge

An edge in a graph that, when removed, creates a disconnected graph

15.2

Untraveled subgraph

The edges that have not been used when building an Euler circuit

15.2

Fleury’s algorithm

An algorithm used to find Euler circuits

15.3

Hamilton path

A path that meets each vertex once and only once

15.3

Hamilton circuit

A path that meets every vertex once and then returns to the starting point

15.3

Weighted graph

A graph for which each edge has a number called a weight associated to it

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G39

Chapter 15 Summary

G39

Section

Item

Meaning

15.3

Nearest-neighbor method

An algorithm used to find an approximate solution to a traveling salesman problem

15.4

Tree

A connected graph in which there are no simple circuits

15.4

Forest

A graph that has no circuits but is not necessarily connected

15.4

Unique path property

For any two vertices in a tree, there is exactly one simple path joining them.

15.4

Spanning tree

A subgraph that is a tree and contains every vertex of the original graph

15.4

Existence of spanning trees

Every connected graph has at least one spanning tree.

15.4

Minimal spanning tree

A spanning tree with the least weight

15.4

Kruskal’s algorithm

An algorithm used to find a minimal spanning tree

Research Questions 1. In Section 15.3 we learned that there is no known procedure for deciding whether an arbitrary graph has a Hamilton circuit. There are, however, some partial results about Hamilton circuits; that is, graphs that satisfy certain conditions are guaranteed to have a Hamilton circuit. Want to know what these conditions are? Go to the library (or the Internet) and find out! Write a brief report on your findings. When possible, include the names of the individuals involved. 2. Recall from Exercises 15.3 that a simple graph is planar if it can be drawn so that edges intersect only at their vertices (or not at all). How can we decide if a particular graph is planar? The answer to this question is known as Kuratowski’s theorem. Write a short paper about this theorem, taking care to describe the key ideas involved.

Paul Erdös, the globe-trotting genius.

George Paul Csicsery Paul Erdös, the globe-trotting genius.

3. Paul Erdös (1913–1996) is universally recognized as one of the most brilliant and prolific mathematicians of the twentieth century. He authored or coauthored more than 1500 research articles and was renowned for his ability to pose (and often solve) problems crucial to the advancement of mathematics. For most of his adult life he had no home of his own, preferring instead to travel the globe and do mathematics with his many collaborators. One of his specialties was—you guessed it—graph theory. By the way, his last name is pronounced “air-dish.” These projects are designed to give you a glimpse into the life and mind of the man affectionately known as “Uncle Paul.” In addition to being one of the brightest mathematicians of his time, Erdös was also considered quite eccentric. His mastery of numbers did not extend to the real world, and he was hopelessly lost when it came to even the simplest of everyday tasks. He was 21 years old before he learned to butter his own toast (until then his mother had always done it for him)! Write a brief report on the life of Paul Erdös. Discuss both his achievements and the amusing character traits that made him beloved throughout the mathematics community.

304470_ch15_web_pG1-G45

G40

11/7/06

10:06 AM

Page G40

15 Graph Theory

4. If Paul Erdös couldn’t solve a particular problem, he encouraged others to try. In fact, he kept a list of unsolved problems and offered cash prizes to those who could solve them (ranging from a few dollars for the “easy ones” up to thousands of dollars for the most challenging ones). Even after his death, this list (and the prize money) is maintained by some of his friends. One of these still-unsolved problems is called the degree/diameter problem. Write a short paper describing it. Be careful to include all relevant concepts: If you solve it, you win the prize! 5. Did you know that graphs can sing? Go to www-cse.ucsd.edu/ users/fan/ and hear it for yourself! What’s going on here? Write a short paper on how graph theory can be “music to your ears.” 6. In this problem you will learn that, in addition to being musically inclined, graphs have quite colorful personalities. They also prefer to hang out with their peers. Go to the library (or the Internet) to find out about cliques, graph colorings, and the chromatic number assigned to each graph. Write a brief paper on your findings. In particular, explain the relationship between the chromatic number and the clique number. For Web surfers, the site http://mathworld.wolfram.com is a good place to start.

Chapter 15 Practice Test For problems 1 and 2, find the degree of each of the vertices in the graph. 1.

2. A

B A

B G

C

C

D

E

F

E

Use the following graph for problems 3–6: a g

A

B b

e d

E

C c f

D

D

Page G41

G41

Chapter 15 Practice Test

3. Does the sequence of edges [a, b, c, d] represent a path, a circuit, or neither? 4. Does the sequence of edges [ g, a, e, d] represent a path, a circuit, or neither? 5. Does the sequence of edges [b, c, f ] represent a path, a circuit, or neither? 6. Does the sequence of edges [g, d, b, c, f ] represent a path, a circuit, or neither? In problems 7–10, determine whether the graph has an Euler path, an Euler circuit, or neither. If the graph has an Euler path, which vertices must form its beginning and ending points? If the graph has an Euler circuit, use Fleury’s algorithm to find one. 7. A

B

a g

f

8. A

C

b h

f e

F

d

E

B

a

c

e

d

E

9.

a

A

B e

f

C b

F

10. A

c

d

D

d

D

D

c E

a

B e

f

C

b

D

F

C b

c E

g

11. A Tampa mail carrier’s territory is shown in the following map. Is it possible for the mail carrier to walk along each street shown once and only once? W Neptune St W Aguilla St W Estrella St W Sitios St W Angeles St W San Rafael St

S Habana Ave

10:06 AM

S Marti St

11/7/06

S Macdill Ave

304470_ch15_web_pG1-G45

304470_ch15_web_pG1-G45

10:06 AM

Page G42

15 Graph Theory

Madison Ave

Greenback Ln Sunrise Ave

80

San Juan Ave

12. A Sacramento County employee must inspect the roads indicated on the map below. His job is to report any major potholes in the roads. Is it possible for the employee to drive along each of the roads once and only once?

Manzanita Ave

G42

11/7/06

Sunset Ave

Fair Oaks Blvd

In problems 13 and 14, determine which edges are bridges. 13.

14. d

a k

h

c

b

b

f c

a

g

h

f e

i

e

j

j d

i g

In problems 15 and 16, use the nearest-neighbor method to find a nearly minimal Hamilton circuit based at the vertex A. Calculate the length of the path you find. 15. A

4 2

B

16.

B 1

6

5

3

5 6

A

C

3 D

7

C

2

8 9

E

7

3

6

D

17. A pilot wants to visit the four state capitals indicated on the map at the top of page G43. The distance between each of the cities is included on the map. Using the nearest neighbor method, find the nearly minimal route for the pilot if he begins his journey in Sacramento.

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G43

G43

Chapter 15 Practice Test

Olympia

629 Helena 871

693

483 1020 Salt Lake City 650

Sacramento

18. The Mexican government would like to build a new highway system so that each of the cities indicated on the map below may be reached via the highway. The cost (in millions of U.S. dollars) is given on the map. Find the highway system that costs the least to build.

Mexico ´ Culiacan 13

17 12

Guadalajara 35

Veracruz

8 15 Acapulco

In problems 19 and 20, use Kruskal’s algorithm to find a minimal spanning tree in the graph. 19. A

4 4

B

20. 3 2

5

2

8

10 1

D

5

5

4 8

6

C 9

7

304470_ch15_web_pG1-G45

G44

11/7/06

10:06 AM

Page G44

15 Graph Theory

Answers to Practice Test ANSWER

1. The degrees of vertices A, B, C, D, E, F, and G are 4, 4, 3, 4, 1, 2, and 0, respectively. 2. The degrees of vertices A, B, C, D, and E are 5, 2, 4, 2, and 1, respectively. 3. The sequence [a, b, c, d] represents a path from A to B. 4. The sequence [g, a, e, d] represents a circuit based at B. 5. The sequence [b, c, f ] represents a path from B to E. 6. The sequence [g, d, b, c, f ] does not represent a path (and so cannot represent a circuit either), since edges b and d do not share the endpoint D. 7. Since vertices A and C have odd degree, while all the rest have even degree, there is an Euler path in the graph beginning at A and ending at C (or vice versa). 8. Each vertex in the graph has even degree. According to the traversability rules, there is an Euler circuit based at any vertex. For example, the sequence [a, b, c, d, e, f ] represents an Euler circuit based at A. 9. A, D, E, and F have odd degree, therefore no Euler path or circuit exists. 10. Vertices A and D have odd degree, while all other vertices have even degree. This implies that there is an Euler path beginning at A and ending at D (or vice versa). 11. By representing the streets that the mail carrier must cover by edges and each intersection as a vertex, we see that there are more than two vertices with odd degree. Thus, it is impossible to find an Euler path or circuit; the mail carrier will have to retrace his steps at some point. 12. By representing each of the roads by an edge and each intersection as a vertex, we see that there are two vertices with odd degree. Thus, there is an Euler path in the graph; the pothole inspector will not have to retrace her steps. 13. Edges c and e are bridges. 14. Edges e and g are bridges. 15. By visiting the vertices in the order A-C-B-D-A, one obtains a Hamilton circuit of length 2  3  6  5  16. 16. By visiting the vertices in the order A-B-E-C-DA, one obtains a Hamilton circuit of length 1  3  3  7  9  23.

IF YOU MISSED

REVIEW

Question

Section

Example(s)

Page(s)

1

15.1

1

G3

2

15.1

1

G3

3

15.1

2

G4

4

15.1

2

G4

5

15.1

2

G4

6

15.1

2

G4

7

15.2

3

G10

8

15.2

3, 7

G10, G13–G15

9

15.2

3

G10

10

15.2

3

G10

11

15.2

2, 3, 4

G9, G10, G10–G11

12

15.2

2, 3, 4

G9, G10, G10–G11

13 14 15

15.2 15.2 15.3

5 5 6

G11–G12 G11–G12 G25

16

15.3

6

G25

304470_ch15_web_pG1-G45

11/7/06

10:06 AM

Page G45

G45

Answers to Practice Test

IF YOU MISSED

ANSWER

REVIEW

Question

Section

Example(s)

Page(s)

17. Applying the nearest-neighbor method, the pilot travels from Sacramento to Salt Lake City, then to Helena, next to Olympia, and then returns to Sacramento. Total mileage: 650  483  629  693  2455 18. Applying Kruskal’s algorithm, the spanning tree will be composed of each of the three highways, extending from Guadalajara. Total cost: 8  12  13  $33 million

17

15.3

7

G26–G27

18

15.4

4, 5

G33–G35

19.

19

15.4

4

G33

20

15.4

4

G33

4

A

B

4

5

2

8

D

C

5

20. 3

5 2

10 1

4 8

6

9

7