Sub topic 8
Why General TSP Cannot Be Approximated
This chapter assumes you know what a Hamiltonian cycle is, that deciding whether a graph has one is NP-complete, and how a polynomial-time reduction works. It also builds on the previous chapter, where the triangle inequality made a 2-approximation possible for metric TSP.
The Claim
For general TSP, edge weights can be any non-negative numbers, and the triangle inequality may fail. In that setting no polynomial-time algorithm can achieve an approximation ratio of ρ, for any constant ρ ≥ 1, unless P = NP. The proof shows that a ρ-approximation algorithm could be used to decide the Hamiltonian cycle problem.
The Gap Reduction
Start with a graph G = (V, E) that has n vertices. Build a complete graph on the same vertices and give each pair (u, v) this weight:
- 1 if (u, v) is an edge of G.
- ρn + 1 if (u, v) is not an edge of G.
Now compare the two possible cases:
| Case | Optimal tour cost |
|---|---|
| G has a Hamiltonian cycle | Exactly n, because the tour uses only weight-1 edges |
| G has no Hamiltonian cycle | At least (ρn + 1) + (n − 1) > ρn, because every tour uses at least one non-edge |
Between n and ρn there is a gap that no tour can fall into. Suppose algorithm A always returns a tour of cost at most ρ · OPT. On a "yes" instance, A returns a tour of cost at most ρn. On a "no" instance, every tour costs more than ρn, so A's tour does too. Checking whether A's tour costs at most ρn therefore decides Hamiltonian cycle in polynomial time.
The reduction runs in polynomial time. It writes n² weights, and each weight needs only O(log(ρn)) bits. The argument still holds when ρ grows with n, for example ρ = 2ⁿ, because the large weight still fits in polynomially many bits.
Seeing the Gap
The code below builds the instance for two 4-vertex graphs and finds the optimal tour by brute force. It only demonstrates the gap. It is not an approximation algorithm.
from itertools import permutations
def gap_instance(n, edges, rho):
E = {frozenset(e) for e in edges}
big = rho * n + 1
return [[0 if i == j else (1 if frozenset((i, j)) in E else big)
for j in range(n)] for i in range(n)]
def optimal_tour_cost(dist):
n = len(dist)
best = float("inf")
for perm in permutations(range(1, n)):
tour = (0,) + perm + (0,)
best = min(best, sum(dist[tour[k]][tour[k + 1]] for k in range(n)))
return best
rho = 2
graphs = {
"cycle": [(0, 1), (1, 2), (2, 3), (3, 0)],
"star": [(0, 1), (0, 2), (0, 3)],
}
for name, edges in graphs.items():
D = gap_instance(4, edges, rho)
print(name, optimal_tour_cost(D), "threshold", rho * 4)The output is cycle 4 threshold 8 and star 20 threshold 8. The cycle graph is Hamiltonian, and its optimal tour costs 4, below the threshold of 8. The star graph is not Hamiltonian, and its optimal tour costs 20, well above 8.
Why Metric TSP Escapes
The constructed weights break the triangle inequality. For a non-edge (u, w) where both (u, v) and (v, w) are edges, the direct weight ρn + 1 is larger than the detour 1 + 1 = 2. The double-tree algorithm depends on shortcuts never costing more than detours. When that property is gone, the optimum gives no handle for bounding a tour.
This style of argument is called a gap reduction: it maps "yes" and "no" instances to optimum values that are separated by more than the approximation factor. Later chapters extend the idea to hardness results that rely on the PCP theorem.
Exercise
Suppose non-edges get weight ρn instead of ρn + 1. Does the reduction still work for n ≥ 2?
Show answer
Yes. A tour on a non-Hamiltonian graph uses at least one non-edge, so it costs at least ρn + (n − 1). For n ≥ 2 that is more than ρn, so the gap between ρn and the "no" case remains.
Exercise
Why does this proof not contradict the 2-approximation for metric TSP?
Show answer
The instances the reduction builds are not metric. Two weight-1 edges u–v and v–w give a path of length 2, while the direct edge u–w has weight ρn + 1 > 2. That violates the triangle inequality, so the metric algorithm's guarantee does not apply to them.