126
A Mathematical A Mathematical View of Our View of Our World World 1 1 st st ed. ed. Parks, Musser, Parks, Musser, Trimpe, Maurer, and Trimpe, Maurer, and Maurer Maurer

nossi ch 6

Embed Size (px)

Citation preview

Page 1: nossi ch 6

A Mathematical View A Mathematical View of Our Worldof Our World

11stst ed. ed.

Parks, Musser, Trimpe, Parks, Musser, Trimpe, Maurer, and MaurerMaurer, and Maurer

Page 2: nossi ch 6

Chapter 6Chapter 6

Routes and NetworksRoutes and Networks

Page 3: nossi ch 6

Section 6.1Section 6.1Routing ProblemsRouting Problems

• GoalsGoals• Study graphs, vertices, and edgesStudy graphs, vertices, and edges• Study paths and circuitsStudy paths and circuits• Study connected graphsStudy connected graphs

• Use Euler’s TheoremUse Euler’s Theorem• Use Fleury’s AlgorithmUse Fleury’s Algorithm

Page 4: nossi ch 6

6.1 Initial Problem6.1 Initial Problem

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

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

Page 5: nossi ch 6

GraphsGraphs

• A A graphgraph is a collection of one or more is a collection of one or more points, called points, called verticesvertices, and the paths , and the paths connecting them, called connecting them, called edgesedges..• The singular of vertices is The singular of vertices is vertexvertex..

Page 6: nossi ch 6

GraphsGraphs• The The verticesvertices are drawn as dots. are drawn as dots.• The The edgesedges are drawn as straight or curved lines. are drawn as straight or curved lines.

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

Page 7: nossi ch 6

Equivalent GraphsEquivalent Graphs

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

Page 8: nossi ch 6

Example 1Example 1• The three graphs shown are equivalent.The three graphs shown are equivalent.

A is connected to B, B to C, and C to D

Page 9: nossi ch 6

Vertices and EdgesVertices and Edges• Two edges may appear to Two edges may appear to

cross, but they do not cross, but they do not actually intersect unless actually intersect unless there is a vertex.there is a vertex.

• Example: Graph (a) shows Example: Graph (a) shows two edges crossing where two edges crossing where there is no vertex. Think of there is no vertex. Think of a road that crosses an a road that crosses an interstate but there is not interstate but there is not an exit.an exit.

Page 10: nossi ch 6

Example 2Example 2• Graphs can be drawn to Graphs can be drawn to

represent real-life represent real-life connections, such as connections, such as roads between cities.roads between cities.

• Example: Draw a graph Example: Draw a graph to represent highway to represent highway connections between connections between Boise, Olympia, Portland, Boise, Olympia, Portland, Salem, Seattle, and Salem, Seattle, and Spokane.Spokane.

Page 11: nossi ch 6

Example 2Example 2The vertices represent the cities, and the edges The vertices represent the cities, and the edges

represent the roads.represent the roads.

4 of the 5 cities are along the same interstate.4 of the 5 cities are along the same interstate.

Page 12: nossi ch 6

Example 3Example 3• List the pairs of adjacent vertices in the graph.List the pairs of adjacent vertices in the graph.• Two vertices are called Two vertices are called adjacent verticesadjacent vertices if there is an edge if there is an edge

connecting them.connecting them.

Page 13: nossi ch 6

Example 3, cont’dExample 3, cont’d• Solution: The pairs of Solution: The pairs of

adjacent vertices are:adjacent vertices are:• A and B, A and C, A and B, A and C,

A and D, A and EA and D, A and E• B and DB and D• C and EC and E• E and E, since there E and E, since there

is a loop at Eis a loop at E

Page 14: nossi ch 6

Example 4Example 4• Draw two different graphs with the Draw two different graphs with the

following propertiesfollowing properties::• Vertices: A, B, C, and DVertices: A, B, C, and D• Adjacent vertices are:Adjacent vertices are:

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

Page 15: nossi ch 6

Example 4, cont’dExample 4, cont’d• Solution: Two possible graphs are shown below. Solution: Two possible graphs are shown below.

•Vertices: A, B, C, and DVertices: A, B, C, and D•Adjacent vertices are:Adjacent vertices are:

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

Page 16: nossi ch 6

Degree of a VertexDegree of a Vertex• The The degree of a vertexdegree of a vertex is the total is the total

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

