A Short History of Exact TSP
The Traveling Salesman Problem is easy to state but has repeatedly driven new ideas in combinatorial optimization. Exhaustive permutation search remains the clearest exact baseline, yet the history of exact TSP also includes linear programming, cutting planes, dynamic programming, and complexity theory.
This article keeps the original three-part progression: brute force establishes the truth, backtracking preserves exactness while pruning, and Sorted Edges (Cheapest Link) shows what changes when speed is preferred over a proof of optimality.
Problem Model & Guarantees
Given cities $V$ and travel costs $d(u,v)$, TSP asks for a minimum-cost Hamiltonian cycle: start at one city, visit every city exactly once, and return to the start. This page assumes a complete, symmetric, nonnegative distance matrix.
Exact methods
Brute force and backtracking eventually compare enough possibilities to certify the optimum. Their answer comes with a proof by exhaustion or bounds.
Constructive heuristic
Cheapest Link quickly constructs one legal cycle. It may be excellent or poor, but the tour alone does not prove how close it is to optimal.
TSP Brute Force: Permutation Enumeration
Fix city 0 as the start—rotating a cycle does not produce a genuinely new tour. Enumerate every ordering of the other $n-1$ cities, add the closing edge back to 0, and keep the least expensive cycle. This is conceptually simple and exact.
Remove rotational duplicates
Fix one start city, leaving $(n-1)!$ candidate orderings rather than $n!$ written sequences.
Remove reverse duplicates
For symmetric costs, a tour and its reverse cost the same. A canonical orientation leaves $(n-1)!/2$ distinct cycles for $n > 2$.
Evaluate every remaining tour
Sum its $n$ edges, including the return to the start. The smallest observed cost is provably optimal.
Why keep brute force?
It is an oracle for tiny instances. A slow, obviously correct solver is invaluable for testing faster exact algorithms and measuring heuristic error.
TSP Backtracking: Bounding & Pruning
Backtracking explores the same permutation tree but reasons about partial tours. It maintains an incumbent (the cheapest complete tour seen) and a lower bound on every unfinished branch. If a branch cannot beat the incumbent, discard it without listing its descendants.
Why Lower Bounds Matter
Using only the cost already paid is a valid bound when all edge weights are nonnegative, but it is weak. The implementations below use a stronger completion bound:
$$\text{partial cost} + \min(\text{last}\to R) + \operatorname{MST}(R) + \min(R\to\text{start})$$
Here $R$ is the set of unvisited cities. Any completion must enter $R$, connect all cities in $R$, and eventually leave $R$ for the start. A minimum spanning tree is no more expensive than the internal edges used by any such completion, making the expression optimistic and safe for pruning.
A good incumbent amplifies the bound
Run a fast heuristic first and use its tour cost as the initial incumbent. Candidate ordering then matters too: trying short edges early often discovers stronger incumbents sooner, though worst-case time remains factorial.
Sorted Edges (Cheapest Link)
Nearest Neighbor chooses the next city from the current endpoint. Cheapest Link instead scans all undirected edges from lightest to heaviest and accepts an edge only when two feasibility rules hold:
- Degree rule: neither endpoint may already have two chosen tour edges.
- Subtour rule: the edge may not close a cycle until it is the final, $n$th selected edge.
A disjoint-set structure tracks whether two endpoints are already in the same path fragment. It is not constructing the tour by itself; it is only answering the premature-cycle question efficiently.
Legal does not mean optimal
The rules guarantee one Hamiltonian cycle on a complete symmetric instance. They do not undo an early greedy choice that later forces an expensive edge.
Worked Example: Four Cities
Let AB=10, AC=15, AD=20, BD=25, CD=30, and BC=35. The sorted order is AB, AC, AD, BD, CD, BC.
| Edge | Decision | Reason | Chosen edges |
|---|---|---|---|
| AB (10) | Accept | Both degrees are below 2; no cycle. | AB |
| AC (15) | Accept | A–B and A–C form one path fragment. | AB, AC |
| AD (20) | Skip | A already has degree 2. | AB, AC |
| BD (25) | Accept | Extends the fragment through B. | AB, AC, BD |
| CD (30) | Accept | This is the final edge, so closing the full cycle is allowed. | AB, AC, BD, CD |
Complexity Analysis
| Method | Time | Extra space | Guarantee |
|---|---|---|---|
| Brute force | $\Theta(n \cdot (n-1)!/2)$ for symmetric TSP | $O(n)$ beyond generated permutations | Exact optimum |
| Backtracking + bounds | $O(n!)$ worst case; pruning is instance-dependent | $O(n)$ search path plus bound workspace | Exact optimum |
| Cheapest Link | $O(n^2 \log n)$ for sorting all edges | $O(n^2)$ for the edge list | Feasible heuristic tour, not an optimality proof |
Brute force spends time proving that nothing was missed. Backtracking seeks the same proof with fewer explored leaves. Cheapest Link stops asking for a proof and commits to one sequence of locally legal choices.
Implementation
Real-World Applications
Correctness oracle
Generate tiny random instances and compare a production solver's answer with brute force. Any cost mismatch reveals a bug or an invalid assumption.
Small exact routing
When the number of stops is genuinely small, backtracking with a good bound may certify an optimal route within the available time.
Heuristic initialization
A Cheapest-Link tour supplies an immediate incumbent for branch-and-bound or a starting point for 2-opt and 3-opt improvement.
Quality measurement
For small benchmark instances, the exact optimum lets you report a heuristic's percentage gap instead of judging a tour in isolation.
Exercises
1. Count distinct cycles
For $n=6$, begin with $6!$ written sequences. Remove rotations and reversals step by step to derive the number of distinct symmetric tours.
2. Audit a lower bound
At partial path A → B in the worked instance, compute the enter-$R$ + MST($R$) + return-to-A bound. Why may it be lower than every realizable completion?
3. Force a premature subtour
Construct five-city weights whose three cheapest edges form a triangle. Trace how the disjoint-set check rejects the triangle-closing edge.
4. Measure, then improve
Generate symmetric Euclidean instances, compare Cheapest Link with the optimum for small $n$, then add 2-opt and report how often the gap shrinks.
Limitations
- Factorial worst case: backtracking can still visit essentially the full permutation tree when bounds are weak or many tours have similar costs.
- Heuristic quality depends on assumptions: on unrestricted weighted complete graphs, Cheapest Link can be arbitrarily worse than optimal. Metric structure helps analysis, but it still lacks Christofides' constant $3/2$ guarantee.
- This implementation is symmetric: asymmetric TSP needs directed-edge degree constraints and different subtour bookkeeping.
- A matrix assumes completeness: missing routes, time windows, capacities, and multiple vehicles turn the problem into richer routing variants.
- Floating-point comparisons: real geographic costs may require tolerances and deterministic tie-breaking.
Practical scale is not a fixed city count
Whether exact backtracking is feasible depends on bound strength, cost structure, incumbent quality, symmetry, and hardware—not a universal threshold such as “15 cities” or “20 cities.” Always enforce a time or node budget in production.