Gap-Introducing Reductions
The first half of this course proved upper bounds: an algorithm achieves ratio . The second kind of theorem says that no polynomial algorithm achieves ratio , unless P = NP. Ordinary NP-hardness proofs do not give such results: they show that finding the exact optimum is hard, and say nothing about getting close. The tool that does is a reduction that creates a gap: the instances it builds have an optimum either at most or at least , with nothing in between, so an algorithm with ratio below can tell the two cases apart and solve an NP-complete problem. Several examples have already appeared in the course; this lesson makes the method explicit and proves its most dramatic instance, the inapproximability of TSP without the triangle inequality.
Gap problems
Definition. For a minimization problem and thresholds , the gap problem is the promise problem: given an instance with either or , decide which. (For maximization: or with .)
Lemma. If is NP-hard, then has no polynomial -approximation with unless P = NP.
Proof. Run the approximation. If , it returns a value at most ; if , every solution has value above . Comparing the value with decides the gap problem.
A gap-introducing reduction maps instances of an NP-complete decision problem to instances of so that yes-instances land at most at and no-instances above . The thresholds and may depend on the input size.
| Problem | Reduction from | Gap | Consequence (unless P = NP) |
|---|---|---|---|
| bin packing | PARTITION | 2 bins vs 3 bins | no ratio below (Bin Packing: First Fit and First-Fit Decreasing) |
| metric -center | dominating set | radius 1 vs 2 | no ratio below 2 (k-Center and Farthest-First Traversal) |
| graph colouring | 3-colourability of planar graphs | 3 colours vs 4 | no ratio below |
| makespan on unrelated machines | 3-dimensional matching | makespan 2 vs 3 | no ratio below (Lenstra, Shmoys and Tardos, 1990) |
| general TSP | Hamiltonian cycle | vs more than | no ratio at all, for any polynomial-time computable |
The colouring row works because every planar graph is 4-colourable (Appel and Haken, 1976), while deciding 3-colourability of planar graphs is NP-complete (Garey, Johnson and Stockmeyer, 1976): the optimum of a planar graph with an edge is 2, 3 or 4, and distinguishing 3 from 4 is the hard part. The program shows the gap on two small planar graphs, computing the chromatic number by brute force.
from itertools import product
def chromatic_number(n, edges):
for k in range(1, n + 1):
for colours in product(range(k), repeat=n):
if colours[0] == 0 and all(colours[u] != colours[v] for u, v in edges):
return k
wheel5 = [(i, (i + 1) % 5) for i in range(5)] + [(5, i) for i in range(5)] # odd wheel: planar
octahedron = [(u, v) for u in range(6) for v in range(u + 1, 6) if v != u + 3 or u >= 3]
for name, n, E in [("octahedron", 6, octahedron), ("wheel with 5 spokes", 6, wheel5)]:
print(f"{name}: {len(E)} edges, chromatic number {chromatic_number(n, E)}")octahedron: 12 edges, chromatic number 3
wheel with 5 spokes: 10 edges, chromatic number 4
An algorithm with ratio below would have to answer 3 on the octahedron and could only answer 4 on the odd wheel, so it would decide planar 3-colourability.
TSP without the triangle inequality
Theorem (Sahni and Gonzalez, 1976). Let be computable in polynomial time. Unless P = NP, there is no polynomial-time -approximation for TSP with arbitrary non-negative costs.
Proof. Reduce from HAMILTONIAN CYCLE, which is NP-complete (Hamiltonian Cycles and the Travelling Salesman). Given a graph with vertices, build the complete graph on with costs
The costs have polynomially many bits because is computable in polynomial time. If has a Hamiltonian cycle, that cycle is a tour of cost . If not, every tour uses at least one non-edge and costs at least . An -approximation returns a tour of cost at most in the first case and necessarily more in the second, so it decides HAMILTONIAN CYCLE.
The constructed costs badly violate the triangle inequality: two edges of cost 1 may span a non-edge of huge cost. With the triangle inequality, the same reduction (non-edges of cost 2, which is metric) gives only that metric TSP is NP-hard, and the gap versus is too small to rule out any constant ratio.
The program applies the reduction to a cycle with chords (Hamiltonian) and to the Petersen graph (famously not Hamiltonian), and solves the TSP instances exactly.
from math import inf
def held_karp(c):
n = len(c)
D = [[inf] * n for _ in range(1 << n)]
D[1][0] = 0
for S in range(1, 1 << n, 2):
for j in range(n):
if D[S][j] < inf:
for k in range(1, n):
if not S >> k & 1:
D[S | 1 << k][k] = min(D[S | 1 << k][k], D[S][j] + c[j][k])
return min(D[-1][j] + c[j][0] for j in range(1, n))
def reduction(n, edges, alpha):
E = {frozenset(e) for e in edges}
return [[0 if u == v else 1 if frozenset((u, v)) in E else alpha * n + 1 for v in range(n)] for u in range(n)]
petersen = [(i, (i + 1) % 5) for i in range(5)] + [(5 + i, 5 + (i + 2) % 5) for i in range(5)] + [(i, i + 5) for i in range(5)]
prism = [(i, (i + 1) % 5) for i in range(5)] + [(5 + i, 5 + (i + 1) % 5) for i in range(5)] + [(i, i + 5) for i in range(5)]
alpha = 3
for name, E in [("pentagonal prism", prism), ("Petersen graph", petersen)]:
opt = held_karp(reduction(10, E, alpha))
verdict = "Hamiltonian" if opt == 10 else "not Hamiltonian"
print(f"{name}: optimal tour {opt:3}; an alpha = {alpha} approximation returns <= {alpha * 10} iff the graph is Hamiltonian -> {verdict}")pentagonal prism: optimal tour 10; an alpha = 3 approximation returns <= 30 iff the graph is Hamiltonian -> Hamiltonian
Petersen graph: optimal tour 40; an alpha = 3 approximation returns <= 30 iff the graph is Hamiltonian -> not Hamiltonian
Both graphs are 3-regular with 10 vertices and 15 edges, and they look alike locally, yet the optimal tour jumps from 10 to 40 (nine graph edges and one non-edge of cost 31, since the Petersen graph has a Hamiltonian path): the reduction turned a yes/no question into a factor-4 gap.
In C++
The same reduction on the Petersen graph, with a larger ; the gap grows with it while the yes-instances stay at cost .
#include <algorithm>
#include <cstdio>
#include <vector>
int main() {
const int n = 10;
int edges[15][2] = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0}, {5, 7}, {7, 9}, {9, 6}, {6, 8}, {8, 5},
{0, 5}, {1, 6}, {2, 7}, {3, 8}, {4, 9}};
for (long long alpha : {2LL, 10LL, 1000LL}) {
std::vector<std::vector<long long>> c(n, std::vector<long long>(n, alpha * n + 1));
for (auto& e : edges) c[e[0]][e[1]] = c[e[1]][e[0]] = 1;
const long long INF = 1LL << 60;
std::vector<std::vector<long long>> D(1 << n, std::vector<long long>(n, INF));
D[1][0] = 0;
for (int S = 1; S < (1 << n); S += 2)
for (int j = 0; j < n; j++)
if (D[S][j] < INF)
for (int k = 1; k < n; k++)
if (!(S >> k & 1)) D[S | 1 << k][k] = std::min(D[S | 1 << k][k], D[S][j] + c[j][k]);
long long best = INF;
for (int j = 1; j < n; j++) best = std::min(best, D[(1 << n) - 1][j] + c[j][0]);
std::printf("alpha = %4lld: Petersen tour %lld > alpha * n = %lld\n", alpha, best, alpha * n);
}
}alpha = 2: Petersen tour 30 > alpha * n = 20
alpha = 10: Petersen tour 110 > alpha * n = 100
alpha = 1000: Petersen tour 10010 > alpha * n = 10000
What gap-introducing reductions cannot do directly
Every reduction above starts from a problem whose yes/no answer already creates a large multiplicative difference in a tiny optimum (2 vs 3 bins, radius 1 vs 2) or from a construction where the cost function can be chosen freely (TSP). For problems such as MAX-3SAT, vertex cover or set cover, the natural reductions from SAT create only an additive gap of one clause or one vertex, which says nothing about ratios. A satisfiable formula has all clauses satisfiable; an unsatisfiable one might still have . To get a constant-factor gap for these problems one needs the PCP theorem (The PCP Theorem), which produces formulas where unsatisfiable means "far from satisfiable". From there, gap-preserving reductions carry the gap to other problems (Gap-Preserving Reductions).
Test yourself
If is NP-hard for a minimization problem, what follows?
- has no polynomial algorithm at all
- No polynomial -approximation with exists unless P = NP
- has a PTAS
- OPT is always between and
In the reduction from Hamiltonian cycle to TSP, why must non-edges cost more than about ?
- To keep the costs metric
- So that any tour using a non-edge costs more than times the cost of a Hamiltonian cycle
- Because must be an integer
- To make the instance sparse
Why does the same reduction with non-edges of cost 2 not rule out constant factors for metric TSP?
- Because cost 2 is not metric
- It only creates the gap versus , a ratio that tends to 1
- Because Christofides solves it exactly
- Because Hamiltonian cycle is easy on such graphs
Why does the planar 3-colourability reduction give a gap for graph colouring?
- Planar graphs are 3-colourable
- Every planar graph is 4-colourable, so the optimum is 3 for yes-instances and 4 for no-instances, a ratio of
- Because colouring is in P
- Because of the PCP theorem