the number of edges leaving or arriving the number of edges leaving or arriving at the vertex.at the vertex.

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

Page 17: nossi ch 6

Example 5Example 5• Find the degree Find the degree

of each vertex in of each vertex in the graph.the graph.

Page 18: nossi ch 6

Example 5Example 5• Find the degree of Find the degree of

each vertex in the each vertex in the graph.graph.

• Solution: Solution: • A has degree 5, A has degree 5, • B has degree 3, B has degree 3, • C has degree 2, C has degree 2, • D has degree 2, D has degree 2, • E has degree 4.E has degree 4.

Page 19: nossi ch 6

Example 5Example 5• A has degree 5, A has degree 5, • B has degree 3, B has degree 3, • C has degree 2, C has degree 2, • D has degree 2, D has degree 2, • E has degree 4.E has degree 4.

How many edges are How many edges are there? _____there? _____

How many total How many total degrees are there?degrees are there?

Page 20: nossi ch 6

TheoremTheorem• If If dd is the sum of all the degrees of is the sum of all the degrees of

the vertices in a graph and the vertices in a graph and ee is the is the number of edges in the graph, then number of edges in the graph, then

dd = 2 = 2ee..

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

Page 21: nossi ch 6

Example 6Example 6• Verify that the Verify that the

theorem is true for theorem is true for the following the following graph. graph.

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

Page 22: nossi ch 6

PathsPaths

• A A pathpath is a route in a graph. is a route in a graph.• Each vertex used is adjacent to the next Each vertex used is adjacent to the next

vertex used.vertex used.• Each edge in the graph is used at most Each edge in the graph is used at most

one time.one time.• A path is written as a list of vertices.A path is written as a list of vertices.

Page 23: nossi ch 6

Example 7Example 7• Find three different Find three different

paths in the graph. paths in the graph. • Solution:Solution:

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

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

• A third path is A third path is C,E,E,AC,E,E,A• There are many other There are many other

paths.paths.

Page 24: nossi ch 6

CircuitsCircuits• A A circuitcircuit is a path is a path

that begins and that begins and ends at the same ends at the same vertex.vertex.

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

Page 25: nossi ch 6

Euler PathsEuler Paths• A path that uses every edge of a graph exactly once is called A path that uses every edge of a graph exactly once is called

an an Euler pathEuler path. (Euler is pronounced “oiler.”). (Euler is pronounced “oiler.”)• Example: The edges are numbered in the order used.Example: The edges are numbered in the order used.

Page 26: nossi ch 6

Euler CircuitsEuler Circuits• A circuit that uses every edge of a graph exactly once is A circuit that uses every edge of a graph exactly once is

called an called an Euler circuitEuler circuit..• Example: The edges are numbered in the order used.Example: The edges are numbered in the order used.

Page 27: nossi ch 6

Connected GraphsConnected Graphs• A graph is said to be A graph is said to be connectedconnected if, for if, for

every pair of vertices, there is a path that every pair of vertices, there is a path that contains them.contains them.

• If a graph is not connected, it is said to be If a graph is not connected, it is said to be disconnecteddisconnected..• An edge is called a An edge is called a bridgebridge if its removal from if its removal from

the graph would change the graph from the graph would change the graph from connected to disconnected.connected to disconnected.

Page 28: nossi ch 6

Example 8Example 8• Explain whether or not the graphs are Explain whether or not the graphs are

connected.connected.a)a)

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

Page 29: nossi ch 6

Example 8, cont’dExample 8, cont’db)b)

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

Page 30: nossi ch 6

Example 9Example 9

• Identify any bridges in the (connected) Identify any bridges in the (connected) graph. graph.

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

Page 31: nossi ch 6

Example 10Example 10• Find all components of the graph.Find all components of the graph.

• There are three components: the piece containing A, E, There are three components: the piece containing A, E, F, and G; the piece containing B and C; and the piece F, and G; the piece containing B and C; and the piece containing D.containing D.

Page 32: nossi ch 6

Degree TheoremDegree Theorem• Any graph must have an even number of Any graph must have an even number of

vertices with odd degree.vertices with odd degree.• We saw earlier that the sum of all the We saw earlier that the sum of all the

degrees in a graph is always an even degrees in a graph is always an even number, so:number, so:

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

• Vertices with odd degrees come in pairs.Vertices with odd degrees come in pairs.

Page 33: nossi ch 6

Euler’s TheoremEuler’s Theorem

