Further Mathematics 2016 Module 2: NETWORKS AND DECISION MATHEMATICS Chapter 9 Undirected Graphs and Networks Key knowledge the conventions, terminology, properties and types of graphs; edge, face, loop, vertex, the degree of a vertex, isomorphic and connected graphs, and the adjacency matrix, and Euler s formula for planar graphs and its application the exploring and travelling problem, walks, trails, paths, Eulerian trails and circuits, and Hamiltonian cycles the minimum connector problem, trees, spanning trees and minimum spanning trees the shortest path problem and Dijkstra s algorithm Key skills construct graphs, digraphs and networks and their matrix equivalents to model and analyse practical situations recognise that a problem is an example of the exploring and travelling problem and to solve it by utilising the concepts of walks, trails, paths, Eulerian trails and circuits, and Hamiltonian paths and cycles recognise that a problem is an example of the minimum connector problem and solve it by utilising the properties of trees, spanning trees and by determining a minimum spanning tree by inspection or using Prim s algorithm for larger scale problems recognise that a problem is an example of the shortest path problem and solve it by inspection or using Dijkstra s algorithm for larger scale problems Chapter Sections Questions to be completed 9.2 Basic concepts 2, 4, 6, 8, 10, 12, 14, 15ab, 16a, 17, 20, 21, 22 9.3 Planar graphs and Euler s formula 1, 2, 4, 5, 6, 9ac, 10, 12, 14, 15, 17,20 9.4 Walks, trails, paths, cycles and circuits 1, 2, 3, 4, 5, 6, 8, 9, 13, 17, 18, 19, 20, 21 9.5 Trees and their application 1, 2, 7, 8, 10, 13, 15, 16, 17, 18, 21ac, 22a, 23, 24 More resources available at http://pcsfurthermaths.weebly.com
Networks 1 PCS 2016 Table of Contents Chapter 9 Undirected Graphs and Networks. 1 Key knowledge... 1 Key skills... 1 9.2 Basic concepts of a network... 3 Definition of a network... 3 Worked Example 1... 3 The degree of a vertex... 3 Worked Example 2... 4 Representation of networks... 4 Worked Example 3... 4 Worked Example 4... 5 Matrix representation of networks... 5 Worked Example 5... 5 9.3 Planar, graphs and Euler s formula... 6 Degenerate graph... 6 Complete graph... 6 Planar graphs... 6 The regions of a planar graph... 7 Converting a non- planar graph... 7 Worked Example 6... 7 Worked Example 7... 7 Converting three- dimensional solids to planar graphs... 8 Worked Example 8... 8 Euler s formula... 8 Worked Example 9... 8 9.4 Walks, trails, paths, cycles and circuits... 9 Walks... 9 Connected graphs... 9 Euler trails... 9 Worked Example 10... 9 Euler circuits... 10 Worked Example 11... 10 An Euler circuit algorithm... 10 Worked Example 12... 11 Path and cycles... 11 Worked Example 13... 12 Hamiltonian cycles... 12 Worked Example 14... 12 9.5 Trees and their application... 12 Graphs and subgraphs... 12 Trees... 13 Worked Example 15... 13 Shortest paths... 13 Worked Example 16... 13 A shortest path algorithm... 13 Worked Example 17... 14 Spanning trees... 14 Minimum spanning tree and Prim s algorithm... 15 Prim s algorithm... 15 Worked Example 18... 15 Maximum spanning tree... 15 Worked Example 19... 15 Dijkstra s algorithm... 16 Dijkstra s algorithm Example 1... 16 Dijkstra s algorithm Example 2... 18 Worked Example 20 (STUDENT PRACTICE)... 19 Additional Dijkstra s Algorithm Questions... 20 Page 2 of 20
9.2 Basic concepts of a network Matrices Notes PCS 2016 Definition of a network The telephone system, your family tree and the internet are all considered to be networks (graphs). The simplest definition of a network is: Consider the following diagram. It is perhaps the simplest network. It consists of two vertices (singular vertex) (circles labelled 1 and 2) and one connection between them. This connection is called an edge. Worked Example 1 Count the number of vertices and edges in the network shown. There are two things worth noting about this classification of a network: 1. the vertices and edges can be labelled in any order, using any suitable labelling system. 2. vertices may have different number of edges connected to them. The degree of a vertex Each vertex may have a number of edges connecting it with the rest of the network. This number is called the degree. A vertex with degree 0 is not connected to any other vertex, and is called an isolated vertex. If two (or more) edges connect the same pair of vertices they are called parallel edges (or multiple edges) and all count towards the degree. If there is only one connection between two vertices, the connection is called a simple, or single, connection. Page 3 of 20
Worked Example 2 Determine the degree of each vertex in the figure shown. Networks 1 PCS 2016 Representation of networks So far we have seen graphical representation of networks. Two other ways of representing networks are: 1. labelling the vertices and labelling the edges according to their vertices 2. matrix representation Worked Example 3 Label the vertices and edges for the figure shown, as in Worked example 2 Page 4 of 20
Worked Example 4 Construct a graph from the following list of vertices and edges. V = {A, B, C, D, E} E = {(A, B), (A, C), (A, D), (B, C), (B, D), (B, D), (C, E), (D, E), (E, E)} Matrices Notes PCS 2016 There may be other geometric configurations which can be drawn from the same vertex and edge list, but they isomorphic (or equivalent) to this one. Matrix representation of networks A method of representing a network is through the use of a matrix. Worked Example 5 Represent the network shown as a matrix In a matrix representation 1. the sum of a row (or column) gives a degree of that vertex, except where a loop is present (shown as a 1 in the leading diagonal), add 1 to the sum of the row or column. 2. if an entire row or its corresponding column has only s then that vertex is isolated 3. the matrix is diagonally symmetric. Page 5 of 20
9.3 Planar, graphs and Euler s formula Networks 1 PCS 2016 A planar graph is a special kind of network or graph. The additional properties of planar graphs will allow us to map two- dimensional and even three- dimensional objects into graphs. Degenerate graph A graph with no edges is called a degenerate graph (or null graph). Complete graph A graph were all vertices are directly connected to all other vertices without parallel edges or loops is called a complete graph. The figure on the left is a degenerate; the one on the right is complete. How many edges would there be in a complete graph of 6 vertices? Planar graphs Consider the following graphs. Figure a is a planar graph because none of the paths {A, B, C, D, E, F} cross each other. Figure b is apparently not a planar graph because the path (A, D) crosses the path (B, C). Is figure c a planar graph? Page 6 of 20
The regions of a planar graph Matrices Notes PCS 2016 The above graph can be divided into three regions (faces): region I, region II and region III. Region III is infinite as it continues beyond the bounds of the diagram. Region I and region II have a finite area. Converting a non- planar graph Although it may appear that a graph is not planar, by modifying the graph it may become clearly planar. Two method that you could use are: 1. Move the edges 2. Move the vertices Worked Example 6 Convert the graph below to a planar graph. Indicate the faces of the planar graph. The degree of each face is the number of edges defining that region. Worked Example 7 Find the degree of each face of the graph shown in the figure. Page 7 of 20
Converting three- dimensional solids to planar graphs Worked Example 8 The figure shows a cube with vertices, V = {A, B, C, D, E, F, G, H}. Convert this to a planar graph. Networks 1 PCS 2016 Euler s formula The relationship that links vertices, edges and faces of a planar graph is know as Euler s formula. Worked Example 9 Verify Euler s formula for the cube of the last figure in Worked example 8. Note that the cube is a form of prism and all prisms can be converted to planar graphs using the technique of one face collapsing into another. Page 8 of 20
Matrices Notes PCS 2016 9.4 Walks, trails, paths, cycles and circuits Walks A walk is a sequence of edges that takes you along some or all of the edges or through some or all of the vertices. There are different ways of naming a walk. For example, consider the figure shown on the right, travelling from node 1 to node 3. A walk could be specified via node 2, namely A- B or by specifying the vertices 1-2- 3. Alternatively, you could the walk C- E- D, or C- F. Each of these routes is a walk. Connected graphs The figure on the left, there is no walk between vertices 1 and 2, nor between vertices 3 and 4, so it is not a connected graph. However, if we add a single edge, as in the figure on the right, between vertices 1 and 2, the entire graph becomes connected. Euler trails A trail is a walk in which no edges are repeated. 1. For an Euler trail to exist, all vertices must be of an even degree or there must be exactly two vertices of odd degree. 2. If the degrees of all the vertices are even numbers, start with any vertex. In this case the starting vertex and ending vertex are the same. 3. If there are two vertices whose degree is an odd number used either as a starting point. The other vertex of odd degree must be the ending point. Worked Example 10 Using the figure, identify an Euler trail. Page 9 of 20
Euler circuits Networks 1 PCS 2016 In an Euler circuit all the vertices must be of an even degree. If there is an odd degree vertex, an Euler circuit is not possible. Worked Example 11 Find an Euler circuit for the planar graph shown. An Euler circuit algorithm For some networks it may be difficult to determine an Euler circuit. Here is an algorithm (a process) that guarantees an Euler circuit. Consider a network where all vertices ar3e of even degree. Let V = {1, 2, 3, } be the list of vertices. Step 1. Choose a starting vertex from the list V. Call this vertex A. Step 2. Step 3. From vertex A, find the smallest possible path which returns to vertex A. This is a sub- circuit of the original network. Let S be the list of vertices in this sub- circuit. For each vertex in S, choose a single vertex in turn as the starting vertex of a different sub- circuit. It should be as small as possible, and not use any previously used edge. Step 4. For each of these new sub- circuits (if there are any), add any new vertices to the list in S. Step 5. Repeat steps 3 and 4 until there are no more new vertices, edges or sub- circuits left; that is, the list S and V are the same. Step 6. Join the sub- circuits at their intersection points. Page 10 of 20
Worked Example 12 Find one possible Euler circuit for the network shown using the Euler circuit algorithm. Matrices Notes PCS 2016 Step Instruction Example 1 Choose a starting vertex, and find its smallest sub- circuit. 2 Create the list S from the first sub- circuit. Find new sub- circuit, not using any edges already used. (step 3) 3 Add to the list S. (step 4) 4 Find the new sub- circuit. (step 3) 5 Add to list S. Check that all vertices are in the list. (step 4) 6 Form the Euler trail, starting with the first sub- circuit, and proceeding through all the other sub- circuit at their intersection. (step 6) 7 List the Euler circuit. Path and cycles In Euler trails and circuits each edge was used exactly once, while vertices could be re- used. Now, consider the case where it is desirable to use each vertex exactly once. Please note: Not all edges need to be used. There can only be up to 2 vertices with degree 1 (dead ends). These would be the start and/or the finishing vertices. Page 11 of 20
Worked Example 13 Determine a Hamiltonian path in the planar graph shown. Networks 1 PCS 2016 Hamiltonian cycles When determining a Hamiltonian path, sometimes it is desirable to start and finish with the same vertex. For example, a travelling salesperson may live in one of the towns (vertices) she visits and would like to start and finish at her home town after visiting all the other towns once. This is similar to the concept of an Euler circuit. Worked Example 14 Determine a Hamiltonian cycle in the planar graph shown. 9.5 Trees and their application Graphs and subgraphs A network can also be called a graph. In practice, a graph should have at least 2 vertices and 1 edge. All or part of this graph can be considered as a subgraph. For example, in the figure, the entire network can be considered as a graph, while the path in pink can be considered a subgraph. Another subgraph could be defined by the path 1 2 3 4 1. 1 A minimum subgraph could be defined by the path 1 2. Often the edges can be assigned some quantity such as distance or cost. If a graph contains quantities, it is then called a weighted graph. Page 12 of 20
Trees Matrices Notes PCS 2016 Worked Example 15 Determine whether each of the figures is a tree, and if not, explain why not. a. b. c. d. The advantage of trees within a network is that the tree could determine an efficient connection between vertices in the sense that there is a minimum distance, cost or time. Shortest paths Sometimes it may be useful to determine the shortest path between 2 selected vertices of a graph. Worked Example 16 Determine the shortest path between nodes A and F in the figure shown. Possible trees between A- F Distance travelled A shortest path algorithm Sometimes it can be difficult to list all the paths between the starting and ending vertex. Here is an algorithm that guarantees the shortest path. Step 1. From the starting vertex, find the shortest path to all other directly connected vertices. Include all such vertices, including the starting one in the list S = {A, B, } Step 2. Choose a vertex directly connected to those in S and find the shortest path to the staring vertex. Step 3. Add the new vertex, V, to the list S. Step 4. Repeat steps 2 and 3 until all vertices are in S. Find the shortest path to the vertex you want. Page 13 of 20
Worked Example 17 Find the shortest path from vertex 1 to vertex 9. Networks 1 PCS 2016 1. From 1 find shortest path to each vertices directly connected to it From To Via Distance Shortest path to 2. Determine set of vertices in S 3. Choose a vertex directly connected to one in S Select vertex 5 4. Add new vertex to the S list 5. Choose a vertex directly connected to one in S Select vertex 6 6. Add new vertex to the S list 7. Choose a vertex directly connected to one in S Select vertex 7 8. Add new vertex to the S list 9. Choose a vertex directly connected to one in S Select vertex 8 10. Add new vertex to the S list 11. Choose last vertex 9 Select vertex 9 12. Add new vertex to the S list 13. Stop once all vertices are listed Spanning trees Spanning trees include all vertices. Consider the following network. If the vertices are a location/town /house etc. and the distances are shown on the edges. Then the figures below show the possible trees. Page 14 of 20
Matrices Notes PCS 2016 Note that each of these trees included all the vertices of the original network. These trees are called spanning trees because of this property. Minimum spanning tree and Prim s algorithm Minimum spanning trees connect all vertices with the smallest distance. Prim s algorithm Step 1. Step 2. Step 3. Step 4. Worked Example 18 Choose the edge with the minimum value. If 2 or more edges are the smallest, choose any of these. Inspect the next edges connected to the two vertices on the ends of your original edge. Choose the smallest edge. Inspect all included vertices so far and choose the smallest edge leading from any vertex. Repeat until all vertices are included. Determine the minimum spanning tree for the network representing footpaths in a school campus. Maximum spanning tree Worked Example 19 Maximum spanning trees connect all vertices with the largest distance. The figure shown represents a telephone network connecting 6 towns, A, B,, F. The numbered edges represent the capacity of the telephone connection between the towns connected, that is, the maximum number of calls that can be made at the same time along that edge. A telephone engineer wishes to determine the maximum capacity of the system in terms of a tree connecting all the towns so that calls can be routed along that tree. Page 15 of 20
Networks 1 PCS 2016 Dijkstra s algorithm Another method for determining the shortest path between a given vertex and each of the other vertices is Dijkstra s algorithm. Dijkstra s algorithm Example 1 The weights in the graph opposite show the distances, in kilometres, by road between the towns. The algorithm will be used to find the shortest path between St Andrews (S ) and Toolangi (T ). Step 1: Create a table 1. Write the starting vertex as the first row vertex. 2. Write the other vertices in the network as column vertices (the order is unimportant). S K Y T H Step 2: Complete the first row Look at the graph to find the distance from the starting vertex (the row vertex in this example S) to the vertices that are directly connected to it (a column vertex). 1. Write down the distance from the row vertex to a column vertex, directly underneath the column vertex as shown. 2. If a vertex is not directly connected to the starting vertex, mark a cross (x). 3. Look for the smallest number in the first row and draw a box around it. If there are two or more the same, any one can be chosen. 4. The column vertex for this boxed number becomes the next row vertex. K Y T H S 13 15 X X K Y T H S 13 15 X X K Step 3: Complete the further rows 1. Copy all boxed numbers into the next row. K Y T H S 13 15 X X K 13 Page 16 of 20
2. For the remaining columns, add the boxed numbers for the row vertex to the distance from the row vertex to the column vertex. a) If the value is greater than the value above it, ignore the new value and copy the existing one. b) If the value is less than or equal to the value above it in the column, write down new value. c) If the row vertex is not directly connected to the column vertex, mark with a cross (x). 3. Look for the smallest unboxed number in the row and draw a box around it. 4. The column vertex for this new boxed number becomes the next row vertex. 5. Repeat step 3 until the destination vertex value has a boxed around it. Matrices Notes PCS 2016 K Y T H S 13 15 X X K 13 15 28 X K Y T H S 13 15 X X K 13 15 28 X Y K Y T H S 13 15 X X K 13 15 28 X Y 13 15 28 29 Step 4: Backtrack to identify the shortest path and its length 1. Start at the box value for the destination vertex. This is the length of the shortest path from the starting vertex to the destination vertex. 2. Draw a line up the column to the last number that is the same as the box number (it does not have to have a box around it). 3. Look at the row vertex for this number and draw a horizontal line to the column for this vertex. 4. Repeat until the starting vertex is reached. 5. The horizontal lines in the table indicate the shortest path. K Y T H S 13 15 X X K 13 15 28 X Y 13 15 28 29 Page 17 of 20
Dijkstra s algorithm Example 2 Find the shortest path from A to F in the weighted graph shown using Dijkstra s algorithm Networks 1 PCS 2016 Step 1: Create a table 1. Write the starting vertex as the first row vertex. 2. Write the other vertices in the network as column vertices (the order is unimportant). Step 2: Complete the first row Look at the graph to find the distance from the starting vertex (the row vertex in this example S) to the vertices that are directly connected to it (a column vertex). 1. Write down the distance from the row vertex to a column vertex, directly underneath the column vertex as shown. 2. If a vertex is not directly connected to the starting vertex, mark a cross (x). 3. Look for the smallest number in the first row and draw a box around it. If there are two or more the same, any one can be chosen. 4. The column vertex for this boxed number becomes the next row vertex. Step 3: Complete the further rows 1. Copy all boxed numbers into the next row. 2. For the remaining columns, add the boxed numbers for the row vertex to the distance from the row vertex to the column vertex. a) If the value is greater than the value above it, ignore the new value and copy the existing one. b) If the value is less than or equal to the value above it in the column, write down new value. c) If the row vertex is not directly connected to the column vertex, mark with a cross (x). 3. Look for the smallest unboxed number in the row and draw a box around it. 4. The column vertex for this new boxed number becomes the next row vertex. 5. Repeat step 3 until the destination vertex value has a boxed around it. A A A A A A B C D E B C D E B C D E B C D E B C D E B C D E Page 18 of 20
Step 4: Backtrack to identify the shortest path and its length 1. Start at the box value for the destination vertex. This is the length of the shortest path from the starting vertex to the destination vertex. 2. Draw a line up the column to the last number that is the same as the box number (it does not have to have a box around it). 3. Look at the row vertex for this number and draw a horizontal line to the column for this vertex. 4. Repeat until the starting vertex is reached. 5. The horizontal lines in the table indicate the shortest path. A Matrices Notes PCS 2016 B C D E Worked Example 20 (STUDENT PRACTICE) Determine the shortest path from A to E, where the distance are in kilometres, by using Dijkstra s algorithm in tabular form. Page 19 of 20
Additional Dijkstra s Algorithm Questions Networks 1 PCS 2016 Page 20 of 20