Docsity

Mathematical Modeling - Discrete Math Model | MATH 381, Study notes of Mathematics

Partial preview of the text

Download Mathematical Modeling - Discrete Math Model | MATH 381 and more Study notes Mathematics in PDF only on Docsity!

Mathematical Modeling

Math 381 Course Notes

University of Washington

Prof. Tim Chartier

Winter 2008

© cR. J. LeVeque

Acknowledgments: These notes are based on many quarters of teaching Math 381. The original notes were compiled by Randy LeVeque in Applied Math at UW. Tim Chartier and Anne Greenbaum contributed significantly to the current version in 2001-2002. Sara Billey contributed to the manuscript in the fall of 2004. Tim Chartier made further contributions as he taught a version of this course at Davidson College in the 2005. Jim Burke contributed a portion of the chapter on linear programming. We thank them for their efforts. Since this document is still evolving, we appreciate the input of our readers in improving the text and its content.

 - Math 381 Notes — University of Washington — Winter 
  • 1 Introduction to Modeling
    • 1.1 Lifeboats and life vests
    • 1.2 The goals of
  • 2 Graph Theory and Network Flows
    • 2.1 Graphs and networks
    • 2.2 The traveling salesman problem
      • 2.2.1 Brute force search
      • 2.2.2 Counting the possibilities
      • 2.2.3 Enumerating all possibilities
      • 2.2.4 Branch and bound algorithms
    • 2.3 Complexity theory
    • 2.4 Shortest path problems
      • 2.4.1 Word ladders
      • 2.4.2 Enumerating all paths and a branch and bound algorithm
      • 2.4.3 Dijkstra’s algorithm for shortest paths
    • 2.5 Minimum spanning trees
      • 2.5.1 Kruskal’s algorithm
      • 2.5.2 Prim’s algorithm
      • 2.5.3 Minimum spanning trees and the Euclidean TSP
    • 2.6 Eulerian closed chains
    • 2.7 P, N P, and NP-complete problems
  • 3 Stochastic Processes
    • 3.1 Basic Statistics
    • 3.2 Probability Distributions and Random Variables
      • 3.2.1 Expected Value
    • 3.3 The Central Limit Theorem
    • 3.4 Buffon’s Needle
  • 4 Monte Carlo Methods
    • 4.1 A fish tank modeling problem
    • 4.2 Monte Carlo simulation
      • 4.2.1 Comparison of strategies
    • 4.3 A hybrid strategy
    • 4.4 Statistical analysis
    • 4.5 Fish tank simulation code
    • 4.6 Poisson processes
    • 4.7 Queuing theory
  • 5 Markov Chains and Related Models ii CONTENTS
    • 5.1 A Markov chain model of a queuing problem
    • 5.2 Review of eigenvalues and eigenvectors
    • 5.3 Convergence to steady state
    • 5.4 Other examples of Markov Chains
      • 5.4.1 Breakdown of machines
      • 5.4.2 Work schedules
      • 5.4.3 The fish tank inventory problem
      • 5.4.4 Card shuffling
    • 5.5 General properties of transition matrices
    • 5.6 Ecological models and Leslie Matrices
      • 5.6.1 Harvesting strategies
  • 6 Linear Programming
    • 6.1 Introduction
      • 6.1.1 What is optimization?
      • 6.1.2 An Example
      • 6.1.3 Sensitivity Analysis
      • 6.1.4 Duality Theory
      • 6.1.5 LPs in Standard Form and Their Duals
    • 6.2 A pig farming model
      • 6.2.1 Adding more constraints
      • 6.2.2 Solving the problem by enumeration
      • 6.2.3 Adding a third decision variable
      • 6.2.4 The simplex algorithm
    • 6.3 Complexity and the simplex algorithm
  • 7 Integer Programming
    • 7.1 The lifeboat problem
    • 7.2 Cargo plane loading
    • 7.3 Branch and bound algorithm
    • 7.4 Traveling salesman problem
      • 7.4.1 NP-completeness of integer programming
    • 7.5 IP in Recreational Mathematics
      • 7.5.1 An Example Puzzle
      • 7.5.2 Formulation of the IP
    • 7.6 Recasting an IP as a 0-1 LP

Math 381 Notes — University of Washington — Winter 2008

Chapter 1

Introduction to Modeling

1.1 Lifeboats and life vests