• For a connected graph:For a connected graph:• If the graph has zero vertices of odd If the graph has zero vertices of odd

degree, then it has at least one degree, then it has at least one Euler circuit. Euler circuit.

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

Page 34: nossi ch 6

Euler’s Theorem cont’dEuler’s Theorem cont’d• For a connected graph:For a connected graph:

• If the graph has If the graph has exactlyexactly twotwo vertices of vertices of oddodd degree, thendegree, then

• It does It does notnot have an Euler have an Euler circuitcircuit..• It has at least one Euler It has at least one Euler pathpath..• Any Euler path starts at one of the two Any Euler path starts at one of the two

vertices of odd degree and ends at the vertices of odd degree and ends at the other.other.

Page 35: nossi ch 6

Euler’s Theorem cont’dEuler’s Theorem cont’d

• For a connected graph:For a connected graph:• If the graph has more than two If the graph has more than two

vertices of odd degree, thenvertices of odd degree, then• It does not have an Euler circuit.It does not have an Euler circuit.• It does not have an Euler path.It does not have an Euler path.

Page 36: nossi ch 6

Example 11Example 11• Does the graph have an Euler circuit, Does the graph have an Euler circuit,

Euler path, or neither?Euler path, or neither?

VertexVertex DegreeDegreeAA 44BB 44CC 22DD 44EE 22FF 22

Page 37: nossi ch 6

Example 11Example 11

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

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

Page 38: nossi ch 6

Example 11, cont’dExample 11, cont’d

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

Page 39: nossi ch 6

Fleury’s AlgorithmFleury’s Algorithm• If Euler’s Theorem indicates that there If Euler’s Theorem indicates that there isis an an

Euler circuit, Fleury’s Algorithm can be used to Euler circuit, Fleury’s Algorithm can be used to findfind the circuit. the circuit.

• The step-by-step procedure is as follows:The step-by-step procedure is as follows:1)1) Copy all the vertices, but not the edges, of the Copy all the vertices, but not the edges, of the

original graph.original graph.

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

Page 40: nossi ch 6

Fleury’s Algorithm, cont’dFleury’s Algorithm, cont’d

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

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

• Number the edges in the order they Number the edges in the order they are transferred.are transferred.

Page 41: nossi ch 6

Fleury’s Algorithm, cont’dFleury’s Algorithm, cont’d

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

5)5) When you transfer the last edge When you transfer the last edge you are done.you are done.

Page 42: nossi ch 6

Example 12Example 12Use Fleury’s Algorithm to find an Euler circuit for Use Fleury’s Algorithm to find an Euler circuit for

the graph. (See ex.6.10 pgs 350-352 in text.)the graph. (See ex.6.10 pgs 350-352 in text.)

• Possible Final Solution: Possible Final Solution:

Page 43: nossi ch 6

6.1 Initial Problem Solution6.1 Initial Problem Solution• The idea of Euler The idea of Euler

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

Page 44: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d• The vertices represent The vertices represent

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

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

Page 45: nossi ch 6

Section 6.1 AssignmentSection 6.1 Assignment Pg 353 (3, 11a,b, 17-19,25,27,39)Pg 353 (3, 11a,b, 17-19,25,27,39)

Page 46: nossi ch 6

Section 6.2Section 6.2Network ProblemsNetwork Problems

• GoalsGoals• Study weighted graphsStudy weighted graphs• Study spanning treesStudy spanning trees

• Study minimal spanning treesStudy minimal spanning trees• Use Kruskal’s algorithmUse Kruskal’s algorithm

Page 47: nossi ch 6

6.2 Initial Problem6.2 Initial ProblemHow can the walkways be How can the walkways be

constructed so that:constructed so that:

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

The total length of the The total length of the walkways is minimized.walkways is minimized.

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

Page 48: nossi ch 6

Weighted GraphsWeighted GraphsA graph in which each edge has a number associated with it is called a A graph in which each edge has a number associated with it is called a weighted graphweighted graph. . The number corresponding to an edge is called the The number corresponding to an edge is called the weightweight of the edge. of the edge.

Page 49: nossi ch 6

Example 1Example 1• Suppose Ed has:Suppose Ed has:

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

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

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

• Draw a weighted graph to represent this Draw a weighted graph to represent this situation.situation.

Page 50: nossi ch 6

Example 1, cont’dExample 1, cont’d• Solution:Solution:

• The vertices of the graph will represent Ed’s The vertices of the graph will represent Ed’s home (home (HH), his workplace (), his workplace (WW), and his health ), and his health club (club (CC).).

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

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

Page 51: nossi ch 6

Example 1, cont’dExample 1, cont’d• Solution, cont’d: One possible weighted graph Solution, cont’d: One possible weighted graph

is shown below.is shown below.

Page 52: nossi ch 6

Redundant EdgesRedundant Edges• Redundant edgesRedundant edges are are

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

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

• The edge The edge CHCH is a is a redundant edge.redundant edge.

Page 53: nossi ch 6

SubgraphsSubgraphs• A A subgraphsubgraph of a of a

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

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

Page 54: nossi ch 6

SubgraphsSubgraphs• Example: Example:

Another Another subgraph could subgraph could be created by be created by removing removing vertex vertex CC and its and its two incident two incident edges. edges.

Page 55: nossi ch 6

Example 2Example 2• A bus line goes between the cities shown in A bus line goes between the cities shown in

the table.the table.a)a) Draw a weighted graph to represent the Draw a weighted graph to represent the

situation.situation.

b)b) Find two different routes from Selma to Anniston.Find two different routes from Selma to Anniston.

Page 56: nossi ch 6

Example 2Example 2a)a) Solution: A weighted graph is shown below.Solution: A weighted graph is shown below.

Page 57: nossi ch 6

Example 2Example 2

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

Page 58: nossi ch 6

Example 2Example 2b)b) Solution, cont’d: Solution, cont’d:

Another possible Another possible route from Selma route from Selma to Anniston is to Anniston is SBASBA, with a total , with a total weight (length) of weight (length) of 160 + 62 = 222 160 + 62 = 222 miles.miles.

Page 59: nossi ch 6

TreesTrees• One way to recognize that a graph One way to recognize that a graph

contains redundant edges is to find a contains redundant edges is to find a circuit in the graph.circuit in the graph.

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

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

Page 60: nossi ch 6

Trees, cont’dTrees, cont’d• The following figure gives examples of graphs The following figure gives examples of graphs

that are trees and a graph that is not a tree. that are trees and a graph that is not a tree.

Page 61: nossi ch 6

Example 3Example 3• This graph is not a tree because it This graph is not a tree because it

contains several circuits. contains several circuits. • Find a subgraph that is a tree.Find a subgraph that is a tree.

Page 62: nossi ch 6

Example 3Example 3• Solution: Circuits are highlighted and Solution: Circuits are highlighted and

edges are removed until the remaining edges are removed until the remaining subgraph has no circuits left. subgraph has no circuits left.

Page 63: nossi ch 6

Spanning TreesSpanning Trees

• A A spanning treespanning tree is a subgraph that: is a subgraph that: • Contains all the original vertices of the Contains all the original vertices of the

graph.graph.• Is connected.Is connected.• Contains no circuits.Contains no circuits.

Page 64: nossi ch 6

Spanning TreesSpanning Trees• Every connected graph has at least one Every connected graph has at least one

spanning tree.spanning tree.• An example of a spanning tree is shown An example of a spanning tree is shown

below.below.

Page 65: nossi ch 6

Minimal Spanning TreesMinimal Spanning Trees• A spanning tree with the smallest A spanning tree with the smallest

possible total weight is called a possible total weight is called a minimal spanning treeminimal spanning tree..

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

Page 66: nossi ch 6

Minimal Spanning TreesMinimal Spanning Trees• For the connected, weighted graph shown For the connected, weighted graph shown

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

Page 67: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm• A method known as Kruskal’s A method known as Kruskal’s

algorithm can be used to find a algorithm can be used to find a minimal spanning tree of a minimal spanning tree of a connected, weighted graph.connected, weighted graph.

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

Page 68: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm• Acceptable edgesAcceptable edges are are

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

Page 69: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm• Acceptable edgesAcceptable edges are are

• Edges that connect two components of Edges that connect two components of the subgraph. the subgraph.

Page 70: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm• Acceptable edgesAcceptable edges are are

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

Page 71: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm• Unacceptable edgesUnacceptable edges are are

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

Page 72: nossi ch 6

Kruskal’s AlgorithmKruskal’s Algorithm1)1) Consider only the vertices of the graph.Consider only the vertices of the graph.2)2) Add the edge with the smallest weight.Add the edge with the smallest weight.3)3) Add the acceptable edge with the smallest Add the acceptable edge with the smallest

weight.weight.4)4) Determine whether all vertices are Determine whether all vertices are

connected by a path.connected by a path.a)a) If so, you have a minimal spanning tree.If so, you have a minimal spanning tree.

b)b) If not, repeat Step 3. If not, repeat Step 3.

Page 73: nossi ch 6

Example 4Example 4

• Construct a Construct a minimal minimal spanning tree for spanning tree for the weighted the weighted graph.graph.

Page 74: nossi ch 6

Example 4Example 4

• Solution:Solution:• Start with the 4 vertices.Start with the 4 vertices.• Add the edge with the smallest weight.Add the edge with the smallest weight.

Page 75: nossi ch 6

Example 4Example 4• Solution, cont’d:Solution, cont’d:

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

• Select the edge Select the edge with weight 2.6.with weight 2.6.

Page 76: nossi ch 6

Example 4Example 4• Solution, cont’d:Solution, cont’d:

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

• Select the edge Select the edge with weight 3.7.with weight 3.7.

Page 77: nossi ch 6

Example 4Example 4• Solution, cont’d:Solution, cont’d:

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

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

Page 78: nossi ch 6

6.2 Initial Problem Solution6.2 Initial Problem Solution• How can a college How can a college

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

Page 79: nossi ch 6

Initial Problem SolutionInitial Problem Solution• Create a weighted Create a weighted

graph to represent graph to represent the buildings and the buildings and existing sidewalks existing sidewalks on the campus.on the campus.

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

Page 80: nossi ch 6

Initial Problem SolutionInitial Problem Solution

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

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

Page 81: nossi ch 6

Initial Problem SolutionInitial Problem Solution• Under this plan, students Under this plan, students

can get from any building can get from any building to any other building to any other building without going outside, without going outside, although they may have although they may have to walk farther inside.to walk farther inside.

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

Page 82: nossi ch 6

Section 6.2 AssignmentSection 6.2 Assignment Pg 370 (5 a,b and list 2 different Pg 370 (5 a,b and list 2 different

routes from St Louis (StL) to routes from St Louis (StL) to Cleveland and the total distance of Cleveland and the total distance of each route, 9,11,27,29)each route, 9,11,27,29)

Page 83: nossi ch 6

Section 6.3Section 6.3Traveling-Salesperson ProblemTraveling-Salesperson Problem

• GoalsGoals• Study Hamiltonian circuitsStudy Hamiltonian circuits• Study the Traveling-Salesperson Study the Traveling-Salesperson

ProblemProblem• Use the Brute-Force AlgorithmUse the Brute-Force Algorithm• Use the Nearest-Neighbor AlgorithmUse the Nearest-Neighbor Algorithm• Use the Cheapest-Link AlgorithmUse the Cheapest-Link Algorithm

Page 84: nossi ch 6

6.3 Initial Problem6.3 Initial Problem

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

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

Page 85: nossi ch 6

Hamiltonian CircuitsHamiltonian Circuits

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

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

Page 86: nossi ch 6

Example 1Example 1

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

• The path can be The path can be written written AGFEDBCAGFEDBC or or CBDEFGA.CBDEFGA.

Page 87: nossi ch 6

Example 2Example 2

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

• The circuit, starting at The circuit, starting at AA, can be written , can be written AGFEDCBAAGFEDCBA

Page 88: nossi ch 6

Hamiltonian Circuits, cont’dHamiltonian Circuits, cont’d

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

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

Page 89: nossi ch 6

Example 3Example 3

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

Page 90: nossi ch 6

Example 3Example 3a)a) Solution: The path Solution: The path ABCDABCD is a Hamiltonian path. is a Hamiltonian path.

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

• Other Hamiltonian paths and circuits are possible.Other Hamiltonian paths and circuits are possible.

Page 91: nossi ch 6

Example 3, cont’dExample 3, cont’db)b) Solution: The path Solution: The path ABCDABCD is a Hamiltonian is a Hamiltonian

path.path.• There is no Hamiltonian circuit.There is no Hamiltonian circuit.

Page 92: nossi ch 6

Example 3, cont’dExample 3, cont’dc)c) There is no Hamiltonian path.There is no Hamiltonian path.

• Any Hamiltonian path must start at either Any Hamiltonian path must start at either AA or or FF..• Any path that starts at Any path that starts at AA will leave out either will leave out either CC, , DD, or , or

F.F.• Any path that starts at Any path that starts at FF will leave out either will leave out either CC, , DD, or , or

A.A.

Page 93: nossi ch 6

Complete GraphsComplete Graphs

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

Page 94: nossi ch 6

Example 4Example 4

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

Page 95: nossi ch 6

Example 4, cont’dExample 4, cont’d

a)a) Solution: Check each pair of vertices. Solution: Check each pair of vertices. • There is exactly one edge between each pair There is exactly one edge between each pair

of vertices, so the graph is complete.of vertices, so the graph is complete.

Page 96: nossi ch 6

Example 4, cont’dExample 4, cont’d

b)b) Solution: Check each pair of vertices. Solution: Check each pair of vertices. • There is no edge from There is no edge from AA to to CC, for example. , for example.

The graph is not complete.The graph is not complete.

Page 97: nossi ch 6

Example 4, cont’dExample 4, cont’d

c)c) Solution: Check each pair of vertices. Solution: Check each pair of vertices. • There are two edges from There are two edges from AA to to FF, for , for

example. The graph is not complete.example. The graph is not complete.

Page 98: nossi ch 6

Complete GraphsComplete Graphs• In general, a graph may or may not have a In general, a graph may or may not have a

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

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

Hamiltonian path.Hamiltonian path.• Adding the starting vertex to the end of the list Adding the starting vertex to the end of the list

describing the path will create a Hamiltonian describing the path will create a Hamiltonian circuit. circuit.

Page 99: nossi ch 6

Example 6Example 6

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

Page 100: nossi ch 6

Example 6, cont’dExample 6, cont’d• Solution:Solution:

Page 101: nossi ch 6

Example 6, cont’dExample 6, cont’d• Note that the complete graph in the Note that the complete graph in the

previous example had 3 vertices and 6 previous example had 3 vertices and 6 different Hamiltonian circuits.different Hamiltonian circuits.

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

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

Page 102: nossi ch 6

Theorem on Complete GraphsTheorem on Complete Graphs

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

nn! = ! = nn((nn – 1)( – 1)(nn – 2)( – 2)(nn – 3)…(1). – 3)…(1).• The symbol The symbol nn! is read “n factorial”.! is read “n factorial”.

Page 103: nossi ch 6

Question:Question:

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

a. 81a. 81b. 40,320b. 40,320c. 362,880c. 362,880d. 3,265,920d. 3,265,920

Page 104: nossi ch 6

Question:Question:

How many possible Hamiltonian circuits How many possible Hamiltonian circuits exist in a complete graph with 9 vertices? exist in a complete graph with 9 vertices? 9*8*7*6*5*4*3*2*1 = 362,8809*8*7*6*5*4*3*2*1 = 362,880

a. 81a. 81b. 40,320b. 40,320c. 362,880 correct answerc. 362,880 correct answerd. 3,265,920d. 3,265,920

Page 105: nossi ch 6

Traveling-Salesperson ProblemTraveling-Salesperson Problem• A salesperson who must visit various A salesperson who must visit various

cities and then return home wants to cities and then return home wants to minimize the cost (measured in distance, minimize the cost (measured in distance, time, or money) of his or her trip.time, or money) of his or her trip.

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

Page 106: nossi ch 6

Complete Weighted GraphsComplete Weighted Graphs

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

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

Page 107: nossi ch 6

Question:Question:

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

a. 26a. 26b. 14b. 14c. 24c. 24d. 41d. 41

Page 108: nossi ch 6

Question:Question:

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

a. 26a. 2610+16=2610+16=26b. 14b. 14c. 24c. 24d. 41d. 41

Page 109: nossi ch 6

Example 7Example 7

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

• Find the path of Find the path of least cost. least cost.

Page 110: nossi ch 6

Example 7, cont’dExample 7, cont’d• Solution: The graph Solution: The graph

has 4 vertices, so has 4 vertices, so there are 4! = 24 there are 4! = 24 different Hamiltonian different Hamiltonian paths.paths.

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

Page 111: nossi ch 6

Example 7, cont’dExample 7, cont’d

Page 112: nossi ch 6

Example 7, cont’dExample 7, cont’d

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

• CDABCDAB• BADCBADC

Page 113: nossi ch 6

Example 7, cont’dExample 7, cont’d• List all possible List all possible

Hamiltonian Hamiltonian circuits that start circuits that start and end at vertex and end at vertex A.A.

• Find the circuit at Find the circuit at AA of least cost. of least cost.

Page 114: nossi ch 6

Example 7, cont’dExample 7, cont’d• Solution:Solution:

Page 115: nossi ch 6

Example 7, cont’dExample 7, cont’d• Solution, cont’d: Solution, cont’d:

There are 2 least-There are 2 least-cost Hamiltonian cost Hamiltonian circuits with a cost of circuits with a cost of 74.74.

• ABCDEAABCDEA• AEDCBAAEDCBA

• These 2 circuits are These 2 circuits are mirror imagesmirror images of each of each other.other.

Page 116: nossi ch 6

Traveling-Salesperson, cont’dTraveling-Salesperson, cont’d

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

• List all possible Hamiltonian circuits.List all possible Hamiltonian circuits.• Calculate the cost of each circuit.Calculate the cost of each circuit.• Find the 2 mirror image circuits of least cost.Find the 2 mirror image circuits of least cost.

• This method is very time-consuming.This method is very time-consuming.

Page 117: nossi ch 6

Traveling-Salesperson, cont’dTraveling-Salesperson, cont’d• Instead of the Brute-Force Algorithm, faster Instead of the Brute-Force Algorithm, faster

approximation algorithms are typically used.approximation algorithms are typically used.• An An approximation algorithmapproximation algorithm finds a Hamiltonian finds a Hamiltonian

circuit that is either the least-cost circuit or is circuit that is either the least-cost circuit or is one that is not much more costly than the least-one that is not much more costly than the least-cost circuit.cost circuit.

• The Nearest-Neighbor AlgorithmThe Nearest-Neighbor Algorithm• The Cheapest-Link AlgorithmThe Cheapest-Link Algorithm(We will not study these other than the names.)(We will not study these other than the names.)

Page 118: nossi ch 6

6.3 Initial Problem Solution6.3 Initial Problem Solution• An author needs to find a route that will An author needs to find a route that will

minimize the total distance she must drive minimize the total distance she must drive between the cities shown below. between the cities shown below.

Page 119: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

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

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

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

Page 120: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

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

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

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

Page 121: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d• Using the algorithm, add acceptable edges Using the algorithm, add acceptable edges

one at a time.one at a time.• The first 7 edges added are shown below. The first 7 edges added are shown below.

Page 122: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d• The cheapest acceptable edge at this point is The cheapest acceptable edge at this point is

the route between Charlotte and Orlando.the route between Charlotte and Orlando.• After that, the route from New Orleans to After that, the route from New Orleans to

Orlando must be added to complete the circuit. Orlando must be added to complete the circuit.

Page 123: nossi ch 6

Initial Problem Solution, cont’dInitial Problem Solution, cont’d• The approximate least-cost Hamiltonian circuit is The approximate least-cost Hamiltonian circuit is

shown below.shown below.• The total cost of the circuit is 2462, so the author The total cost of the circuit is 2462, so the author

will drive 2462 miles if she takes this route on will drive 2462 miles if she takes this route on her trip. her trip.

Page 124: nossi ch 6

A fun website with Traveling A fun website with Traveling Salesman Problem (TSP) Salesman Problem (TSP)

Artwork:Artwork:http://www.oberlin.edu/math/fachttp://www.oberlin.edu/math/faculty/bosch/tspart-page.htmlulty/bosch/tspart-page.html

Page 125: nossi ch 6

Section 6.3 AssignmentSection 6.3 Assignment Pg 396 (1,5,7,17,19,25, 27) For Pg 396 (1,5,7,17,19,25, 27) For

problems 25 and 27 you may look at problems 25 and 27 you may look at the charts in the back of the book the charts in the back of the book rather than making one yourself. rather than making one yourself. Then, write a sentence explaining Then, write a sentence explaining your choice of an answer and how your choice of an answer and how the chart helps you make the choice the chart helps you make the choice you did.)you did.)

Page 126: nossi ch 6

Chapter 6 Assignments

• Pg 353 (3, 11a,b, 17-19,25,27,39)

• Pg 370 (5 a,b and list 2 different routes from St Louis (StL) to Cleveland and the total distance of each route, 9,11,27,29)

• Pg 396 (1,5,7,17,19,25, 27) For problems 25 and 27 you may look at the charts in the back of the book rather than making one yourself. Then, write a sentence explaining your choice of an answer and how the chart helps you make the choice you did.)