Sub topic 3
Approximation Schemes: Trading Accuracy for Time
This chapter assumes you know the approximation ratio, basic dynamic programming, and what a linear program (LP) is.
PTAS and FPTAS
An approximation scheme takes an error parameter ε > 0 and returns a solution within a factor (1 + ε) of optimal, or (1 − ε) for maximization problems. A PTAS runs in polynomial time for each fixed ε. Its running time can still be something like n^(1/ε). An FPTAS must run in time polynomial in both n and 1/ε. A common mistake is to treat every PTAS as practical. When the exponent grows with 1/ε, the algorithm is too slow for small ε.
An FPTAS for 0/1 Knapsack
Knapsack has an exact dynamic program that runs in time polynomial in the total value. That total can be huge. The fix is to scale every value down by K = ε·vmax/n and round down. Then you solve the scaled instance exactly. Each item loses less than K of value, so the chosen set loses at most nK = ε·vmax ≤ ε·OPT.
def knapsack_fptas(values, weights, capacity, eps):
n = len(values)
k = eps * max(values) / n
scaled = [int(v // k) for v in values]
total = sum(scaled)
INF = float("inf")
min_w = [0] + [INF] * total
keep = [[False] * (total + 1) for _ in range(n)]
for i in range(n):
for p in range(total, scaled[i] - 1, -1):
cand = min_w[p - scaled[i]] + weights[i]
if cand < min_w[p]:
min_w[p] = cand
keep[i][p] = True
best = max(p for p in range(total + 1) if min_w[p] <= capacity)
items, p = [], best
for i in range(n - 1, -1, -1):
if keep[i][p]:
items.append(i)
p -= scaled[i]
return sorted(items)
print(knapsack_fptas([60, 100, 120], [10, 20, 30], 50, 0.1))The program prints [1, 2]. The table has O(n²/ε) entries, so the running time is O(n³/ε).
LP Rounding, Randomization, and Primal-Dual
- LP rounding: For weighted vertex cover, relax each xv ∈ {0,1} to 0 ≤ xv ≤ 1 with xu + xv ≥ 1 on every edge. Then round every x_v ≥ 1/2 up to 1. Each edge has at least one endpoint at 1/2 or more, so the result is a valid cover. Its cost is at most 2·LP ≤ 2·OPT.
- Randomized MAX-3SAT: Set each variable true with probability 1/2. A clause with three distinct variables fails with probability 1/8. By linearity of expectation, the assignment satisfies 7/8 of the clauses on average.
- Primal-dual: Raise dual variables until a primal constraint becomes tight, then add that element to the solution. Weak duality bounds OPT, so you never have to solve the LP.
Limits and Classes
A gap reduction maps yes-instances to OPT ≥ c and no-instances to OPT < s. An algorithm with a ratio better than c/s would then decide an NP-hard problem. The PCP theorem supplies such gaps. For example, MAX-3SAT has no (7/8 + ε)-approximation unless P = NP, so the random assignment above is the best possible.
| Class | Meaning | Example |
|---|---|---|
| FPTAS | poly(n, 1/ε) | Knapsack |
| PTAS | poly(n) for each fixed ε | Euclidean TSP |
| APX | some constant ratio | Vertex cover, MAX-3SAT |
Every APX-hard problem lacks a PTAS unless P = NP.
Exercise
Why does the knapsack FPTAS guarantee value at least (1 − ε)·OPT?
Show answer
Rounding loses less than K per item, so the total loss is at most nK = ε·vmax. Since OPT ≥ vmax (assuming each item fits by itself), the loss is at most ε·OPT.
Exercise
Why does MAX-3SAT have no PTAS unless P = NP?
Show answer
The PCP theorem shows that approximating MAX-3SAT beyond 7/8 + ε is NP-hard. A PTAS could reach any ratio close to 1, so it would contradict that result.