In a January, 1998 article “Most Ferries Short Of Life Rafts – Is It A Titanic Problem Or A Reasonable Cost-Control Measure?” the Seattle Times announced that Washington State Ferries, which service the Puget Sound area (see Figure 1.1), were not carrying enough lifeboats for all passengers. In fact, as we will see there is a reason for this decision. The ferries do carry enough life vests to make up the difference. However, the Washington ferries traverse cold waters. As such, it would be better to carry more lifeboats since your chances of surviving are better in a lifeboat than in cold water. However, lifeboats take up much more space and so there is a tradeoff — the capacity of the ferries would be greatly reduced if they had to carry enough lifeboats for everyone. Suppose the XYZ Boat-builders have come to us with the following problem. They are designing a new ferry boat and want to determine the number of lifeboats and life vests to equip it with. They give us the following information:

  • Each vest holds 1 person and requires 0.05 m^3 of space to store.
  • Each boat holds 20 people and requires 2.1 m^3 of space to store.
  • We must have capacity for 1000 people in one or the other.
  • The total space to be devoted to this equipment is at most 85 m^3.

How many of each should they install?

One might go through the following steps in determining a solution:

  1. First see if it’s possible to accommodate everyone in lifeboats, which would be best. This would require (1000/20) × 2 .1 = 105m^3 of space, so the answer is no, we must use some combination.
  2. Make sure there’s enough space for life vests for everyone, otherwise the problem is impossible: 1000 × .05 = 50m^3 , so it would be possible to provide only life vests and have space left over. But for the best solution we’d like to use more of the available space and provide as many boats as possible.
  3. Figure out how many boats and vests are used if we exactly use all the available space and provide exactly the necessary capacity. We can set this up as a mathematical problem. There are two unknowns

x 1 = number of vests x 2 = number of boats

1.2 The goals of 381 3

