Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved Chapter 15: Graph Theory 15.1 15.2 15.3 15.4 Basic Concepts Euler Circuits Hamilton Circuits and Algorithms Trees and Minimum Spanning Trees 15-4-2 © 2008 Pearson Addison-Wesley. All rights reserved Chapter 1 Section 15-4 Trees and Minimum Spanning Trees 15-4-3 © 2008 Pearson Addison-Wesley. All rights reserved Trees and Minimum Spanning Trees • • • • • Connected Graphs and Trees Spanning Trees Minimum Spanning Trees Kruskal’s Algorithm Number of Vertices and Edges 15-4-4 © 2008 Pearson Addison-Wesley. All rights reserved Trees In the previous two sections, we looked at graphs with special kinds of circuits, In this section we examine graphs (called trees) that have no circuits. 15-4-5 © 2008 Pearson Addison-Wesley. All rights reserved Connected Graph A connected graph is one in which there is at least one path between each pair of vertices. 15-4-6 © 2008 Pearson Addison-Wesley. All rights reserved Example: Connected Graph Below is an example of a connected graph. 15-4-7 © 2008 Pearson Addison-Wesley. All rights reserved Tree We call a graph a tree if the graph is connected and contains no circuits. 15-4-8 © 2008 Pearson Addison-Wesley. All rights reserved Example: Trees Each of the graphs below is a tree. 15-4-9 © 2008 Pearson Addison-Wesley. All rights reserved Example: Trees Neither of the graphs below is a tree. Not connected Has a circuit 15-4-10 © 2008 Pearson Addison-Wesley. All rights reserved Unique Path Property of Trees In a tree there is always exactly one path from each vertex in the graph to any other vertex in the graph. 15-4-11 © 2008 Pearson Addison-Wesley. All rights reserved Spanning Tree A spanning tree for a graph is a subgraph that includes every vertex of the original, and is a tree. 15-4-12 © 2008 Pearson Addison-Wesley. All rights reserved Example: Finding a Spanning Tree Find a spanning tree for the graph below. Solution We must break two circuits by removing a single edge from each. One of several possible ways to do this is shown. 15-4-13 © 2008 Pearson Addison-Wesley. All rights reserved Minimum Spanning Tree A spanning tree that has total minimum total weight is called a minimum spanning tree for the graph. 15-4-14 © 2008 Pearson Addison-Wesley. All rights reserved Kruskal’s Algorithm for Finding a Minimum Spanning Tree Choose edges for the spanning tree as follows. Step 1: First edge: choose any edge with the minimum weight. Step 2: Next edge: choose any edge with minimum weight from those not yet selected. (The subgraph can look disconnected at this stage.) 15-4-15 © 2008 Pearson Addison-Wesley. All rights reserved Kruskal’s Algorithm for Finding a Minimum Spanning Tree Step 3: Continue to choose edges of minimum weight from those not yet selected, except do not select any edge that creates a circuit in the subgraph. Step 4: Repeat step 3 until the subgraph connects all vertices of the original graph. 15-4-16 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Use Kruskal’s algorithm to find a minimum spanning tree for the graph. 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-17 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Solution First, choose ED (the smallest weight). 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-18 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Solution Now choose BF (the smallest remaining weight). 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-19 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Solution Now CD and then BD. 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-20 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Solution Note EF is the smallest remaining, but that would create a circuit. Choose AE and we are done. 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-21 © 2008 Pearson Addison-Wesley. All rights reserved Example: Kruskal’s Algorithm Solution The total weight of the tree is 16.5. 1 E 7 D A 10 7.5 1.5 B 4.5 F 9.5 3 4 C 8 15-4-22 © 2008 Pearson Addison-Wesley. All rights reserved Number of Vertices If a graph is a tree, then the number of edges in the graph is one less than the number of vertices. A tree with n vertices has n – 1 edges. 15-4-23 © 2008 Pearson Addison-Wesley. All rights reserved Example: Vertex/Edge Relation A molecule of a chemical compound contains 54 atoms and it has a tree-like structure. How many chemical bonds are there in the molecule? Solution If the atoms are like the vertices of a tree, the bonds are like the edges. This tree has 54 vertices, so the number of bonds (edges) must be 54 – 1 = 53. 15-4-24 © 2008 Pearson Addison-Wesley. All rights reserved