0% found this document useful (0 votes)
24 views43 pages

Reading As 7

Uploaded by

boatsansuk7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
24 views43 pages

Reading As 7

Uploaded by

boatsansuk7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 43
er fe Tae DR et et) US) RR Oo LE) DUC Re LED ESPON Ly as n this chapter, when we refer to “graphs,” we are no longer using the word as it applies to graphs of equ tions, say, in the Cartesian coordinate system. Rather, we are talking about a finite set of points that are con- nected by a line segments (or possibly curved seg- ments, if line segments are impractical for whatever reason). Graphs, in this sense, can be used to represent real-life situations, with much of the “clutter” of extra~ neous information removed For instance, if we were to consider a salesperson trav- eling through a series of towns, we could obviously acquire a map of the region and examine his path on that document. We could, however, strip away the extraneous information, represent each of the towns by a point, and connect the points with line segments intended to depict his travel path (not necessarily to scale) from one town to another. As welll see, this al- lows us to investigate the problem of minimizing travel distances, which would be of interest if we wanted to minimize our travel time or cost. | | j | Graph Theory 503 N\A reser Eero Pal eaetoriard terete vases hl coat) tecclor roar certi cL able to: @ Identify graphs, and the terminology u them. ® Understand the concepts of paths and circuits. CMG oped eer ete Crscerrcaittt ® Work with Hamilton paths and Hamilton circuit: © Construct and use the specialized form of a graph: tree 14.1] Es Preliminaries of Graphs ‘A graph, in the sense we will consider here, is a finite set of points connected by line segments or arcs. The points are referred to as the vertices or nodes of the graph (each individual point i called a vertex), and the line segments or orcs are referred to as edges. Should an edge connect a vertex to itself, that edge is called a loop, and two vertices connected by an edge are said to be adjacent vertices within the graph. Ifa pair of vertices are connected by two distinct edges, then those edges are said to be parallel. The number of vertices in a particular graph is referred to as the order of the graph, and the number of edges in a graph is referred to as the graphis size. ‘There are many technical terms with which we can continue to specify indi- vidual features of graphs and thereby categorize them. For instance, a graph is a complete graph on a set of vertices if every pair of vertices are adjacent to one an- other. A graph that is not complete is referred to as an incomplete graph. A graph iscalled.a simple graph ifit has no loops or parallel edges. The list goes on and on. ‘Weill use capital letters like A, B, C, and so on to name the vertices of a ‘graph and the two vertices connected by an edge to name the edges. ‘That is, if ‘you have the pair of vertices named A and B, then the edge connecting them would be AB or BA (unless otherwise specified, direction is immaterial in a graph, so AB and BA are considered equivalent). For loops, since the edge con- nects the vertex to itself, the naming convention would be AA, BB, and so on. Should two edges cross one another, the intersection is not considered a new vertex of the graph, If'we can represent a graph on a piece of paper in such a way that the edges only intersect at vertices, then the graph is called planar. When you view an integrated circuit, you will notice that the components of the chip are set up in such a manner that none of the connections cross one another, and therefore (in a sense) the chip can be viewed as a planar graph. 504 Chapter 14 c z g De F 8 3 Figure 142 Graph depicting the Konigsberg bridge problem ‘The utility of graphs lies in their simplicity. That is, through the use of a graph, we can remove all extraneous or potentially distracting information from our problem setup and visualize only the important aspects of the problem. Let’ illustrate this with an introduction to a classic problem involving graphs, the Konigsberg bridge problem. Konigsberg was the capital city of what was ‘once East Prussia (the territory of which was divided between Poland and the Soviet Union following World War I1), and in that city (now Kaliningrad, Rus- sia), the Pregel River was spanned by a series of bridges that connected several islands (Figure 14.1). Ze ie Pregel River A i Nl Bridges—_/ tinaaeg 4 Figure 14.1 The Konigsberg bridge problem ‘The problem was to determine if anyone could traverse all seven ofthe bridges “without crossing any ofthe bridges twice. The great Swiss mathematician Leonhard Euler simplified the problem to one involving a graph, as shown in Figure 14.2. ‘Welll revisit this problem shortly once we have a bit more information about graphs. For now, let’ think ofa more contemporary example and then continue with our introduction to the terminology welll need. EXAMPLE 14.1 Consider a communications network, such as a collection of computers used to communicate via email. The computers in the collection are considered the vertices of this graph (though they might be more appropriately thought of as “nodes” in this context), and the wiring connecting the computers is considered the edges in the graph. ‘The number of edges emanating from or connecting to a vertex is referred to as the degree of the vertex. This number could, if the vertex were isolated, be 0. Since a loop both emanates from and connects to a vertex, a loop counts as two edges connected to its vertex. Based on this definition of degree, we can classify vertices as being even or odd, depending on their degree. A graph is said to be a regular graph (or a k-regular graph) if every vertex has the same degree, k. Finally, a graph is said to be a trivial graph if it has only one vertex and otherwise is said to be nontrivial graph. Graph Theory 505 EXAMPLE 14.2 Identify the degree of each vertex in the graph shown in Figure 14.3 and classify the vertices as even or odd. Also identify the order of the graph. We will con- sider the vertices in alphabetical order and address the questions of degree and = _ even/odd first. In closing, we will identify the order of the graph. To keep things organized, we will express our answer in tabular form. 8 c Figure 14.3 Graph for - = Ee Example 142 B 4 ‘Even ic 3 ad D 2 Even z E 3 Odd E 2 Even 3 G 2 Even 3 “There are a total of seven vertices, and therefore the order of the graph is 7. “s a] : “Adjacency Matrices % wt Because c4 ance were to designate Graph tor the a vertices of a graph as vi, vy» Y then we could construct an rn adjacency adjacency matrix, where the i, j entry of the matrix is 1 if there exists an edge matrix connecting ¥; to v, and 0 otherwise. Consider the graph shown in Figure 14.4. For this graph, the adjacency matrix would be HH coo Observe that an adjacency matrix for a graph that is not a directed graph must, by necessity, be a symmetric matrix. The reason this must be the case is that if vertex v; is connected by an edge to vertex v, then it must also be the case that vertex v, is connected by an edge to vertex v,- Here, as an illustration, what does the 1 in the (2, 2) position mean? The graph contains an edge connecting vertex v, to v3. What does the 1 in the (1, 4) position mean? The graph contains an edge connecting vertex v, to v,. For every entry of 1 in the matrix, identify its i, j position in the matrix and observe that ‘an edge connects vertices v, and ¥, EXAMPLE 14.3 For the graph shown in Figure 14.5, produce the adjacency matrix. By in- spection, we can find the adjacent vertices and insert 1s in those entries of Figure 14.5 Graph for Example 14.3 3 camara 204 _ Figure 14.6 Graph depicting path C, B,D. E,A A 8 ¢ Qj o & cee tars Figure 14.7 Adigraph the matrix whose row and column correspond to the adjacent vertices. In all other entries, we place a 0. Thus, in this situation, we obtain the matrix 01000 10010 O00 tt Geieto 7 oo110 Paths Ina graph, a walk is a sequence of vertices connected by edges. There are special types of walks, called trails and paths, that are characterized by the edges they tra- verse and the vertices they visit. A trail isa walk in which no edges are repeated, and a path is a trail that has no repeated vertices. Thus, a path isa special type of walk wherein no edges are repeated and no vertices are revisited. A circuit, or cycle, is a ‘walk that starts and ends at the same vertex but that is not a loop. The number of ‘edges traversed by walk, trail, or path is called the length of the walk, trail, or path. ‘The term “path” is, in application, sometimes made a bit more relaxed, and revisiting of vertices is permitted. Thus, a distinction is drawn between a path and a simple path, with the term “path” permitting revisitation of vertices. In this chapter, we will not require that paths be simple, and therefore the words “path” and “walk” are synonymous, and when we intend to refer to a simple path, we will specifically use that terminology. ‘There are several accepted conventions for the naming of paths, but we will adopt the practice of listing the vertices of the path in order of traversal as the pathis name. For instance, if we have a graph with numerous vertices, among which are the vertices A, B, C, D, and E, we could specify the path C, B,D, E, A, which describes motion beginning at C, moving to B, then to D, then to E, and ending at A (assuming that the graph contains edges CB, BD, DE, and EA) (igure 14.6). Any path that ends at the same vertex as it began is referred to asa circuit, and a one-edge loop path is referred to as a pendant, We point out that the name “circuit” may be bit misleading and specify that a circuit (or any path, for that matter) need not include every vertex in the graph. ‘Although we shall not explore them here, a graph is said to be a directed graph if the edges all have an indicated direction on each edge. Such graphs are some- times called digraphs, and the direction of each edge is indicated by an arrowhead drawn on the edge (Figure 14.7). For digraphs, changing the order of vertices when naming an edge i significant, since AB would no longer be viewed as the same as BA. A graph that is not directed is sometimes called an undirected graph. ‘The distance between vertices in a graph is defined to be the number of vertices in the shortest path that connects the vertices. Should there be no paths connecting the pair of vertices in question, then we ay the distance between the verticesis infinite. ‘A graph in which every pair of vertices can be connected by a path is called a connected graph, and a graph that is not connected is called a disconnected graph. Ifremoval ofa particular edge changes a connected graph into a discon- nected graph, then that edge is referred to as a bridge. Graph Theory 507 EXAMPLE 14.4 : EX Ys Figure 14.8 Graph for Example 14.4 ‘Sketch a complete three-regular graph of order 4. SOLUTION ‘The problem calls for a graph having four vertices (order 4), each of which has three edges entering it and every vertex connected to every other vertex. Although the graph in Figure 148 is not the only possibility it has the desired properties. zap Insuch acase, the numerical values are said to be the weights fence edge, the graph is called a weighted graph. Weights appear frequently in applications of graph theory. In the so-called friendship graph, the edges would represent connections or friendships be- tween individuals and the weights the strength of those friendship (measured ‘on some appropriate scale). In a communications network graph, the weights could indicate the cost of maintenance or construction of the communications links between individuals or locations within the network. ‘We can investigate a weighted graph and a pair of connected vertices within the graph, and we can search for the minimum (or maximum) sum of weights of the edges forming a path between the vertices. If we calculate the sum of weights for any particular such path, that sum is defined to be the length of the path, and the ‘minimum length of all such paths is defined to be the weighted distance between vertices. This definition coincides with the definition of the distance between vertices inn unweighted graph if we make the assumption that the weights ofall edges are 1. ‘The shortest-path problem lies behind a very familiar Web application you may have used yourself, an online map generator that provides you with the “shortest travel distance between locations” Sound familiar? It can also be used to solve problems like network routing, where the goal is to find the shortest path for data packets to take through a switching network. It is also used in more general search algorithms for a variety of problems ranging from auto- mated circuit layout to speech recognition. “The technique we will use here is called Dijkstra’ algorithm, after the Dutch computer scientist Edsger Dijkstra, and is often used to solve routing problems. In fac, the algorithm is generally used to determine the shortest distance from a particular vertex to all other vertices in the graph, but in this case, we are inter- ested in the shortest distance to a particular vertex, so will use a truncated version of the algorithm, We could repeat the process for any particular vertex we wished, During the algorithm, we will designate any vertex whose minimum dis- tance from the starting vertex is known as “solved.” All other vertices shall be referred to as “unsolved.” Until we know the shortest distance from the starting vertex to a particular vertex with certainty, the distance to that vertex will be referred to as a candidate distance. Let’ suppose we are interested in finding the shortest distance from vertex Sto vertex T in Figure 14.9. We begin by identifying all unsolved vertices con- nected to S, and these are seen to be A, B, and C. The candidate distances from vertex S to these other vertices are 2, 5, and 4, The smallest of these candidates 508 Chapter 14 is retained, and the vertex connected to $ by that distance is now considered known, and its candidate distance is its minimum distance from S. 12 Figure 14.9 Graph for a shortest distance problem 4 can wai ‘We can keep track of the minimum distances by use ofa table in which we place the minimum distance from S once itis known: 0 2 a}a|m|ololalelo ‘Vertices S and A are now considered solved. Next, we consider all unsolved vertices connected by a path to a known vertex and determine their distances from S. The connected unsolved vertices here are F, D, B, and C, and we compute the candidate distances from $ to these vertices. The distances are S, A, F = 14, S,A,D = 9,8, A,B = 4,8, B = 5, and S,C = 4. ‘We have a tie for the shortest distance from S, and therefore we make an ar- bitrary choice of which one to keep. Here, we'll choose to keep S, A, B, and thus the distance from $ to B is known to have minimal distance 4: Ss 0 A 2 B 4 c D E F T Again, we consider the distance from $ to all unsolved vertices connected by a vertex to a solved vertex. The unsolved vertices in question are P, D, E, and C. We compile the candidate distances from $ to those vertices and again choose the shortest distance: SA, F=14,8,4,D= , S, A, B, D = 8, S, A, B,E= 7,8, C= 4 Graph Theory 509 We keep the shortest distance from the list, and thus the shortest distance from S to any unsolved vertex is 4, and the shortest distance from $ to Cis known: alalele apa|e|olola|>|o “The process continues until we know the shortest distance to T. The set of unsolved vertices connected by a path to a solved vertex are D, E,and F, and we now find the candidate distances to those vertices from S. These distances are 5,4, P= 14,8,A,D =9,5,A,B,D=8,5,A,B,E= 75, E=8 ‘The shortest of these distances is 7, and thus the distance from $ to vertex E is known to be 7: s 0 A 2 B 4 c 4 a iz E 7 | Ey 8 ‘The unsolved vertices now connected to a solved vertex are D, F, and T. We find the candidate distances from S to each of these vertices: S.A, F= 14,8,4,D = 9,5, A,B, D = 8, S, A, B, E,D = 8,5, A,B, E, T= 14 ‘The smallest of these is 8, connecting S to D. We keep one of those paths, and the distance from $ to D is now known to be sje|alalolo H)a|alolofale|o ‘Teopatonitee Both unknown vertices are connected by an edge to a known vertex, so we list all candidate distances from S to F and to T. They are SA, F=14,5,4,D, T= 14, 8, A, B, B,D, T= 13 We keep the smallest distance, which is 13, and thus we know that the shortest distance from $ to T is 13. Since this is the distance we were seeking, we can terminate the process. Observe that the shortest distance to F was never com- pletely resolved, but we could determine it if we continued the process through one more iteration: s 0 A 2 B 4 c 4 D 3 : E 7 t F 3 T 3B is EXAMPLE 14.5 ‘The given weighted graph depicts a switching network and the delay times (in nanoseconds) for data packets of a particular size to pass through the various paths of the network (Figure 14.10). Find the shortest path for a packet of data between points A and B in the network. Figure 14.10 Weighted graph of a switching network ‘ocean SOLUTION As before, we construct a table showing the shortest time from vertex A to any other vertex in the network: efalmlola]> ‘There are three unsolved vertices connected to vertex A, and of those three, the minimum distance is from vertex A to vertex E, and hence the distance from A to E is known to be 7, which we enter into the chart: A o c i ; ; : | f B Is ‘The unsolved vertices connected by an edge to a solved vertex are now C, D, and B. We compute the candidate distances from A to each of these vertices: AC=14 AD AE,D=8 A,E,B=22 ‘The shortest of these distances is 8, and thus vertex D is solved, with distance 8 from vertex A: | elm |e olo Scapa ‘The unsolved vertices connected to solved vertices are C and B, and we compute the candidate distances as AC=14 A,E,D,C=10 A,E,B=22 A,E,D,B=20. ‘The smallest of these distances is 10, and hence the distance from A to Cis now solved: 10 lo 512 Chapter 14_ Exercises 5 E a i F a 3 : Both of the remaining unsolved vertices arc connected by an edge to a solved vertex, so we can find distances from A to each of these vertices: AED,CF=14 A,E,D,B=20 A,E,B=22 ‘The smallest of these distances is 14, and hence the vertex F is now solved, and its distance from A is 14: A oO c 10 D 8 3 E : E 14 i B 3 We have been forced to run through all other vertex distances in this example and now can finally find the distance from A to B: AE,B= 22 A,E,D,B=20 A,E,D,C,R,B=17 ‘The minimum of these distances is 17, and thus the minimum distance from A to Bis 17, and we conclude that the shortest routing path for the data is A, E, D, C.B,B, which (oddly!) runs through all intermediate data transfer points: 0 10 8 7 14 7 w)almlolol> ‘Straten ae Answer the following questions using proper grammar, complete sentences, and correct terminalogy. 1. Define what is meant by a mathematical graph, including the distinction between the edges and vertices of the graph. Graph Theory 513 2. What does it mean to say that a graph is connected? 3. Inan unweighted graph, what is meant by the notion of distance between vertices? 4, Explain Dijkstra’s algorithm. What is the distinction between a path and a circuit? 6. What isa bridge in a graph? Draw an example ofa graph having a bridge, identify the bridge, and then explain why that edge is a bridge. For the following graphs, identify the degree of the vertices of the graph, classify the graph as either even or odd, and give the order of the graph. ZA Le > ° b ° 1) ® o “8 3 > b ° m i In the following problems, graphs from previous problems are referenced. Produce the adjacency matrix for each of the geaphs. 15. Problem 7 16. Problem 8 17. Problem 9 18, |. Problem 10 19. 20, 21. Problem 11 Problem 12 Problem 13 Problem 14 In the following problems, a graph is described. Sketch an example of a graph having the indicated properties. 23, 24, 25. 26. ‘The graph has five vertices. “The graph has five vertices, three of which are even. ‘The graph has seven vertices with two bridges. ‘The graph has four odd vertices. 514 Chapter 14 ; 3 Figure 14.11 ° é The following problems refer to the graph shown in Figure 14.11. 27. Is A,B, C, Da path within the graph? 28. Which edges of the graph are not included in the path A, B, C, E? 29, Within the graph, can we find a path that includes all the edges without using any edge twice? If so, find the path. In the following problems, sketch a graph with the indicated properties. 30. Sketch a complete seven-regular graph of order 8. 31. Sketch a complete four-regular graph of order 5. 32. Sketch a complete five-regular graph of order 6. 33. Sketch a complete six-regular graph of order 7, For the following graphs, determine if the graphs are connected or disconnected. 34. A 8 c D 35. B c o% z i E F Cee Graph Theory 515 39. h c To do so, welll summon the name of one of the true giants of mathematical history, Leonhard Euler, and introduce the concepts of the Euler path and the Euler circuit. Euler Paths and Circuits "An Buler path is path along a connected graph that connects all the graph’ Since a circuit is a path that begins and ends at the same vertex, it follows that an Euler circuit is a circuit that passes through each edge of a graph exactly once. These two concepts are closely related and differ in that an Buler circuit must start and fin- ish at the same vertex. The definition indicates, we should mention, that every Euler circuit must be an Euler path, but the converse is not true. Our first challenge will be to determine if a given graph contains an Euler path, an Euler circuit, or neither. This can be determined by brute-force experi- ‘mentation, although other, more elegant methods for resolving the question do exist, as we'll see, Let’ begin with an example. EXAMPLE 14.6 Figure 14.12 Graph for Example 14.6 Does the graph shown in Figure 14.12 contain an Euler path? If so, find the Euler path. SOLUTION Without a theoretical tool (yet!) to help us, what we need to dois to rely on some trial and error to see if we can determine the answer. Beginning with vertex A, ‘we proceed to vertex B (arbitrarily chosen). In order for us to construct an Euler path (if possible), we must reach every vertex and traverse no edge more than once, Thus, our only choice is to advance to vertex C and from there advance to vertex A. Since we must continue to blaze new trails across new edges, our choices now are somewhat limited: we can follow either AE or AD. Randomly choosing to follow AD, we proceed to vertex D, then E, and our Euler path is complete. (Note that in this example, we could have proceeded back along EA to complete an Euler circuit, but this was not asked of us.) ‘The method for solution in Example 14.6 was what we refer to asa proof by demonstration. That is, we established that the graph contained an Euler path by finding the path and then exhibiting it for all to see. Sometimes, this can be quite challenging, and it is better (well, easier!) to prove the existence of the item we're looking for by using theoretical results. 516 EXAMPLE 14.7 Figure 14.13 Graph for Example 147 Figure 14.14 Graph of Example 14.6 cB Figure 14.15. Graph of Example 147 Does the graph shown in Figure 14.13 contain an Euler path? What about an Euler circuit? Ifso, find them. SOLUTION Again, we choose an arbitrary vertex at which to start, and (to avoid monotony) welll select vertex C. Beginning at C, we traverse the path C, D, E, B, A. This has allowed us to visit all the vertices of the graph but does not qualify as an Euler path, since edge CB was never traversed. Observe that this does not tell us that no Euler path exists. Hardly so! Allit demonstrates is that the particular path we found, which did reach all the ver- tices, was not an Euler path. Beginning at vertex B, we traverse the path B, C, D, E, B, A, and this is an- other path that reached all the vertices, and it had the property of traversing all of the edges in the graph. Therefore, this path was an Euler path! Thus, we have proved, by demonstration, the existence of an Euler path. ‘There can be no Euler circuit, however, because of the structure of the graph. Observe that vertex A sits at the end of a “dead-end road” in the graph. The only access to vertex A is via edge BA, and since this can be traversed only once, there is no way to begin and return to vertex A or any way to manage to reach vertex B, then A, and then another vertex without recrossing edge BA. ‘What is it about these graphs that allows the existence of an Euler path? The answer lies in a result called Buler’s theorem, which tells us that the number of odd vertices within a graph controls whether an Euler path or an Euler circuit will occur. Eul The i Suppose we have a connected graph. Then a. A graph with no odd vertices has at least one Euler path, which will also be an Euler circuit. The circuit can be initiated at any vertex you wish and will terminate at that same vertex. b. A graph with exactly two odd vertices has at least one Euler path but no Euler circuits. The Euler path must begin at an odd vertex, and it will end at the other odd vertex. . A graph with more than two odd vertices has neither an Euler path nor an Euler circuit. Let’s reexamine Example 14.6, with the weapon of Euler’s theorem now cast and in our hands. Observe that every vertex is even, with degrees of either 4 (for vertex A) or 2 (the rest of the vertices) (Figure 14.14). By Euler’s theorem, there is at least one Euler path, which will also be an Euler circuit. Recall that ‘we constructed an Euler path and remarked that (had we proceeded one vertex further) we would have had an Euler circuit as well. ‘What about Example 14.7? Vertex B has degree 3, so its an odd vertex, and vertex A has degree 1, so its odd (Figure 14.15). The remaining vertices are even, 80 we are in the situation of having exactly two odd vertices. The second state- ‘ment within Euler's theorem tells us that there is at least one Euler path but no Graph Theory 517 Euler circuit, which is what we found. Moreover, the Euler paths we could find would have to begin at one odd vertex and end at the other. Recall, we initially attempted to begin our path at vertex C, which wasan even vertex, and we failed to construct an Buler path. When we began at vertex B, one of the odd vertices, wwe were able to construct an Euler path, which ended at the other odd vertex, A. EXAMPLE 14.8 Figure 14.16 Graph for Example 148 Using the result of Euler's theorem, construct a connected graph that has no Euler paths or circuits. SOLUTION ‘The third criterion from Euler’s theorem tells us that we must construct a graph with more than two odd vertices. So, we will devise a graph with three odd vertices (if we can manage it), andl that will serve as our example. Consider the graph shown in Figure 14.16. Each of the vertices has degree 3, and therefore no Buler path should exist. Let’ see (for purposes of investigation) what might happen if we attempt to con- struct an Buler path. Starting at vertex A, we can follow A, C, B, A, D, C,..., but at this point there is no way to cross edge BD, and we are stuck at vertex C. A similar experience awaits no matter which series of edges we cross in an attempt, to visit all vertices while crossing all edges a single time. EXAMPLE 14.9 Ali needs to use an electronic scanner device to read the electricity meters on all the houses in a particular neighborhood. In an effort to minimize his driving time and gas expenses, he wants to read the meters in all the houses, passing down each street only one time. A map depicting the neighborhood is shown in Figure 14.17. Is it possible for Ali to accomplish his goal? a 5 tuners. © 2 i Figure 14.17 Graph for i Example 14.9 3 SOLUTION For Ali to achieve his objective, he must traverse all the streets in the neighbor- hood, passing through each a single time, Over a cup of coffee, he labels all the intersections in the neighborhoods as vertices A through I and considers the situation, Familiar with Euler's theorem, he decides to count the number of odd vertices in the graph and finds that vertices F, I, E, and H are odd vertices. Since there are more than two odd vertices, Ali realizes (with a bit of frustration!) that his task is a hopeless one, and he is certain to have to pass down at least one street a second time. 518 Chapter 14 EXAMPLE 14.10 For the graph shown in Figure 14.18, does an Euler path or an Euler circuit exist? IFso, give an example of such a path and/or circuit. Figure 14.18 Graph for 4 Example 14.10 by SOLUTION Examination of the graph reveals that, surprisingly, all the vertices are even. ‘Therefore, the first statement in Euler’ theorem tells us there is at least one Euler path, which will also be an Euler circuit. All we have to do now is produce one. Beginning at vertex A, we will attempt to construct an Euler path, knowing that (if we are successful) we will return to vertex A to close the circuit. One path is A,B,E,F,K, J, H, D, E,l, H, B,C, M, LH, GA ‘There are many others, but this one suffices, Secel e It would be sitar hat to have an alge rithm to which we could appeal for the construction of Euler paths or circuits so that our construction process would be systematic rather than ad hoc. Fleury’s algorithm, a rather famous result from the 1860s, has the curious property of having an uncertain attribution. That is, though certain writings of the French mathematician Edouard Lucas refer to Fleury, nowhere is there mention of Fleury’s full name. Because of the precision inherent in all math- ematics, this is a truly unusual occurrence, but limitations on time prevent us from discussing the anonymity of the devisor of the algorithm we now present. Fleury’ algorithm tells us that to construct an Euler path or circuit, begin at any vertex you wish. From that vertex, pick an edge to traverse, darkening it or marking it in some manner so as to ensure that you will not recross it. Never cross a bridge unless no other choice exists! Traverse that edge to reach the next vertex. Repeat steps 2 and 3 until all edges have been traversed, returning to the original vertex if possible (to create an Euler circuit) Graph Theory 519 EXAMPLE 14.11 ‘The graph in Figure 14.19 has two odd vertices: A and C. Euler's theorem tells us there is an Euler path but not an Euler circuit and that the Euler path must begin at one odd vertex and end at the other. Construct an Euler path for the graph. c 8 e dD je i Figure 14.19 Graph for i Example 14.11 : e SOLUTION ‘We must begin our path at either A or C, so we will use alphabetical preference and begin at vertex A. Our path can be A, B, D, B, F, D, E, C, D, A, C, which crosses each of the edges a single time. Observe that, as predicted by Euler's theorem, we ended at vertex C, the other odd vertex. EXAMPLE 14.12 For the graph shown in Figure 14.20, if an Euler path or circuit exists, find examples of them. Figure 14.20 Graph for Example 14.12 cogent SOLUTION All the vertices in the figure are even, and therefore Euler’s theorem tells us there is an Euler path that is also an Euler circuit. We arbitrarily choose to begin at vertex A and attempt to cross all edges of the graph, returning to A. A, B, D, C.B.EF,G.EH,G,K.L,1,K, 1, KL, 1,D,A serves as the Euler path/cycle in this case. EXAMPLE 14.13 In a small office, the relationships as confidante’ among the workers is dis- played in Figure 14.21. Adjacent workers (vertices) know one another and talk regularly. If Thuy tells a secret to Marc, is it possible for the secret to be relayed across all the lines of communication, with no one “repeating the gossip” to someone whom they have already told or who has told the secret to them? SOLUTION In order for the message to be relayed across ll lines of communication, itis neces- sary for the secret to be transmitted along all the edges of the graph and to every vertex, and thus the question amounts to whether there exists an Euler path within 520 Chapter 14 c 9 Figure 14.23 Graph for the map of five countries Figure 14.21 Relationship ‘Among Workers the communication network, starting with Thuy. We notice there are two odd ver- tices, Thuy and Moira, and therefore Eulers theorem guarantees the existence ofan Euler path, and since itis beginning with Thuy, it must end with Moira. ‘The only person Thuy knows in the network is Marc, so he is told first. Marc has a choice of three individuals to whom he can tell the secret, and he arbitrarily chooses to tell Debbie, who passes the story on to Aidan, who tells it to Moira. The path is not complete because Bonnie has not yet been told Thuy’s secret, and all the lines of communication have not been used. Moira tells the secret to Bonnie, who passes it on to Marc, who then repeats it for the final time, to Moira, and the Euler path is complete. ‘Map Coloring — ‘lem: given any map, what is the minimum number of colors required so that no two countries sharing a common border have the same color? The problems solution, which is entirely nontrivial, is four, established using a computer to perform proof by contradiction during the mid-1970s. Given a connected set of countries on a map, we can attempt to resolve the question for a particular case by using edges to depict the geographical adja- cency of neighboring countries, with the countries depicted as vertices. Such a graph is, by the way, referred to as a dual graph for the map. Figure 14.22 Map of five countries ‘The map shown in Figure 14.22 depicts five countries subdividing a large landmass, The dual graph for the map is shown in Figure 14.23. What is the minimal number of colors needed in order to ensure that no two neighboring countries are filled with the same color on the map? Let's start our investigation with vertex A. Since A is adjacent to both B and Cand those two vertices are, themselves, adjacent, the map requires at least three colors, possibly antique white, blue, and carmine, Are any more colors needed? From the graph, we see F is adjacent to both B and D but not to A or GC, and therefore we can color E the same as A, and therefore we still have used only three colors. Isa fourth color needed for D? Vertex D is adjacent only to E, B, and C, and therefore it cannot be antique white, blue, or carmine, and thus a fourth color is needed to fil in D. You may be wondering if there is a method for determining the exact num- ber of colors required for a particular map, and the answer to that question is no. It is known that a maximum of four colors will be required, but there is no algorithm for determining how many colors a given map will need. EXAMPLE 14.14 ‘oct Figure 14.24 Graph for Example 14.14 Draw a map for which the graph shown in Figure 14.24 would be a dual graph. SOLUTION Many solutions are possible because of the creativity of the person drawing the map. Figure 14.25 shows one example that would suffice. Alll we need to do is to construct a map in such a way that our countries touch only those with whom the graph demonstrates they share a border. In this case, we appear to have a rather wild graph, suggesting the existence of a body of water between countries C and Fand also between D and B, C, and E. (2 Ne) Figure 14.25 Possible Map EXAMPLE 14.15 ‘What is the solution to the Konigsberg bridge problem? That is, is it possible to ‘cross all seven of the bridges spanning the Pregel River without traversing any individual bridge more than once? SOLUTION In the depiction of the Konigsberg bridge problem in Figures 14.26a and 14.26b, ‘we see that the degrees of the vertices are 5 for vertex A, 3 for vertex B, 3 for vertex C, and 3 for vertex D. Thus, each of the four vertices is odd. According to Euler’ theorem, a graph with more than two odd vertices can have no Euler path, which in this case is the route sought to cross all the bridges a single time. ‘Thus, the walk described in the problem is not possible. 522 Chapter 14 = we as Preyel River G er tS Bridges—_/ \ Figure 14.26b Graph for the Konigsberg Bridge Problem Figure 14.26a The Konigsberg Bridge Problem Exercises Answer the following questions using proper grammar, complete sentences, and correct terminology. 1. What is an Euler path? 2. How does an Buler circuit differ from an Euler path? 3, What is Fleury’s algorithm, and for what is it used? 4, How can weuse the number and type of vertices to establish the existence or nonexistence of an Euler circuit? For the following exercises, use the graph shown in Figure 14.27. A a 5 compton Figuei427_—~OSOS™ DE 5. Find an Euler path, if one exists, that begins at vertex A. 6. Find an Euler path, ifone exists, that begins at vertex D. 7. Find an Euler path, if one exists, that begins at vertex B. 8. Doesan Buler circuit exist for this graph? For the following exercises, use the graph shown in Figure 14.28. Figure 14.28 DE Graph Theory 523 9. Find an Buler path, if one exists, that begins at vertex A. 10. Find an Euler path, if one exists, that begins at vertex C. 11. Find an Euler path, if one exists, that begins at vertex B. 12. Does an Euler circuit exist for this graph? For the following exercises, use the graph shown in Figure 14.29. 13. Find an Euler path, if one exists, that begins at vertex A. 14, Find an Euler path, if one exists, that begins at vertex C. 15, Find an Euler path, if one exists, that begins at vertex B. 16. Does an Euler circuit exist for this graph? 17. Suppose we had a graph with 1000 vertices, all of which are even (Figure 14.30). (a) Does an Euler path exist for the graph? Explain, Figure 14.29 (b) Does an Euler circuit exist for the graph? Explain. A 8 West ofthe Mississippi Figure 14.30 The Western United States 18, Represent the shown map as a graph, using a vertex to represent each state, with states sharing a common border joined by an edge. 19. Does the graph described in Problem 18 possess an Euler path? Explain, and if the answer is yes, produce such a path. 20. Does the graph described in Problem 18 possess an Euler circuit? Explain, and if the answer is yes, produce such a circuit. Frithe follogrizig graphs, wes Floury'walgorithm to finillan Hularpath and an Hulse enccait (if one exists). 21. 2. a o x 524 Chapter 14 wa 4 Bc a D = FE i l : 6 —i; Hn 13 ‘A Hamiltonian path is a path in an undirected graph that visits each vertex exactly once. A Hamiltonian circuit is a Hamiltonian path that begins and endsat the same vertex, and graphs possessing such a cycle are referred to as, Hamiltonian graphs or sometimes as traceable. At present, there is no known efficient method for determining whether or not a given graph is Hamiltonian. ur first effort in the analysis of Hamiltonian graphs will be to discuss particular properties that such a graph must possess, and our second will be to produce some special graphs that are known to be Hamiltonian. In the latter case, we will see that the demonstration of “Hamiltonianicity” relies on the general concept that a graph having “enough” edges must be Hamiltonian (although, granted, the term “enough” is weak and imprecise). gaa is, every pair of vertices in the graph must be capable cing connected by a path within the graph. This virtually goes without say- cy m n Clopeimaga e Figure 14,31 Graph with vertex of degree 1 ing, since the condition of being Hamiltonian requires that a path exists by which all the vertices can be visited exactly one time. ‘A second condition is that every vertex must have degree two or more. This may also be apparent from the definition of being Hamiltonian, since there must be path that visits all the vertices at least one time. However, let's do an example where a particular graph (Figure 14.31) has a vertex of degree 1 and understand what the ‘consequences would be of a vertex of degree 1 being present within the graph. Clearly, vertex A is of degree 1, with only edge AD connecting that vertex to the rest of the graph, If we attempt to begin our path at A, the only choice for our first stop in the circuit is vertex D. We are then free to choose any of three other vertices to which to travel from D to proceed with the circuit. However, to close the circuit by returning to vertex A, we must again pass through D, which is forbidden in a Hamiltonian graph. By similar reasoning, starting at any vertex other than A, we ‘must eventually visit vertex A, meaning that the circuit must contain the sequence of vertices D, A, D, again violating the definition of being a Hamiltonian graph. Graph Theory 525 A third condition that must exist within a Hamiltonian graph arises if we introduce the concept of bipartite graphs. A graph is called bipartite if the ver- tices of the graph can be divided into two sets where every edge within the graph goes between the sets and there is no edge within either of the sets. Ifa graph is bipartite and Hamiltonian, then the two sets into which the grap can be split as mentioned in the definition must have the same number of ver‘ices. ‘The rationale for this will be left for you to discuss in the exercises, but itis not a terrifically deep result. ‘When particular conditions must be present in a given situation, those con- ditions are referred to as necessary conditions. On the other side of this concept lie sufficient conditions. When we say a set of conditions are sufficient for event E to happen, we mean that if the conditions are present, then E must occur. Recall, however, that we had said there was no efficient method for establishing that a graph is Hamiltonian. At this point, we should mention that, in all but relatively simple graphs (having a fairly small number of vertices), establishing the existence of these conditions is challenging. Lets present some sufficient conditions to ensure Hamiltonianicity. First, if ‘graph having more than two vertices is undirected and complete, then it must be ‘Hamiltonian. Why would this be the case? First ofall, for completeness, every ver- tex must have degree at least 2, since it must be connected to all the other vertices in the graph. Therefore, we can number the vertices in any particular order we wish and then use the cycle Yo Vi...» Vm Vo All the edges must exist because of complete- ness of the graph, and therefore this cycle establishes a Hamiltonian circuit ‘The next sufficient condition is that if you have an undirected, loop-free graph with n vertices, and if for every pair of distinct vertices A and B itis true that deg(A) + deg(B) = (n ~ 1), then the graph must have a Hamiltonian path. ‘The proof of this result is a bit more challenging, and we will suppress it in this book, leaving it to a mathematical course on graph theory for its establishment. Itis, however, valid. Note the result is really saying, in another form, that if the graph has “enough? edges (there is the recurrence of our vague term “enough”), then it must have a Hamiltonian path. The graph shown in Figure 14.32 satisfies the criteria listed above. Observe that it has quite a few edges! Let’ see if we can find a Hamiltonian path: A, B, F, C, E, D sulfices as an illustration. Note that it is not a Hamiltonian cycle, but we were asked only for a path in this case. ‘There are other sufficient conditions for a graph to be Hamiltonian, which welll ist here: + If the degree of each vertex of an undirected loop-free graph is at least 7 7 where n is the number of vertices of the graph, then the graph “ 7 E has a Hamiltonian path. || « If G is undirected and loop-free with n = 3 vertices and if deg(x) + : deg(y) = n for all vertices x and y that are not adjacent, then G has a D E 8 Hamiltonian cycle. Figure 14.32 A Graph that « If the graph is undirected and loop-free with n = 3 vertices and if MUST have a Hamilton Path deg(x) = n/2 for all vertices x, then the graph has a Hamiltonian cycle. 526 Chapter 14 Exercises problem is referred to as the traveling salesman problem because, if we were to view the weights on the graph as the miles between cities, then the circuit mentioned would correspond to a route the salesman could follow where all cities are visited and the travel distance is minimized. Obviously, this would be of great interest to anyone who worked in an industry where representatives would want to visit the client lis face-to-face. ‘As was the case with the general problem on establishing that a graph is a Ham- iltonian graph, there is no known (efficient) solution to the traveling salesman problem, nor is it known that no such efficient solution exists! This problem is an example of a much larger class of mathematical problems known as combinatorial optimization problems. One could, in theory, attempt to find all possible Hamiltonian circuits and then simply choose the one hav- ing minimal total weight, but this is impractical. In one illustration of a 16-city traveling salesman problem (the problem of Homer's Ulysses attempting to visit all the cities described in The Odyssey exactly once, there are 653,837,184,000 distinct routes). Merely listing all the possibilities required over 90 hours of computer time on a powerful workstation, and it was from the list of possibili- ties that the smallest result was chosen. Since the brute-force technique of enumeration of possibilities is clearly inadequate, there have been specific algorithms created that reduce solution time by eliminating most of the round-trips without ever having to explicitly consider and compare them, The problem finds application in computer science in the design of an idealized printed circuit board having a particular number of holes where the distances would be the amount of wire used to connect the holes. Answer the following questions using proper grammar, complete sentences, and correct, terminology. What is meant by the traveling salesman problem? 2. Whatisa Hamiltonian path, and what (ifanything) distinguishes it from an Euler path? 3. What conditions are needed to ensure that 2 graph is Hamiltonian? What does it mean to say that a graph is bipartite? Give an example of a graph that is bipartite. Shown ure a collection of graphs. Determine whether they possess a launiltonias path. If they do possess such a path, produce the path. If they do not possess such a path, explain why. c 6 4 D 5. a oI Graph Theory 527 aN v 10. A Boe 3 ™ a i i — i ‘The following graphs do possess at east one Hamiltonian path, Find any particular one ofthese paths. nA 8 fa 8 bc r i ay i i | . e . D EE FG 12 4 Hy 14, i YI ; é FE F Soh Ts Use the associated graphs to solve the following problems. 15. Suppose. regional manager headquartered in Chicago must travel by car to visit offices in Minneapolis, Cleveland, and St. Louis. Ifthe distances, between the cities are as shown in Figure 14.33, find the Hamiltonian circuit that will allow the manager to visit all the regional offices while traveling the shortest overall distance. Chicago Minneapolis Cleveland ‘@onpyetaig Figure 14.33 774 mi 528 Chapter 14 Figure 14.34 Graph of proposed videophone 16, Repeat Problem 15, using the following “greedy” algorithm. Start at Chi cago, find the nearest city to you, and travel to that first. From there, choose to visit the city closest to where you are but not Chicago. Iterate this process, making the last leg of your journey back to Chicago. Com- pare the result to that found in Problem 15. (This algorithm is referred to as the nearest-neighbor algorithm). 17. Suppose a videophone service will be established on an experimental basis among five cities. Figure 14.34 gives the links that are included in the network, with the value of each edge corresponding to the instal- lation costs in millions of dollars for that link. Each city need not be directly connected because calls can be routed through a sequence of intermediate cities. Establish a Hamiltonian path for the network that minimizes the cost of construction of the videophone service. 14 i -_Agraph that contains no circuits is referred to as an acyclic graph, “acyclic” mean- egaEaDs simple, connected graph is acyclic, then we call ita tree. trees one can form on. graph having five vertices are shown in Figure 14.35. ye : | Figure 14.36 Examples of trees Figure 14.35 Possible trees ona graph with five vertices oe x ‘Typically, one vertex of a tree is designated as the root vertex, and itis from this vertex that the tree is considered to “grow” Unlike a physical tree, however, itis common to place the root of the tree at the top of the graph, from which the edges of the tree can be followed downward (Figure 14.36). If no root is desig- nated, we refer to the tree as nonrooted, or free. Much like the trees we encounter in nature, graphical trees can have branches, and each of these can be considered subtrees. The vertices at which the branches split are referred to as parent vertices, and all those vertices lying, beyond that branch location are considered children of the parent vertex. A vertex having no children is referred to as a leaf of the tree. ‘A particular type of tree, called a binary tree, is used extensively in the organization of data (Figure 14.37). A binary tree is one where each vertex has at most two children, which are designated as the left child and the right child, based on their position relative to the parent. Should a binary tree be such that all vertices except the leaves have two children and all the leaves have a Graph Theory 529 | Figure 14.37 A full anda i he complete binary tree common depth, then the tree is called a full binary tree. Ifa tree is nearly full but the bottom level is missing some leaves, we refer to the tree as a complete binary tree. Since all trees are connected graphs (by definition), there must be a path from the root to any vertex in the tree, and since the graph is acyclic, the path is unique. The height (in some books called the depth) of a vertex in the tree is the length of the path from the root to the vertex, and the root itself is said to have height 0. The height of the tree is the maximum of all vertex depths. EXAMPLE 14.16 For the following graph, determine the height of the tree, the right child of vertex A, and the height of vertex K (Figure 14.38). Figure 14.38 Graph for Example 14.16, SOLUTION ‘The greatest height of any vertex in the tree is 4, and thus the height of the tree is 4. Vertex A has two children, C and D, but D is the right child of vertex A. Finally, vertex K has height 3. (Figure 14.39). This type of graph depicts the corporate hierarchical structure of an organization and allows members or outsiders to see where the various members of the organization stand in relation to one another. INSPECTOR GENERAL CHIEF OF STAFF Figure 14.39 Corporate organization chart econ een 4 ey Graph Theory 531 Files on a computer are also organized in a treelike structure, which you can see listed in a vertical pattern, with the roots on the left (Figure 14.40). Figure 14.40 Computer file listing Figure 14.41 Chain letter recipient list ‘The spread of a chain letter can be represented through the use of a tree, with the originator of the chain letter serving as the root (Figure 14.41). If we as- sume that each recipient forwards the chain letter to three friends, then each root ‘would have three children, and hence the nth stage of the chain would expand the number of overall individuals involved in the chain letter process to 3". ‘actu Betty Carlos Dania £4 Felicia Gorardo Heloise fola_— John Gt Leonardo. Manvel = 3 : Naney 3 532 Chapter 14 8 . could be represented using an adjacency matrix. This technique, we pointed out, would permit us to describe the graph effectively in a manner that would capture the essential information about the relationships (if any) among the vertices in a form readily used by computers. The analog to thie concept in the case of a binary tree is the array representation, which is an n X 3 array, having n rows (corresponding to the m vertices of the tree) and three columns (indicat- ing the vertex and the left or right child of the vertex). For instance, consider the binary tree shown in Figure 14.42. The array for this tree will be constructed in the following manner. We will have a row of the array corresponding to each vertex in the graph and then an indication in the Figure 1442 Abinary tree middle and right cells the left and right children of the vertex. For the example given in Figure 14.42, we would have the following: ela : i i mla|=|m|olole|> |= elolololm|almlal> elelolelolalo|o|= Siro lawia a Note that a 0 is used to indicate the absence of a particular type of child for any given vertex. The virtue of this construction, as was the case for the ad- jacency matrix, is that it is easily programmed into a computer, and thus the information contained within the tree is able to be stored in a form usable to the computer. Tree Traversal ere are several methods for doing this, but the one we shall present here is called the preorder method. In this technique, we describe the branches of the tree, following them to their final leaf and then moving to the next branching. Consider the example shown in Figure 14.43. The tree structure begins with the root r, which we will list first. We will then follow the left-most branch of the tree to its final leaf: RACGI i i vf Tae ene Graph Theory 533 Figure 14.43 A binary tree J K Having reached the final leaf, we return to the immediately preceding “fork” in the tree, and follow that branch to its final leaf. The fork came at G, and follow- ing the other direction at that fork reaches the final leaf K, which extends our traversal list to RAGGIK ‘We continue to backtrack to all preceding forks and follow the alternate path to the final leaf of that branch. Doing so, we obtain RACGILKHD,LB EP Since the vertices are identified strategically, with horizontally aligned vertices labeled using successive letters of the alphabet, it is possible to reconstruct the graph given this traversal listing, Thus, we have a second method for storing the information of the tree in a form to which computers can readily be applied. EXAMPLE 14.17 Figure 14.45 Partially completed tree Draw the tree whose preorder traversal representation is as follows R,A,C,G,D, H,1,B, EJ, FKL SOLUTION ‘The root of the tree is, as has been our convention, R, and we see in the listing that the next two vertices shown are A, C (Figure 14.44), Since B is missing, we know there is a binary fork from R, with two initial vertices in the tree, A and B. Following A, we have vertex C, and since G stands between Cand D, it must be that Cand D are children of A, while Gs a child of C. Also, since H and I appear in the listing after D and before the “out-of-order” letter B, it follows that Hand [are children of D. Thus, we have (to this point) the partial construct shown in Figure 14.45. Returning to the list, we see that the next vertex in order is B, followed by E, J, and F, Since Jis interposed between E and F, it must be that E and F are children of B, with Ja child of B. Following F, we see K and L, which must be children of F, and therefore the completed tree is as shown in Figure 14.46.

You might also like