Figure 1.2: Balancing the load of ferries is important as the boats carry great weights. (Picture taken from http://www.wsdot.wa.gov/ferries/.)

this to XYZ. They respond: “Well sure, the 85m^3 figure was just an approximation. We can easily find another 0.2m^3 if it means we can fit in two more boats.

This simple example illustrates some of the issues involved in mathematical modeling:

  • The problem is usually not presented as a standard mathematical problem, but must be worked into this form.
  • There may be many different ways to model the same problem mathematically. In the above example we reduced it to a linear system. But for more complicated problems of this same type this would not be possible and we would have to deal directly with the fact that we are given inequality constraints (e.g., the total volume must be no more than 85 m^3 ) rather than equalities. The problem is better set up as a linear programming problem, a type of discrete optimization problem in which we try to maximize the number of boats subject to two sets of constraints (an upper bound on volume and a lower bound on capacity). Actually it is an integer programming problem since we also have the constraint that the solution must be a pair of integers. There are standard methods for solving these types of problems.
  • Once the “mathematical problem” has been solved (e.g., the linear system above), we need to interpret the answer to this problem in terms of the original problem. Does it make sense?
  • Often the information presented is not complete or necessarily accurate. Here, for example, we weren’t told to begin with the information that the number of boats had to be even, or that the available volume was only approximate.
  • Often the problem is far too hard to model in detail and solve exactly. This example was quite straightforward in this regard, but typically one must make decisions about what aspects to consider and which can be safely ignored (or must be ignored to get a solvable problem). Often there is no “right answer”, though some answers are much better than others!

1.2 The goals of 381

The goals of Math 381 are the following:

  • Learn about the modeling process. How does one take an ill-defined “real world problem” and reduce it to a mathematical problem that can be solved by standard techniques? What issues are

4 Introduction to Modeling

involved in dealing with real data and complex problems, where we can often only hope to model some small piece of the total problem?

  • In order to have any chance of making a model that reduces to a “standard mathematical problem”, we must learn what some of these standard problems are. For example, in the above problem we recognized early on that we could set it up as a linear system of equations, and we knew that this would be a good thing to do since there are standard methods for solving such systems (such as Gaussian elimination). We need some more tools in our tool bag in order to do modeling. We will see a variety of standard problems and how each can arise in many different contexts. These will be introduced in the course of looking at a number of modeling problems.
  • Math 381 concentrates on discrete modeling, which means the mathematical problems typically involve a discrete set of values or objects (e.g. the life vests and lifeboats). Moreover there are typically a discrete set of possibilities to choose between. Trying out all of the possibilities to see which is best might be one possible approach, but is typically very inefficient. We want to use mathematical techniques to make the job easier. For example, it is clear that the solution to the problem above must consist of at most 1000 vests (since this would accommodate everyone) and at most 40 lifeboats (since this would use all the available space). One could try all possible combinations and find the right mix by trial and error, but as mathematicians we recognize that it is much easier to simply solve a 2 × 2 linear system. There are many standard mathematical problems and techniques which are useful in discrete modeling. Some of these are: - Linear programming and integer programming, - Combinatorics and combinatorial optimization, - Graph theory, - Network flows and network optimization, - Dynamic programming, - Queuing theory, - Stochastic processes and Markov chains, - Monte Carlo simulation, - Difference equations and recurrence relations, - Discrete dynamical systems, - Game theory, - Decision analysis, - Time series analysis and forecasting.

Many modeling problems are better solved with continuous models, in which case different mathe- matical techniques are used, for example differential equations. Such models are studied in AMath

  • The main emphasis of this course will be on the modeling process, taking a problem and setting it up as a mathematical problem, and interpreting the results of the model. Along the way we also will learn something about techniques for solving some of the standard problems listed above, e.g., solving a linear programming problem by the “Simplex Method”. This is necessary in order to solve the modeling problem, but the study of methods for solving these problems is not the main emphasis of this course. There are other courses which concentrate on understanding the mathematical aspects of these problems and the methods which have been developed to solve them. Some of these are:

6 Introduction to Modeling

Math 381 Notes — University of Washington — Winter 2008

Chapter 2

Graph Theory and Network Flows

2.1 Graphs and networks

Imagine you are planning a trip around the United States based on a map showing distances between various cities and points of interest. The map has a labeled point for each city and lines connecting nearby cities are labeled by the distance between the two cities. One might ask a question like “How should we drive if we want to visit every city on the map?” This is an example of a network flow problem from graph theory. More generally, a graph is a collection of vertices or nodes which are connected by edges. A graph is connected if there is a way to get from any vertex to any other vertex by following edges. Figure 2.1 shows a few types of (connected) graphs that arise in many different applications:

  • A directed graph (or digraph) has arrows on edges indicating what direction one can move between nodes.
  • A network has weights on the edges, often indicating the cost of moving from one vertex to the neighbor, e.g. the distance or driving time in the map example. A network could also be directed, for example if some routes on the map are one-way streets.
  • A tree is a connected graph which contains no circuits. A family tree is one familiar example.

Graph Directed graph Network Tree

2

3

6

4

12

3

(^46)

2

8

5 10

Figure 2.1: Some common graphs.

The vertices and edges of a graph might represent any number of different things, depending on the application. For example, the vertices in a digraph might represent legal positions in a game, with an arrow from Vertex A to Vertex B if you can go from Position A to Position B by a single legal move. Or the vertices could represent individuals in a hierarchical organization, with an edge from A to B if Person A reports to Person B. These and other examples are discussed in [Rob76].

2.2 The traveling salesman problem 9

as an addition or multiplication. These are called floating point operations since scientific notation is usually used to represent a large range of values on the computer. For computations of the sort mathematicians, engineers and scientists do, a useful measure of a computer’s speed is the number of floating point operations per second, called flops. Machine speed is often measured in megaflops (millions of floating point operations per second). A 500 MHz machine might do about 40 megaflops. Supercomputer speeds are often measured in gigaflops (billions of flops) or teraflops (trillions of flops). Returning to the traveling salesman problem, note that to compute the length of a single route requires about N additions, adding up the length between each pair of cities on the route, as well as more work to keep track of which route to examine next, which route is shortest, etc. Let’s not worry too much about the exact cost, but suppose that we are working on a machine that can examine ten million routes per second. Then solving the 10-city TSP would take about 1/3 of a second. Not bad. But already with 20 cities it would be difficult to find the answer using this brute force approach. We now have about 2. 4 × 1018 routes to examine, and at a rate of 10 million per second this will take

  1. 4 × 1011 seconds, which is about 7,715 years. Even if we move up to a supercomputer that is a thousand times faster, it would take almost 8 years. For a TSP with 50 cities there is no conceivable computer that could find the solution in our lifetimes, using the brute force approach. Many simple problems suffer from this kind of combinatorial explosion of possible solutions as the problem size increases, which makes it impossible to simply enumerate and check every possibility. Nonetheless such problems are solved daily, using more sophisticated mathematical techniques.

2.2.3 Enumerating all possibilities

For an N-city TSP with N sufficiently small, we could solve by enumeration. This requires some algorithm for systematically checking every possibility. Figure 2.2 shows one way to think about enu- merating all the possible routes for the 4-city TSP. In the rightmost column is an enumeration of all 24 routes in the lexicographic order, so called because this is the order that would be obtained by putting the 24 strings representing different routes into alphabetical order. Note that the 3! = 6 routes starting with A come first, then the 6 routes starting with B, and so on. Within each set, the routes are grouped by which city comes second, ordered from “lowest” to “highest” in lexicographic ordering.

2.2.4 Branch and bound algorithms

Instead of evaluating the cost of every path appearing in the tree of Figure 2.2, one might be able to rule out some paths early if their cost exceeds that of the best path discovered so far. Consider, for example, the network in Figure 2.3. One might first try a greedy algorithm that takes the shortest edge to a new city at each step. This leads to the path O-ADCB-O, which has a total cost of 15. After discovering this, any path in Figure 2. that uses edge BD (or, equivalently, DB) can be eliminated, since the cost of that edge alone is 16. By continuing to check the other paths that start with O-A, one finds that the path O-ABCD-O has a cost of only 14. Examining next the paths that begin with O-D, and discarding any partial paths whose cost exceeds 14, one finds that O-DABC-O costs only 11, and this enables one to eliminate even more possibilities. Paths beginning with O-C and O-B still must be checked, but as soon as the cost of a partial path exceeds 11, that branch of the tree can be eliminated from further consideration. This type of algorithm is sometimes called a branch and bound algorithm. The key idea is to obtain some sort of bound on how good the shortest path within a given subtree could possibly be and, if a less costly path has already been identified, to prune away those branches of the tree, thereby reducing the required computation. If we are unlucky then we might not be able to prune much of the tree and in the worst-case scenario we have to examine the entire tree anyway, which is no improvement in running time. However in practice a good branch and bound algorithm will typically be much faster than pure enumeration, and problems are solved this way which would otherwise be intractable.

10 Graph Theory and Network Flows

ABCD ABDC ACBD ACDB

BDCA

BDAC

BCDA

BCAD

BADC

BACD

ADBC ADCB

ABC ACB ACD ADB ADC

ABD AB AC AD

A

BAC BAD BCA BCD BDA BDC

BA BC BD

CABD CADB CBAD CBDA CDAB CDBA

DABC DACB DBAC DBCA DCAB DCBA

CAB CAD CBA CBD CDA CDB

DAB CAC DBA DBC DCA DCB

CA CB

DB DB

DA

CD

C

B

O

D

Figure 2.2: Decision tree for enumerating all possible routes in a traveling salesman problem starting from City O and visiting four other cities A, B, C, and D. The right column shows an enumeration of all permutations of the 4 cities, in lexicographic order.

O

A B

D C

Seattle =

Figure 2.3: A traveling salesman network starting from Seattle and visiting four other cities A, B, C, and D.

12 Graph Theory and Network Flows

FLOUR

FLOOR

FLOOD

BLOOD

BROOD

BROAD

BREAD

Given two English words with the same number of letters, how could we determine the shortest word ladder between them? (Assuming there is one, or determine that none exists.) This can be set up as a network flow problem. Suppose we are considering N -letter words, then we could in principle construct a graph where the vertices consist of all N -letter words in the English language. We draw an edge from one vertex to another if those two words are simple mutations of each other in which only a single letter has been changed. A word ladder then corresponds to a path through this graph from one word to the other. In fact this graph (with nearly 6000 vertices) has been constructed for N = 5 by Don Knuth and is available on the web (see the pointer from the class webpage). Word ladders and algorithms for manipulating these graphs are discussed at length in [Knu93], which describes a general platform for combinatorial computing. Finding the shortest word ladder is equivalent to the shortest-path problem through a network if we assign every edge in the graph the weight 1. Given a network and two specific vertices, how do we find the shortest path between them? For small networks this is easy to do by trial and error, particularly if the graph is drawn in such a way that the physical distance between the vertices roughly corresponds to the weight of the edge, as is the case for a map. But the weights may have nothing to do with physical distance and at any rate if there are thousands or millions of vertices and edges it may be impossible to even draw the graph.

2.4.2 Enumerating all paths and a branch and bound algorithm

One approach to solving a shortest-path problem would be to enumerate all possible paths between the start and end vertices, compute the length of each path, and choose the shortest. To enumerate all paths, we could build a “decision tree” similar to what was illustrated in Figure 2.2 for the TSP. The problem with this approach is that for a graph with N vertices, there may be very many possible paths to choose between. How many? In the worst case, there would be an edge connecting each vertex with each of the N − 1 other vertices. In this case we could visit any or all of the other vertices on the way between the start and finish, and the number of possible paths would be exponential in N , just as for the TSP. The set of all possible paths could be searched more efficiently using a branch and bound algorithm, similar to that described for the TSP. However, for this problem there turn out to be much more efficient algorithms which are guaranteed to give the answer with relatively little work.

2.4.3 Dijkstra’s algorithm for shortest paths

Dijkstra’s algorithm is a systematic procedure for finding the shortest path between any two vertices. Actually this algorithm solves the problem by embedding it into what appears to be a harder problem, that of finding the shortest route to all other vertices from a given vertex. The set of all shortest routes is built up in N steps, by finding the closest node in Step 1, the next closest node in Step 2, and so on. By the end we know the best route to every other node and in particular to the destination node. Each step requires examining the distance from the node that was “solved” in the previous step to all unsolved nodes which can be reached from this node. This requires examining at most N − 1 edges, so the work required is O(N ) in each of the N steps, and hence the total work is O(N 2 ). To implement it on a computer for a large network requires some suitable data structure for storing the network with information about which vertices are connected to one another and the weight of each edge. One way to represent a network or directed network on a computer is with a matrix. The rows

2.5 Minimum spanning trees 13

and columns correspond to the nodes of the network and the (i, j) entry of the matrix is the weight on the edge from node i to node j (or, if there is no edge from i to j, that entry can be set to ∞). A matrix representation of the network in Figure 2.3 is:

O A B C D − − − − − O | 0 2 5 4 3 A | 2 0 2 9 1 B | 5 2 0 1 16 C | 4 9 1 0 6 D | 3 1 16 6 0

We’ll go through some simple examples of Dijkstra’s algorithm in class. It is described in many books, e.g., [HL95] and [Rob84]. A writing assignment will be to produce your own description of this algorithm.

2.5 Minimum spanning trees

Another type of problem that arises in many applications is to connect a collection of vertices at the lowest possible cost. Examples include highway construction and telephone line installation: the vertices represent cities and the roads or phone lines correspond to edges constructed so that there is some path between every pair of vertices. In graph theoretic terms, this is accomplished via a minimal cost spanning tree. Recall that a tree is a graph that is connected and has no circuits. If a group of vertices is connected by edges that do contain a circuit, then it is not hard to see that one (or more) of the edges can be removed without destroying the connectedness of the graph. This is illustrated in Figure 2.4. Since each edge has a nonnegative cost associated with it, clearly the least expensive way to connect the vertices will be via a graph with no circuits (i.e., a spanning tree).

Figure 2.4: Graphs with circuits and corresponding spanning trees

In a spanning tree, the number of edges is always one less than the number of vertices: e = N − 1. Each graph in Figure 2.4 has N = 5 vertices, and the two trees have e = 4 edges. There are two well- known algorithms for finding a minimal cost spanning tree in a connected network: Kruskal’s algorithm and Prim’s algorithm.

2.5.1 Kruskal’s algorithm

Kruskal’s algorithm begins by sorting the edges of the graph in order of increasing cost. For the network shown in Figure 2.5 this order is: {AB}(8), {CD}(10), {CE}(12), {DE}(22), {BC}(53), {BE}(54), {AD}(63), and {AE}(70). Each edge is then considered in turn and, if it does not form a circuit with edges already in the good set, it is added to the good set. This is continued until the good set has N − 1 edges. Since the good set has no circuits, it is a tree. If all edges have been examined and the good set still does not have N − 1 edges, it means that the original graph must not have been connected, and this fact can be reported to the user. The first edges added to the tree from Figure 2.5 are {AB},

2.6 Eulerian closed chains 15

While there is no known polynomial time algorithm for solving the Euclidean TSP, there is an easy way to find a route whose cost is within a factor of two of the optimal: Construct a minimum spanning tree. Starting at the origin node, move along edges of the minimum spanning tree until you can go no further. Then backtrack along these edges until you reach a point from which you can traverse a new edge to visit a new node or until all of the nodes have been visited and you can return to the origin. This is illustrated in Figure 2.6, where the minimum spanning tree is marked and the suggested path is ODOABCBAO. The total cost of this path is twice the cost of the minimum spanning tree. Another possible path is OABCBAODO, which also traverses each edge of the minimum spanning tree twice.

5

8

7

9 C

5

7

13

11

12

10

O

A B

D

Figure 2.6: Euclidean TSP network with minimum spanning tree. Path OD-O-ABC-BA-O costs twice as much as the minimum spanning tree, and tour ODABCO is within a factor of two of optimal.

The path constructed in this way is not a legitimate tour for the TSP, since it visits some nodes more than once. But because the weights satisfy the triangle inequality, any path between nodes that visits other nodes along the way that have already been visited can be replaced by a direct route between the given nodes, and the cost will be no greater. Thus one arrives at a tour whose cost is at most twice that of the minimum spanning tree. For the example in Figure 2.6, this tour is ODABCO and has a total cost of 40. Had we chosen the other path, OABCBAODO, it would have been replaced by the tour OABCDO, which has a total cost of 34 (and turns out to be the optimal tour for this problem). Since the minimal cost spanning tree is the lowest cost set of edges that connects all of the vertices, any traveling salesman tour that visits all of the vertices must cost at least as much as the minimal cost spanning tree: 25 for our example. This gives a lower bound on the cost of the optimal tour, while the tour derived above, whose cost is within a factor of two of this value, provides an upper bound. This information can be used within a branch and bound algorithm to hone in on the actual optimal tour.

2.6 Eulerian closed chains

Still another type of graph thoeretic problem that arises in many applications is that of finding an Eulerian closed chain: A path that starts at a given node, traverses each edge of the graph exactly once, and returns to the starting point. This problem might arise, for example, in scheduling snowplows or street sweepers. If the edges of the graph represent streets, then the object is to plow or sweep each street once but, if possible, not to backtrack over streets that have already been serviced. This type of problem is also popular in many mathematical games. In fact, it is said that graph theory was invented by Euler in the process of settling the famous K¨onigsberg bridge problem. The situation is pictured in Figure 2.7. There are seven bridges and the question is whether one can start at a particular point, cross each bridge exactly once, and return to the starting point. If you try it for a while, you can probably convince yourself that the answer is “No”. To see this in a more formal way, let the land masses in the problem be represented by nodes and the bridges by edges in a multigraph (a graph that can have more than one edge between a pair of nodes). This multigraph is shown in Figure 2.8. Note that if we start at a particular node in the multigraph and travel along one edge to a different node, then we must leave that node along a different edge. If there is only one edge through the node then this will not be possible. Moreover, if there are three or five or

16 Graph Theory and Network Flows

D

A

B

C

Figure 2.7: The bridges of K¨onigsberg

D

A

B

C

Figure 2.8: Multigraph representing the bridges of K¨onigsberg

any odd number of edges through that node, then in order to traverse all of these edges, we will have to enter then leave the node until there is only one unused edge remaining. But at that point we are stuck, because we must enter the node in order to use that edge, but then we cannot leave. The same holds for the starting node. If there is only one edge through it, then we can leave but never return, and if there are an odd number of edges through it, then we can leave and return a certain number of times but eventually we will be at the starting node with one unused edge remaining to traverse. The degree of a vertex is defined as the number of edges through that vertex. Using the above sort of reasoning Euler proved the following:

Theorem (Euler[1736]). A multigraph G has an Eulerian closed chain if and only if it is connected up to isolated vertices and every vertex of G has even degree.

The condition that the graph be connected up to isolated vertices just means that there is no edge that cannot be reached at all. There is no Eulerian closed chain in Figure 2.8 since, for example, vertex D has degree 3. (In fact, all of the vertices in this multigraph have odd degree.) A good way to establish the sufficiency of Euler’s theorem is by describing an algorithm for computing an Eulerian closed chain in an even connected multigraph. Consider, for example, the multigraph in Figure 2.9. Start at any vertex and travel to other vertices along unused edges until you can go no further. For example, we might start at A, go to B, C, D, back to B, and then to A. For each of the vertices visited we use an even number of edges — one to enter and one to leave — each time we visit the vertex, so that the number of unused edges through each vertex remains even. Moreover, once we leave the initial vertex, it is the only one with an odd number of unused edges through it; for every other vertex, if we enter we can also leave. Therefore our path can end only back at the original vertex. At this point, we may not have traversed all of the edges of the multigraph, so go to any vertex that has some unused edges through it: vertex C, for example, and repeat. Take one of the unused edges to a new vertex and again continue until you can go no further. For example, we might go from C to E to F to G to E to C. This path can be combined with our previous one to form the chain: