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-3-2 © 2008 Pearson Addison-Wesley. All rights reserved Chapter 1 Section 15-3 Hamilton Circuits and Algorithms 15-3-3 © 2008 Pearson Addison-Wesley. All rights reserved Hamilton Circuits and Algorithms • • • • Hamilton Circuits Minimum Hamilton Circuits Brute Force Algorithm Nearest Neighbor Algorithm 15-3-4 © 2008 Pearson Addison-Wesley. All rights reserved Hamilton Circuit A Hamilton circuit in a graph is a circuit that visits each vertex exactly once (returning to the starting vertex to complete the circuit). 15-3-5 © 2008 Pearson Addison-Wesley. All rights reserved Example: Identifying Hamilton Circuits Refer to the graph below. Which of the following are Hamilton circuits? a) A B E D C F A b) A B C D E F C EBFA c) B C D E F B C B A F D E © 2008 Pearson Addison-Wesley. All rights reserved 15-3-6 Example: Identifying Hamilton Circuits Solution a) It is a Hamilton circuit for the graph. b) It is not a Hamilton circuit since it visits B more than once. c) It is not a Hamilton circuit since it does not visit all the vertices. 15-3-7 © 2008 Pearson Addison-Wesley. All rights reserved Hamilton Circuits for Complete Graphs Any complete graph with three of more vertices has a Hamilton circuit. 15-3-8 © 2008 Pearson Addison-Wesley. All rights reserved When Hamilton Circuits Are the Same Hamilton circuits that differ only in their starting points will be considered to be the same circuit. 15-3-9 © 2008 Pearson Addison-Wesley. All rights reserved Number of Hamilton Circuits in a Complete Graph A complete graph with n vertices has (n – 1)! Hamilton circuits. 15-3-10 © 2008 Pearson Addison-Wesley. All rights reserved Example: Number of Circuits How many Hamilton circuits are in a complete graph with 5 vertices? Solution Here n = 5, so there are (5 – 1)! = 4! = 24 Hamilton circuits. 15-3-11 © 2008 Pearson Addison-Wesley. All rights reserved Minimum Hamilton Circuits In a weighted graph, a minimum Hamilton circuit is a Hamilton circuit with the smallest possible weight. 15-3-12 © 2008 Pearson Addison-Wesley. All rights reserved Brute Force Algorithm Step 1: Choose a starting point. Step 2: List all the Hamilton circuits with that starting point. Step 3: Find the total weight of each circuit. Step 4: Choose a Hamilton circuit with the smallest total weight. 15-3-13 © 2008 Pearson Addison-Wesley. All rights reserved Example: Brute Force Algorithm Find a minimum Hamilton circuit for the complete, weighted graph below 3 A 1 D 1 B 5 3 7 C 15-3-14 © 2008 Pearson Addison-Wesley. All rights reserved Example: Brute Force Algorithm Solution 1 D 1. 2. 3. 4. 5. 6. 3 A 1 B 5 7 3 C A BC D A A BD CA A CBD A A CDBA A D BCA A DCBA Weight of circuit 14 12 Min. 14 12 (opposite of 2) 14 (opposite of 3) 14 (opposite of 1) © 2008 Pearson Addison-Wesley. All rights reserved 15-3-15 Nearest Neighbor Algorithm Step 1: Step 2: Step 3: Choose a starting point. Call this vertex A. Check all the edges joined to A, and choose one that has the smallest weight. Proceed along this edge to the next vertex. At each vertex you reach, check the edges from there to vertices not yet visited. Choose the smallest weight. Proceed along this edge to the next vertex. © 2008 Pearson Addison-Wesley. All rights reserved 15-3-16 Nearest Neighbor Algorithm Step 4: Step 5: Repeat Step 3 until you have visited all the vertices. Return to the starting vertex. 15-3-17 © 2008 Pearson Addison-Wesley. All rights reserved Example: Nearest Neighbor The time it takes to travel between points (in minutes) is shown on the graph below. Use the nearest neighbor algorithm to approximate the least time to visit each location. A 9 B 10 20 9 3 13 8 C 8 7 E 5 D 15-3-18 © 2008 Pearson Addison-Wesley. All rights reserved Example: Nearest Neighbor Algorithm Solution Start Circuit Weight A A D E BC A 40 B BE D CA B 37 C 37 D C D E BA C D E BA C D E E BDCA E 51 37 15-3-19 © 2008 Pearson Addison-Wesley. All rights reserved Example: Nearest Neighbor Algorithm Solution (continued) From the information on the previous slide we would say that a route of 37 minutes should be about the least amount of time. Note that A B E C D A has a total weight of 36 minutes. All we can expect from the nearest neighbor algorithm is a reasonably good solution. 15-3-20 © 2008 Pearson Addison-Wesley. All rights reserved