1 / 148

# A Mathematical View of Our World - PowerPoint PPT Presentation

A Mathematical View of Our World. 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer. Chapter 6. Routes and Networks. Section 6.1 Routing Problems. Goals Study graphs, vertices, and edges Study paths and circuits Study connected graphs Use Euler’s Theorem Use Fleury’s Algorithm.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'A Mathematical View of Our World' - thom

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### A Mathematical View of Our World

1st ed.

Parks, Musser, Trimpe, Maurer, and Maurer

### Chapter 6

Routes and Networks

Section 6.1Routing Problems

• Goals

• Study graphs, vertices, and edges

• Study paths and circuits

• Study connected graphs

• Use Euler’s Theorem

• Use Fleury’s Algorithm

• Can the people of Konigsberg, pictured here, take a walk crossing each bridge exactly one time?

• The solution will be given at the end of the section.

• A graph is a collection of one or more points, called vertices, and the paths connecting them, called edges.

• The singular of vertices is vertex.

• The vertices are drawn as dots.

• The edges are drawn as straight or curved lines.

• Each edge has two ends with a vertex at each end, or else it is a loop connecting a vertex to itself.

• Two graphs are considered the same if they have the same number of vertices connected in the same way, even if they look different.

• The three graphs shown are equivalent.

• Two edges may appear to cross, but they do not actually intersect unless there is a vertex.

• Example: Graph (a) shows two edges crossing where there is no vertex.

• Graphs can be drawn to represent real-life connections, such as roads between cities.

• Example: Draw a graph to represent the roadmap.

• Solution: The vertices represent the cities, and the edges represent the roads.

• Two vertices are called adjacent vertices if there is an edge connecting them.

• List the pairs of adjacent vertices in the graph.

• Solution: The pairs of adjacent vertices are:

• A and B, A and C, A and D, A and E

• B and D

• C and E

• E and E, since there is a loop at E

List all the vertices that are adjacent to the vertex labeled Portland.

a. Salem, Boise, Olympia

b. Salem, Spokane

c. Salem, Olympia, Seattle, Spokane

d. Boise

• Draw two different graphs with the following properties:

• Vertices: A, B, C, and D

A and C, B and C, B and D, C and D.

• Solution: Two possible graphs are shown below.

• The degree of a vertex is the total number of edges at the vertex.

• Find the degree of a vertex by counting the number of edges leaving or arriving at the vertex.

• A loop contributes 2 to the degree of a vertex.

• Find the degree of each vertex in the graph.

• Solution:

• A has degree 5,

• B has degree 3,

• C has degree 2,

• D has degree 2,

• E has degree 4.

• If d is the sum of all the degrees of the vertices in a graph and e is the number of edges in the graph, then d = 2e.

• Note: This theorem is true because each edge adds 2 to the degree total.

• Verify that the theorem is true for the following graph.

• Solution: The sum of the degrees is 16. The number of edges is 8. Check that 16 = 2(8).

• A path is a route in a graph.

• Each vertex used is adjacent to the next vertex used.

• Each edge in the graph is used at most one time.

• A path is written as a list of vertices.

• Find three different paths in the graph.

• Solution:

• One possible path is A,B,D,A,E.

• A second path is B,A,B,D.

• A third path is C,E,E,A

• There are many other paths.

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

• Example: One circuit in the graph is A,B,D,A.

• A path that uses every edge of a graph exactly once is called an Euler path.

• Note: Euler is pronounced “oiler.”

• Example: The edges are numbered in the order used.

• A circuit that uses every edge of a graph exactly once is called an Euler circuit.

• Example: The edges are numbered in the order used.

• A graph is said to be connected if, for every pair of vertices, there is a path that contains them.

• If a graph is not connected, it is said to be disconnected.

• An edge is called a bridge if its removal from the graph would change the graph from connected to disconnected.

• Explain whether or not the graphs are connected.

• Solution: The graph is connected because there is a path, using one edge or more, between every pair of vertices.

• Solution 2: The graph is disconnected because, for example, there is no path between vertex A and vertex G.

• Identify any bridges in the (connected) graph.

