Chapter 6 Hamilton Joins the Circuit Outline/learning Objectives To identify and model Hamilton circuit and Hamilton path problems. To recognize complete graphs and state the number of Hamilton circuits that they have. To identify traveling-salesman problems and the difficulties faced in solving them. 2 3 Outline/learning Objectives 4 To implement brute-force, nearestneighbor, repeated nearest-neighbor, and cheapest-link algorithms to find approximate solutions to traveling salesman problems. To recognize the difference between efficient and inefficient algorithms. To recognize the difference between optimal and approximate algorithms. 5 6.1 Hamilton Circuits and Hamilton Paths Hamilton path A path that visits each vertex of the graph once and only once. Hamilton circuit A circuit that visits each vertex of the graph once and only once (at the end, of course, the circuit must return to the starting vertex). 6 7
8 Figure (a) shows a graph that has Euler circuits and has Hamilton circuits. One such Hamilton circuit is A, F, B, C, G, D, E, A. Note that once a graph has a Hamilton circuit, it automatically has a Hamilton path-- The Hamilton circuit can always be truncated into a Hamilton path by dropping the last vertex of the circuit. 9 10 Figure (b) shows a graph that has no Euler circuits but does have Euler paths (for example C, D, E, B, A, D), has no Hamilton circuits (sooner or later you have to go to C, and then you are stuck) but does have Hamilton paths (for example, A, B, E, D, C). Aha, a graph can have a Hamilton path but no Hamilton Circuit! 11 Figure (c) shows a graph that has neither Euler circuits nor paths (it has four odd vertices), has Hamilton circuits (for example A, B, C, D, E, A there are plenty more), and consequently has Hamilton paths (for example, A, B, C, D, E). 12 13
Figure (d) shows a graph that has Euler circuits (the vertices are all even), has no Hamilton circuits (no matter what, your are going to have to go through E more than once!) but has Hamilton paths (for example, A, B, E, D, C). 14 15 Figure (e) shows a graph that has no Euler circuits but has Euler paths (F and G are the two odd vertices), had neither Hamilton circuits nor Hamilton paths. 16 17 Figure (f) shows a graph that has neither Euler circuits nor Euler paths (too many odd vertices), has no Hamilton circuits, but does have Hamilton paths. The lesson in the previous Example is that the existence of an Euler path or circuit in a graph tells us nothing about the existence of a Hamilton path or circuit in that graph. This implies that Euler s theorems from Chapter 5 are useless when it comes to Hamilton circuits and paths. In fact, there are no Hamilton s theorems that we can use to determine whether a Hamilton circuit or path exists. 18 19
There are, however, nice theorems that identify special situations where a graph must have a Hamilton circuit. This best known of these theorems is Dirac s theorem: If a connected graph has N vertices (N > 2) and all of them have degree greater than or equal to N/2, then the graph has a Hamilton circuit. 6.2 Complete Graphs 20 21 If a graph has a Hamilton circuit, then how many different Hamilton circuits does it have? A graph with N vertices in which every pair of distinct vertices is joined by an edge is called a complete graph on N vertices and denoted by the symbol K N. Number of Edges in K N K N has N(N 1)/2 edges. Of all graphs with N vertices and no multiple edges or loops, K N has the most edges. 22 23 If we travel the four vertices of K 4 in an arbitrary order, we get a Hamilton path. For example, C, A, D, B is a Hamilton path. D, C, A, B is another Hamilton Path. 24 25
Each of these Hamilton paths can be closed into a Hamilton circuit-- the path C, A, D, B begets the circuit D, A, D, B, C. The path D, C, A, B begets the circuit D, C, A, B, D. 26 27 It is important to remember that the same Hamilton circuit can be written in many ways. For example, C, A, D, B, C is the same circuit as A, D, B, C, A the only difference is that in the first case we used C as the reference point in the second case we used A. 28 29 Number of Hamilton Circuits in K N There are (N 1)! Distinct Hamilton circuits in K N. 6.3 Traveling Salesman Problems 30 31
The traveling salesman is a convenient metaphor for many different important real-life applications, all involving Hamilton circuits in complete graphs but only occasionally involving salespeople. Any graph whose edges have numbers attached to them is called a weighted graph, and the numbers are called the weights of the edges. The graph is called a complete weighted graph. 32 33 The problem we want to solve is fundamentally the same find an optimal Hamilton circuit (a Hamilton circuit with least total weight) for the given weighted graph. 6.4 Simple Strategies for Solving TSPs 34 35 36 Strategy 1 (Exhaustive Search) Make a list of all possible Hamilton circuits. For each circuit in the list, calculate the total weight of the circuit. From all the circuits, choose the circuit with smallest total weight. 37 Strategy 2 (Go Cheap) Strategy 2 (Go Cheap) Start from the home city. From there go to the city that is the cheapest to get to. From each new city go to the next city that is cheapest to get to. When there are no more new cities to go to, go back home.