From Hamiltonian Cycles to Tour Costs
A Hamiltonian cycle answers a yes-or-no question: can we visit every vertex exactly once and return to the start? The traveling-salesman problem adds a cost to each edge and asks which such cycle has least total cost. On a small graph, we can answer by listing the distinct cycles and adding their edge weights. The exhaustive search is simple, but it depends on being precise about what counts as a tour and how rotations and reversals are treated.
Throughout, graphs are finite and simple. The traveling-salesman instances considered here have at least three vertices. Edge costs are real numbers, and costs are symmetric: traveling along an edge has the same cost in either direction. We do not assume the triangle inequality.
A Hamiltonian cycle is a cycle that visits every vertex exactly once before returning to its starting vertex. A Hamiltonian tour in a weighted graph is that cycle together with its total cost. If the vertices in cyclic order are \(v_1,\ldots,v_n\), its cost is
Changing the starting point only rotates this list; traversing the same undirected cycle in reverse gives the reverse list. Neither change creates a different tour. An optimal tour is a Hamiltonian tour of minimum cost among all tours in the instance. Completeness guarantees that tours exist when \(n\ge3\): any ordering of the vertices, followed by a return to the first, is a Hamiltonian cycle.
Why Fixing a Starting Vertex Works
Proof. Fix one vertex \(r\) as the first vertex in a written description of a cycle. Arrange the other \(n-1\) vertices in any order, then return from the last vertex to \(r\). This gives \((n-1)!\) written descriptions. Every Hamiltonian cycle has exactly two such descriptions: one for each direction around the cycle, both starting at \(r\). The descriptions are distinct because \(n\ge3\), so the two neighbors of \(r\) occur in opposite orders. There are no other descriptions of that cycle starting at \(r\), since its cyclic order is fixed once a direction is chosen. Thus each distinct undirected cycle has been counted twice, and the number of cycles is \((n-1)!/2\). \(\square\)
Proof. Choose a vertex \(r\). Each permutation of the other vertices gives a Hamiltonian cycle by starting at \(r\), following the permutation, and returning to \(r\). Conversely, every Hamiltonian cycle has a description starting at \(r\), so at least one of its two directions appears in this list. Therefore every possible tour cost is represented. The list is finite and nonempty, so its costs have a minimum. Since the list contains every tour, its minimum is the minimum over all tours and is optimal. Symmetry ensures that the reverse description has the same cost, so retaining both directions does not change the minimum. \(\square\)
For hand calculations, we can avoid listing both directions: after fixing \(r\), keep just one ordering from each reverse pair. The proposition shows that this leaves \((n-1)!/2\) tours. For larger instances, the number grows rapidly; exhaustive enumeration is therefore a useful exact method for small examples, not a promise that brute force is efficient at every size.
Worked Examples
Worked Example: Enumerating All Tours on Four Vertices
Let \(V=\{A,B,C,D\}\), let \(E=\{AB,AC,AD,BC,BD,CD\}\), and assign the costs \(w(AB)=4\), \(w(AC)=8\), \(w(AD)=7\), \(w(BC)=5\), \(w(BD)=6\), and \(w(CD)=3\). The graph is complete because these are all six pairs of distinct vertices. Fix \(A\). There are \((4-1)!/2=3!/2=3\) distinct tours to check.
Use the orders \(B,C,D\), \(B,D,C\), and \(C,B,D\). For \(A-B-C-D-A\), the edge costs are \(4,5,3,7\), so the total is \(4+5+3+7=19\). For \(A-B-D-C-A\), they are \(4,6,3,8\), so the total is \(4+6+3+8=21\). For \(A-C-B-D-A\), they are \(8,5,6,7\), so the total is \(8+5+6+7=26\). The least of \(19,21,26\) is \(19\).
Check: The three tours have all been included: there are exactly \(3\) distinct cycles by the count, and the three displayed costs are \(19\), \(21\), and \(26\). The reverse of \(A-B-C-D-A\) is \(A-D-C-B-A\), the same undirected tour, not a fourth candidate. Thus the tour \(A-B-C-D-A\) is optimal with cost \(19\).
Worked Example: Exhaustive Search on Five Vertices
Let \(V=\{1,2,3,4,5\}\), let \(E\) contain all ten pairs of distinct vertices, and set \(w(12)=2\), \(w(13)=7\), \(w(14)=8\), \(w(15)=6\), \(w(23)=3\), \(w(24)=9\), \(w(25)=10\), \(w(34)=4\), \(w(35)=11\), and \(w(45)=5\). Fix vertex \(1\). The count gives \((5-1)!/2=4!/2=12\) distinct tours. The table lists one direction for each tour; the cost column shows every edge cost being added.
| Tour starting at 1 | Cost calculation | Total |
|---|---|---|
| 1-2-3-4-5-1 | 2+3+4+5+6 | 20 |
| 1-2-3-5-4-1 | 2+3+11+5+8 | 29 |
| 1-2-4-3-5-1 | 2+9+4+11+6 | 32 |
| 1-2-4-5-3-1 | 2+9+5+11+7 | 34 |
| 1-2-5-3-4-1 | 2+10+11+4+8 | 35 |
| 1-2-5-4-3-1 | 2+10+5+4+7 | 28 |
| 1-3-2-4-5-1 | 7+3+9+5+6 | 30 |
| 1-3-2-5-4-1 | 7+3+10+5+8 | 33 |
| 1-3-4-2-5-1 | 7+4+9+10+6 | 36 |
| 1-3-5-2-4-1 | 7+11+10+9+8 | 45 |
| 1-4-2-3-5-1 | 8+9+3+11+6 | 37 |
| 1-4-3-2-5-1 | 8+4+3+10+6 | 31 |
For example, the sixth row corresponds to edges \(12,25,54,43,31\); their costs are \(2,10,5,4,7\), whose sum is \(2+10+5+4+7=28\). Comparing all twelve totals gives a minimum of \(20\), attained by \(1-2-3-4-5-1\).
Check: The twelve rows equal the predicted number \(4!/2=12\), so the list covers every distinct cycle exactly once. The first row's sum is \(2+3+4+5+6=20\), and every other displayed total—\(29,32,34,35,28,30,33,36,45,37,31\)—is greater than \(20\). The tour in the first row is therefore optimal.
Worked Example: Two Tours Tie for the Minimum
Let \(V=\{p,q,r,s\}\), \(E=\{pq,pr,ps,qr,qs,rs\}\), and set \(w(pq)=1\), \(w(pr)=2\), \(w(ps)=2\), \(w(qr)=2\), \(w(qs)=2\), and \(w(rs)=1\). Fix \(p\). There are \((4-1)!/2=3\) tours.
The tour \(p-q-r-s-p\) costs \(w(pq)+w(qr)+w(rs)+w(sp)=1+2+1+2=6\). The tour \(p-q-s-r-p\) costs \(w(pq)+w(qs)+w(sr)+w(rp)=1+2+1+2=6\). The third tour, \(p-r-q-s-p\), costs \(w(pr)+w(rq)+w(qs)+w(sp)=2+2+2+2=8\). Thus the minimum is \(6\), attained by two distinct tours.
Check: The three computed costs are \(6,6,8\), and they correspond to the full set of three distinct cycles. The two cost-\(6\) tours use different edge sets, so this is a genuine tie between tours, not a cycle and its reverse.
Common Pitfalls and Interpretation
Adding only the edges used to arrive at the last vertex is not enough. A tour must return to its starting vertex. In the first example, the mistaken calculation \(4+5+3=12\) follows \(A-B-C-D\) but omits the return edge \(DA\), whose cost is \(7\). The corrected tour cost is \(4+5+3+7=19\). Omitting the return edge calculates the cost of a path, not a tour.
Do not treat rotations or reversals as new undirected tours. For example, \(A-B-C-D-A\), \(B-C-D-A-B\), and \(A-D-C-B-A\) describe the same cycle. Fixing a starting vertex removes the rotations; retaining one ordering from each reverse pair removes the duplicate direction. These conventions prevent overcounting while preserving every possible tour.
A cheapest-looking collection of edges may not form a tour. A tour has to visit every vertex once and return to its start. Its cost is the sum around a single Hamiltonian cycle, not the sum of an arbitrary selection of low-cost edges. Exhaustive enumeration checks the full cycle condition at the same time as it compares costs.
The examples show why the weighted problem has two ingredients: the graph specifies which edges can be used, and the cost function determines how tours compare. In a complete instance every edge is available, but the tour condition still restricts the choices. For a small instance, listing all distinct cycles gives a transparent certificate of optimality: a tour of the stated cost, together with the costs of every other candidate.
Check Your Understanding
For each question, state enough of the calculation or reasoning to justify your answer.
- How many distinct undirected Hamiltonian cycles are there on a complete graph with six labeled vertices?
- In a symmetric instance, why does reversing a tour preserve its cost?
- Suppose a tour on four vertices has consecutive edge costs \(3,8,2,5\). What is its total cost, including the return edge?
- For \(V=\{a,b,c\}\), with \(w(ab)=2\), \(w(bc)=7\), and \(w(ca)=4\), how many distinct tours are there, and what is their cost?
- Explain why a list of all tours with their costs proves optimality when the list is exhaustive.