• Solution: There are three bridges: the edge between D and E, the edge between D and F, and the edge between F and G.

• A component of a graph is a maximal connected piece of the graph.

• A component is connected.

• If any more edges are added to the component (if there are any more in the graph) it would become disconnected.

• Every graph has one or more components.

• Any connected graph has one component.

• For the connected graph in the previous example, the entire graph is the only component.

• A disconnected graph has two or more components.

• For the disconnected graph in the previous example, there are two components.

• To find the components of a graph, use the following algorithm.

• Pick any vertex of the graph and highlight it.

• Highlight all edges connecting to the highlighted vertex and all vertices at the end of those edges.

• Repeat step 2 as many times as possible.

• When no more vertices can be highlighted, you have a component.

• Find all components of the graph.

• Solution: We use the algorithm from the preceding slide. There are three components: the piece containing A, E, F, and G; the piece containing B and C; and the piece containing D.

• Any graph must have an even number of vertices with odd degree.

• We saw earlier that the sum of all the degrees in a graph is always an even number, so:

• Vertices with even degrees do not have to come in pairs.

• Vertices with odd degrees come in pairs.

• For a connected graph:

• If the graph has zero vertices of odd degree, then it has at least one Euler circuit.

• If a graph has an Euler circuit, then it has no vertices of odd degree.

• For a connected graph:

• If the graph has exactly two vertices of odd degree, then

• It does not have an Euler circuit.

• It has at least one Euler path.

• Any Euler path starts at one of the two vertices of odd degree and ends at the other.

• For a connected graph:

• If the graph has more than two vertices of odd degree, then

• It does not have an Euler circuit.

• It does not have an Euler path.

Does the graph have an Euler circuit, an Euler path, or neither?

a. Euler circuit

b. Euler path only

c. neither

• Does the graph have an Euler circuit, Euler path, or neither?

• Solution: Every vertex is of degree 2 or degree 4, so by Euler’s theorem the graph has an Euler circuit.

• Solution: There are two vertices of odd degree, E and G, so by Euler’s theorem the graph has only an Euler path.

• If Euler’s Theorem indicates that there is an Euler circuit, Fleury’s Algorithm can be used to find the circuit.

• The step-by-step procedure is as follows:

• Copy all the vertices, but not the edges, of the original graph.

• Select any vertex on the original graph and mark it as the present position.

• Choose one edge at the marked vertex and transfer it to the new graph.

• Do not choose a bridge, unless it is the only edge available.

• Number the edges in the order they are transferred.

• Use the vertex on the other end of the edge as the new present position. Repeat step 3.

• When you transfer the last edge you are done.

• Use Fleury’s Algorithm to find an Euler circuit for the graph.

• Possible Final Solution:

• The idea of Euler circuits can be used to solve the question of whether the people of Konigsberg can take a walk crossing each bridge exactly one time.

• The vertices represent the land and the edges the bridges. The described walk would be an Euler path.

• We use Euler’s Theorem to show that there is no such path for their walk because there are four vertices of odd degree.

Section 6.2Network Problems

• Goals

• Study weighted graphs

• Study spanning trees

• Study minimal spanning trees

• Use Kruskal’s algorithm

• Walkways need to be built between the buildings on the campus pictured at right.

• How can the walkways be constructed so that:

• Students can go from any building on campus to any other building without needing to walk outside.

• The total length of the walkways is minimized.

• The solution will be given at the end of the section.

• A graph in which each edge has a number associated with it is called a weighted graph.

• The number corresponding to an edge is called the weight of the edge.

• Typically the weights of the edges in a graph are assigned in a way that represents some physical situation or practical problem.

• The lengths of the edges in a graph do not have to be proportional to the stated weights.

• An example of a weighted graph is shown below.

• Suppose Ed has:

• A 35-minute drive from his home to his workplace

• A 15-minute drive from his workplace to his health club

• A 25 minute drive from his health club to his home

• Draw a weighted graph to represent this situation.

• Solution:

• The vertices of the graph will represent Ed’s home (H), his workplace (W), and his health club (C).

• The weight of each edge will represent the driving time between the two places.

• For simplicity, we can draw all the edges as straight lines and with the same length.

• Solution, cont’d: One possible weighted graph is shown below.

• Redundant edges are edges that can be removed while still leaving a path between the two vertices.

• Example: If edge CH is removed from the previous graph, Ed can still get from home to his club by driving to work and then to the club.

• The edge CH is a redundant edge.

Are there any redundant edges in the graph?

a. yes

b. no

• A subgraph of a given graph is a set of vertices and edges chosen from among those of the original graph.

• Example: Removing edge CH creates the subgraph shown at right.

• Example: Another subgraph could be created by removing vertex C and its two incident edges.

• A bus line goes between the cities shown in the table.

• Draw a weighted graph to represent the situation.

• Find two different routes from Selma to Anniston.

• Solution: A weighted graph is shown below.

• Solution: One possible route from Selma to Anniston is SMGA, with a total weight (length) of 49 + 127 + 27 = 203 miles.

• Solution, cont’d: Another possible route from Selma to Anniston is SBA, with a total weight (length) of 160 + 62 = 222 miles.

• One way to recognize that a graph contains redundant edges is to find a circuit in the graph.

• Recall that a circuit is a path that begins at a vertex and returns to that vertex without using any edges twice.

• A connected graph that has no circuits is called a tree.

Choose the graph that is a tree.

a. b.

c. d.

• The following figure gives examples of graphs that are trees and a graph that is not a tree.

• This graph is not a tree because it contains several circuits.

• Find a subgraph that is a tree.

• Solution: Circuits are highlighted and edges are removed until the remaining subgraph has no circuits left.

• A spanning tree is a subgraph that:

• Contains all the original vertices of the graph.

• Is connected.

• Contains no circuits.

• Every connected graph has at least one spanning tree.

• An example of a spanning tree is shown below.

• A spanning tree with the smallest possible total weight is called a minimal spanning tree.

• Since a connected, weighted graph can have multiple spanning trees, there may be one or more than one of those spanning trees with the smallest total weight.

• For the connected, weighted graph shown below:

• Subgraph (b) is not a minimal spanning tree.

• Subgraph (c) is a minimal spanning tree.

• A method known as Kruskal’s algorithm can be used to find a minimal spanning tree of a connected, weighted graph.

• Kruskal’s algorithm begins with all the vertices of a graph and adds edges one by one, using the idea of acceptable and unacceptable edges.

• Acceptable edges are

• Edges that do not share a vertex with any edges already chosen.

• Acceptable edges are

• Edges that connect two components of the subgraph.

• Acceptable edges are

• Edges that connect a component of the subgraph to a new vertex.

• Unacceptable edges are

• Edges that add to a component of the subgraph, but do not add a new vertex.

• Consider only the vertices of the graph.

• Add the edge with the smallest weight.

• Add the acceptable edge with the smallest weight.

• Determine whether all vertices are connected by a path.

• If so, you have a minimal spanning tree.

• If not, repeat Step 3.

• Construct a minimal spanning tree for the weighted graph.

• Solution:

• Add the edge with the smallest weight.

• Solution, cont’d:

• All unused edges are acceptable, so we simply choose the edge with the smallest weight.

• Select the edge with weight 2.6.

• Solution, cont’d:

• The acceptable edges at this step were the ones with weights 4.8 and 3.7.

• Select the edge with weight 3.7.

• Solution, cont’d:

• The subgraph is now connected, so this is a minimal spanning tree.

• The weight of the tree is 1.5 + 2.6 + 3.7 = 7.8.

• How can a college build walkways of the minimum length possible so that students can go from any building on campus to any other building without needing to walk outside?

• Create a weighted graph to represent the buildings and existing sidewalks on the campus.

• The weight of each edge is the distance between the two buildings.

• Use Kruskal’s algorithm to find a minimal spanning tree.

• The edges included in the minimal spanning tree represent the sidewalks that should be converted into covered walkways.

• Under this plan, students can get from any building to any other building without going outside, although they may have to walk farther inside.

• The length of the walkways was minimized to a total of 210 + 220 + 120 + 200 = 750 feet.

Section 6.3Traveling-Salesperson Problem

• Goals

• Study Hamiltonian circuits

• Study the Traveling-Salesperson Problem

• Use the Brute-Force Algorithm

• Use the Nearest-Neighbor Algorithm

• An author needs to find a route that will minimize the total distance she must drive between the cities.

• The solution will be given at the end of the section.

• A path that visits each vertex in a graph exactly once is called a Hamiltonian path.

• If a Hamiltonian path begins and ends at the same vertex, it is called a Hamiltonian circuit.

• The highlighted edges in the graph represent a Hamiltonian path.

• The path can be written AGFEDBC or CBDEFGA.

• The highlighted edges in the graph represent a Hamiltonian circuit.

• The circuit, starting at A, can be written AGFEDCBA

• Note: A Hamiltonian path or circuit must pass through every vertex of the graph, but it does not have to use every edge.

• A Hamiltonian path can be used, for example, to model a delivery truck stopping at every house in a neighborhood but not using every street.

• Find a Hamiltonian path in each graph or explain why you cannot.

• Solution: The path ABCD is a Hamiltonian path.

• Adding an edge to the path forms the Hamiltonian circuit ABCDA.

• Other Hamiltonian paths and circuits are possible.

• Solution: The path ABCD is a Hamiltonian path.

• There is no Hamiltonian circuit.

• There is no Hamiltonian path.

• Any Hamiltonian path must start at either A or F.

• Any path that starts at A will leave out either C, D, or F.

• Any path that starts at F will leave out either C, D, or A.

• A complete graph is a graph in which every pair of vertices is connected by exactly one edge.

• For each graph, determine whether or not it is complete.

• Solution: Check each pair of vertices.

• There is exactly one edge between each pair of vertices, so the graph is complete.

• Solution: Check each pair of vertices.

• There is no edge from A to C, for example. The graph is not complete.

• Solution: Check each pair of vertices.

• There are two edges from A to F, for example. The graph is not complete.

• Draw an example of a complete graph with five vertices.

• Count the number of edges in the graph.

• Solution: Two possible representations of such a graph are shown below.

• A complete graph with 5 vertices has 10 edges.

• The number of edges in a complete graph always follows a certain pattern.

• A complete graph with n vertices

always has edges.

A graph has 20 vertices and 195 edges. Is the graph complete?

a. yes

b. no

• In general, a graph may or may not have a Hamiltonian path or circuit.

• A complete graph, however, always has a Hamiltonian circuit.

• Any list of all the vertices in the graph will be a Hamiltonian path.

• Adding the starting vertex to the end of the list describing the path will create a Hamiltonian circuit.

• List all the Hamiltonian paths and all the Hamiltonian circuits in the graph.

• Solution:

• Note that the complete graph in the previous example had 3 vertices and 6 different Hamiltonian circuits.

• This is the case because each circuit can begin at one of the 3 vertices, travel to one of 2 vertices second, and travel to the 1 remaining vertex last.

• There are 3(2)(1) = 6 Hamiltonian circuits.

• The number of Hamiltonian paths in a complete graph with n vertices is

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

• The symbol n! is read “n factorial”.

How many possible Hamiltonian circuits exist in a complete graph with 9 vertices?

a. 81

b. 40,320

c. 362,880

d. 3,265,920

• A salesperson who must visit various cities and then return home wants to minimize the cost (measured in distance, time, or money) of his or her trip.

• Because Hamiltonian circuits can be applied to find this type of least-cost trip, the problem of finding a least-cost Hamiltonian circuit is called the Traveling-Salesperson Problem.

• The cost of a path in a weighted graph is the sum of the weights assigned to the edges in the path.

• When costs are assigned to each edge in a complete graph, the graph is called a complete weighted graph.

What is the cost of the path ABD in the graph below?

a. 26

b. 14

c. 24

d. 41

• List all possible Hamiltonian paths, and their costs, in the complete weighted graph.

• Find the path of least cost.

• Solution: The graph has 4 vertices, so there are 4! = 24 different Hamiltonian paths.

• These paths and their costs are listed on the next slide.

• Solution, cont’d: There are 2 Hamiltonian paths with the lowest cost of 37.

• CDAB

• List all possible Hamiltonian circuits that start and end at vertex A.

• Find the circuit at A of least cost.

• Solution:

• Solution, cont’d: There are 2 least-cost Hamiltonian circuits with a cost of 74.

• ABCDEA

• AEDCBA

• These 2 circuits are mirror images of each other.

• The method used to solve the previous example is called the Brute-Force Algorithm.

• List all possible Hamiltonian circuits.

• Calculate the cost of each circuit.

• Find the 2 mirror image circuits of least cost.

• This method is very time-consuming.

• Instead of the Brute-Force Algorithm, faster approximation algorithms are typically used.

• An approximation algorithm finds a Hamiltonian circuit that is either the least-cost circuit or is one that is not much more costly than the least-cost circuit.

• Two approximation algorithms will be studied:

• The Nearest-Neighbor Algorithm

• Specify a starting vertex.

• If unvisited vertices remain, go from the current vertex to the unused vertex with the lowest-cost connecting edge.

• If no unvisited vertices remain, return to the starting vertex to finish forming the circuit.

• Apply the algorithm to approximate the lowest-cost Hamiltonian circuit.

• Solution:

• Let the starting vertex be A.

• The unvisited vertices are B, C, D, and E.

• The choice of edges are AB: 13, AC: 11, AD: 17, or AE: 15.

• Choose edge AC and move to vertex C, the new current vertex.

• Solution, cont’d:

• The unvisited vertices are B, D, and E.

• The choice of edges are CB: 20, CD: 12, or CE: 14.

• Choose edge CD.

• Solution, cont’d:

• The current vertex is now D.

• The unvisited vertices are B and E.

• The choice of edges are DB: 19 or DE: 16.

• Choose edge DE.

• Solution, cont’d:

• The current vertex is now E.

• The unvisited vertex is B.

• Choose edge EB.

• Solution, cont’d:

• The current vertex is now B.

• There are no unvisited vertices.

• Solution, cont’d:

• The Hamiltonian circuit is ACDEBA.

• Its cost is 70.

• This is at or near the lowest possible cost.

• All edges are acceptable and no edges have been selected.

• Choose an acceptable edge of smallest weight.

• If a Hamiltonian circuit is not formed, determine the set of acceptable edges and repeat Step 2.

• Unacceptable edges are those that either share a vertex with two selected edges or that will close a circuit that is not Hamiltonian.

• If the selected edges form a Hamiltonian circuit, this is the low-cost Hamiltonian circuit.

• Apply the algorithm to approximate the lowest-cost Hamiltonian circuit.

• Solution:

• All edges are acceptable.

• Select the edge of lowest cost: AC.

• Solution, cont’d:

• All edges are still acceptable.

• Select the edge of lowest cost: CD.

• Solution, cont’d:

• Edges BC,CE, and AD are unacceptable.

• Select the acceptable edge of lowest cost: AB.

• Solution, cont’d:

• Edges BC,CE, BD, and AD are unacceptable.

• Select the acceptable edge of lowest cost: DE.

• Solution, cont’d:

• The only remaining acceptable edge is BE.

• The low-cost circuit is complete, with a weight of 70.

• An author needs to find a route that will minimize the total distance she must drive between the cities shown below.

• Imagine a graph in which the vertices represent the cities and the weighted edges represent the distances.

• This is a Traveling-Salesperson problem, and there are 9! = 362,880 possible Hamiltonian circuits.

• Of these, 8! = 40,320 circuits start at New Orleans.

• With such a large number of circuits, it is foolish to try to solve this by hand using the Brute-Force Algorithm.

• The Cheapest-Link Algorithm will be used to find a low-cost Hamiltonian circuit representing a low-cost trip for the author.

• Rather than drawing the large graph, view the costs (distances) in the table.

• Using the algorithm, add acceptable edges one at a time.

• The first 7 edges added are shown below.

• The cheapest acceptable edge at this point is the route between Charlotte and Orlando.

• After that, the route from New Orleans to Orlando must be added to complete the circuit.

• The approximate least-cost Hamiltonian circuit is shown below.

• The total cost of the circuit is 2462, so the author will drive 2462 miles if she takes this route on her trip.