Sub topic 10
Approximation Schemes: Trading Accuracy for Time
The earlier chapters each gave one fixed guarantee: 2 for vertex cover, H_n for set cover, 4/3 for LPT scheduling. If you need a solution within 1% of optimal, none of those algorithms can provide it. An approximation scheme is a family of algorithms with a dial on it. You choose an error tolerance ε > 0, and the scheme returns a solution within a factor (1 + ε) of optimal. Smaller ε costs more running time. This chapter defines the two main kinds of scheme, works through a complete one for makespan scheduling, and explains why some problems can have the faster kind while others cannot.
This chapter assumes you know approximation ratios for minimization and maximization problems, the list scheduling and LPT analysis from the scheduling chapter, and the difference between NP-hardness and strong NP-hardness.
Definitions
An approximation scheme takes two inputs: an instance I of size n, and an accuracy parameter ε > 0.
- For a minimization problem it returns a solution of cost at most (1 + ε) · OPT(I).
- For a maximization problem it returns a solution of value at least (1 − ε) · OPT(I). Some textbooks write OPT/(1 + ε) instead. The two forms are interchangeable up to rescaling ε.
The schemes are classified by how their running time depends on ε:
- A PTAS (polynomial-time approximation scheme) runs in time polynomial in n for every fixed ε. The dependence on 1/ε can be anything, such as n^(1/ε) or 2^(2^(1/ε)) · n.
- An EPTAS (efficient PTAS) runs in time f(1/ε) · n^c, where c is a constant that does not depend on ε. The function f can be exponential, but ε is kept out of the exponent of n.
- An FPTAS (fully polynomial-time approximation scheme) runs in time polynomial in both n and 1/ε, for example O(n³/ε).
Each class contains the next one: every FPTAS is an EPTAS, and every EPTAS is a PTAS. Any PTAS also gives a constant-factor approximation, since you can fix ε = 1 and get a 2-approximation.
The differences matter in practice. The table shows rough operation counts for n = 1000 and ε = 0.1.
| Scheme type | Example running time | Operations at n = 1000, ε = 0.1 |
|---|---|---|
| PTAS | n^(1/ε) | 10^30 |
| EPTAS | 2^(1/ε) · n | about 10^6 |
| FPTAS | n² / ε | 10^7 |
The PTAS in the first row meets the definition but is useless at this accuracy. "Polynomial for each fixed ε" says nothing about the size of the exponent.
The Common Design Pattern
Most approximation schemes follow the same three steps:
- Split the input. Separate the "large" parts, which strongly affect the objective, from the "small" parts.
- Solve the large parts exactly. Use brute force or dynamic programming. The number of large parts, or the number of distinct values they can take, is bounded by a function of 1/ε.
- Handle the small parts cheaply, with greedy or rounding, and show that the error they add is at most ε · OPT.
The threshold between large and small parts is what makes accuracy cost time. A smaller ε means more parts count as large, so the exact step gets more expensive.
A PTAS for Makespan on a Fixed Number of Machines
The scheduling chapter showed that list scheduling achieves a ratio of 2 − 1/m. Graham (1969) refined it into a scheme. Sort the jobs in decreasing order, schedule the k largest jobs optimally by trying every assignment, and then add the remaining jobs one at a time to the least-loaded machine.
import heapq
import itertools
import math
def ptas_makespan(jobs, m, eps):
jobs = sorted(jobs, reverse=True)
k = min(len(jobs), math.ceil(m / eps))
large, small = jobs[:k], jobs[k:]
# Step 2: try all m^k assignments of the large jobs.
best_loads = None
for assign in itertools.product(range(m), repeat=k):
loads = [0] * m
for p, i in zip(large, assign):
loads[i] += p
if best_loads is None or max(loads) < max(best_loads):
best_loads = loads
# Step 3: list-schedule the small jobs greedily.
heap = [(load, i) for i, load in enumerate(best_loads)]
heapq.heapify(heap)
for p in small:
load, i = heapq.heappop(heap)
heapq.heappush(heap, (load + p, i))
return max(load for load, _ in heap)
jobs = [7, 5, 4, 3, 3, 2]
print(ptas_makespan(jobs, 2, 0.5)) # k = 4
print(ptas_makespan(jobs, 2, 0.2)) # k = 6, all jobs are largeThe first call prints 14 and the second prints 12. The optimum is 12, for example {7, 5} and {4, 3, 3, 2}. With ε = 0.5, the four largest jobs are placed optimally as {7, 3} and {5, 4}. The greedy step then has no good place for the remaining 3, 3 and 2, so the result is 14/12 ≈ 1.167 times optimal. With ε = 0.2, every job counts as large and brute force finds the optimum.
Why the guarantee holds
Let p₁ ≥ p₂ ≥ … ≥ p_n be the job sizes and let C be the algorithm's makespan. Look at the job j that finishes last.
- Case 1: j is a large job. Adding the small jobs did not raise the maximum load, so C equals the optimal makespan for the large jobs alone. That value is at most OPT, because the large jobs are a subset of the full instance.
- Case 2: j is a small job. As in the list scheduling proof, job j started on the least-loaded machine, so its start time was at most (Σp − pj)/m. This gives C ≤ Σp/m + (1 − 1/m) · pj ≤ OPT + (1 − 1/m) · p{k+1}, because a small job is no larger than p{k+1}.
The remaining step bounds p{k+1} using OPT. The k + 1 largest jobs all have size at least p{k+1}, and some machine must receive at least ⌈(k+1)/m⌉ of them. So OPT ≥ ⌈(k+1)/m⌉ · p_{k+1}. Substituting into Case 2:
C ≤ OPT · (1 + (1 − 1/m) / ⌈(k+1)/m⌉).
With k ≥ m/ε, the added term is less than m/(k+1) < ε, so C ≤ (1 + ε) · OPT. For the first run (m = 2, k = 4), the bound is 1 + 0.5/3 = 7/6. The observed result 14/12 equals 7/6 exactly, so the analysis is tight for this instance.
Running time
The brute-force step tries m^k = m^⌈m/ε⌉ assignments. Sorting and the heap add O(n log n). For a fixed m and a fixed ε, m^⌈m/ε⌉ is a constant, so the scheme is a PTAS. It is not an FPTAS, because the time grows exponentially in 1/ε. It also requires m to be fixed: if m is part of the input, m^(m/ε) is no longer polynomial. Hochbaum and Shmoys (1987) gave a PTAS that works even when m is part of the input, but they did it by rounding job sizes, not by enumerating assignments.
When an FPTAS Is Impossible
The next chapter builds an FPTAS for 0/1 knapsack. Makespan with m in the input has no FPTAS unless P = NP. The difference comes from strong NP-hardness.
Suppose the objective is always an integer and OPT ≤ q(n, U), where U is the largest number in the input and q is a polynomial. Run an FPTAS with ε = 1/(q(n, U) + 1). The returned cost is at most (1 + ε) · OPT < OPT + 1. Since costs are integers, the result equals OPT. The running time is polynomial in n and q(n, U), which makes it a pseudo-polynomial exact algorithm.
A strongly NP-hard problem stays NP-hard even when all numbers in the input are bounded by a polynomial in n. For such a problem, a pseudo-polynomial algorithm would solve it in polynomial time, which would mean P = NP. This gives the following rule:
The step from PTAS to "no scheme at all" is covered in the chapters on hardness and approximation classes. APX-hard problems such as metric TSP and vertex cover have no PTAS unless P = NP.
Common Errors
| Mistake | Correction |
|---|---|
| Calling an n^(1/ε) algorithm an FPTAS | An FPTAS must be polynomial in 1/ε. Here 1/ε appears in the exponent of n, so it is only a PTAS. |
| Using the (1 + ε) form for a maximization problem | For maximization, the guarantee is value ≥ (1 − ε) · OPT. Check which convention your source uses. |
| Treating m, a dimension, or another parameter as fixed without saying so | The scheme above is polynomial only when m is fixed. State every parameter that is assumed constant. |
| Assuming a PTAS is practical | Check the actual exponent and constants. Many PTASs exist only to classify a problem's complexity. |
| Bounding the small-part error against something other than OPT | The added error must be at most ε · OPT, which is usually shown with a lower bound such as Σp/m or ⌈(k+1)/m⌉ · p_{k+1}. |
Exercise
In ptas_makespan with m = 3 machines, what value of k is used for ε = 0.25, and how many assignments does the brute-force step try (assuming n ≥ k)? Is this PTAS an EPTAS when m is fixed?
Show answer
k = ⌈3 / 0.25⌉ = 12, so the loop tries 3^12 = 531,441 assignments. With m fixed, the running time is m^⌈m/ε⌉ + O(n log n), which has the form f(1/ε) + poly(n). The exponent of n does not depend on ε, so it is an EPTAS (but not an FPTAS, since f grows exponentially in 1/ε).
Exercise
Bin packing asks for the minimum number of unit-capacity bins that can hold items of given sizes. The answer is an integer at most n. Explain why bin packing has no FPTAS unless P = NP. Use only the facts that the optimum is at most n and that deciding whether 2 bins suffice is NP-hard.
Show answer
Run the FPTAS with ε = 1/(n + 1). It returns at most (1 + ε) · OPT < OPT + OPT/(n + 1) ≤ OPT + 1 bins. The count is an integer, so it equals OPT. The running time is polynomial in n and 1/ε = n + 1, so we would solve bin packing exactly in polynomial time. That includes the NP-hard question of whether 2 bins suffice, so P = NP. (The same argument shows bin packing has no approximation ratio below 3/2: when OPT = 2, any answer below 3 must be 2.)
Exercise
Prove the lower bound OPT ≥ ⌈(k+1)/m⌉ · p{k+1} used in the makespan analysis, and explain why OPT ≥ (k+1) · p{k+1} / m alone would also be enough to get a (1 + ε) guarantee.
Show answer
Each of the k + 1 largest jobs has size at least p{k+1}. By the pigeonhole principle, some machine in any schedule, including the optimal one, receives at least ⌈(k+1)/m⌉ of them, so its load is at least ⌈(k+1)/m⌉ · p{k+1}. That load is at most OPT. The weaker bound follows because ⌈x⌉ ≥ x. Using it, the added term is at most (1 − 1/m) · p_{k+1} ≤ (1 − 1/m) · m · OPT / (k+1) < m · OPT / (k+1). This is at most ε · OPT when k + 1 ≥ m/ε, which k = ⌈m/ε⌉ satisfies.