Sub topic 3
Proving Guarantees Without Knowing the Optimum
This chapter assumes you know the definition of the approximation ratio from the previous chapter. It also assumes you can read basic Python and follow a short proof by inequalities. Here is the central difficulty. A guarantee such as "ALG ≤ 2 · OPT" compares the algorithm's output with the optimal value OPT. For an NP-hard problem, we cannot compute OPT in polynomial time. If we could, we would not need an approximation. So we need a way to prove a ratio against a number we can never see.
The Sandwich Argument
The standard approach is to find a stand-in for OPT. This is a quantity that the analysis can reason about and that is guaranteed to sit on the correct side of OPT.
For a minimization problem, you find a lower bound LB that satisfies LB ≤ OPT for every instance. Then you prove ALG ≤ α · LB. Chaining the inequalities gives the guarantee:
ALG ≤ α · LB ≤ α · OPT.
For a maximization problem the directions flip. You find an upper bound UB ≥ OPT and prove ALG ≥ UB / α (or ALG ≥ ρ · UB for a ratio ρ < 1). Then ALG ≥ ρ · UB ≥ ρ · OPT.
OPT never appears in the core of the proof. It only shows up in the one inequality relating the bound to OPT, and that inequality is usually easy to justify.
A good analysis needs two things. The bound must be valid, meaning it really is on the correct side of OPT for every instance. It must also be tight enough, meaning the algorithm's output can be tied back to it with a small factor α.
Where Bounds Come From
Most analyses in this tutorial use one of a few families of bounds. The table previews them. Later chapters develop each one, so this chapter only names the source of the bound.
| Source of bound | Why it bounds OPT | Used later for |
|---|---|---|
| Total volume or average | Any solution must handle all the "mass" of the input | Makespan, bin packing |
| Largest single piece | Any solution must handle the biggest item somewhere | Makespan |
| Combinatorial structure | Every solution must pay for each part of a structure, such as each edge of a matching | Vertex cover |
| Relaxed problem | Dropping a constraint can only improve the optimum | Metric TSP (MST), LP rounding |
| Dual feasible solution | Weak LP duality bounds the primal optimum | Primal-dual, set cover |
The relaxation idea is the most general. If you remove constraints from a minimization problem, the feasible set grows, so its optimum can only go down. A minimum spanning tree is a relaxation of a tour: delete any edge of the optimal tour and you get a spanning tree, so MST ≤ OPT_TSP. A linear program that allows fractional values is a relaxation of the integer problem, so LP ≤ OPT.
Worked Example: Next Fit for Bin Packing
Bin packing is a clean example that the rest of the tutorial does not cover. You are given items with sizes in (0, 1] and must pack them into the fewest bins of capacity 1. The problem is NP-hard.
The Next Fit algorithm keeps one bin open. It puts each item into the open bin if the item fits. Otherwise it closes that bin for good and opens a new one.
Step 1: Choose a lower bound
Let S be the total size of all items. Each bin holds at most 1 unit, so any packing needs at least S bins, and since the number of bins is a whole number, at least ⌈S⌉ of them:
LB = ⌈S⌉ ≤ OPT.
This bound is valid for every instance, and computing it takes one pass over the input.
Step 2: Relate the algorithm to the bound
Suppose Next Fit uses k bins, B₁, …, Bk. Look at two consecutive bins Bi and B{i+1}. The first item of B{i+1} did not fit into B_i, so
load(Bi) + load(B{i+1}) > 1.
Group the bins into disjoint pairs (B₁, B₂), (B₃, B₄), and so on. There are ⌊k/2⌋ such pairs, and each pair holds more than 1 unit, so
S > ⌊k/2⌋ ≥ (k − 1) / 2.
Rearranging gives k < 2S + 1 ≤ 2⌈S⌉ + 1. Since k is an integer, k ≤ 2⌈S⌉ = 2 · LB ≤ 2 · OPT.
Next Fit is therefore a 2-approximation. The proof never mentions what an optimal packing looks like. It only uses the volume bound and one structural fact about the algorithm's output.
Step 3: Check the bound empirically
The code below runs Next Fit on random instances. For each one it computes the lower bound and finds the true optimum by brute force, which is feasible for 8 items. It checks the full sandwich LB ≤ OPT ≤ ALG ≤ 2 · LB. Exact fractions avoid floating-point errors in the capacity checks.
from fractions import Fraction as F
from math import ceil
import random
def next_fit(sizes):
bins = [[]]
load = F(0)
for s in sizes:
if load + s > 1:
bins.append([])
load = F(0)
bins[-1].append(s)
load += s
return bins
def optimal_bins(sizes):
items = sorted(sizes, reverse=True)
best = [len(items)]
loads = []
def place(i):
if len(loads) >= best[0]:
return
if i == len(items):
best[0] = len(loads)
return
for j in range(len(loads)):
if loads[j] + items[i] <= 1:
loads[j] += items[i]
place(i + 1)
loads[j] -= items[i]
loads.append(items[i])
place(i + 1)
loads.pop()
place(0)
return best[0]
rng = random.Random(1)
worst_vs_opt = F(0)
worst_vs_lb = F(0)
for _ in range(200):
sizes = [F(rng.randint(1, 10), 10) for _ in range(8)]
alg = len(next_fit(sizes))
lb = ceil(sum(sizes))
opt = optimal_bins(sizes)
assert lb <= opt <= alg <= 2 * lb
worst_vs_opt = max(worst_vs_opt, F(alg, opt))
worst_vs_lb = max(worst_vs_lb, F(alg, lb))
print("worst ALG/OPT:", float(worst_vs_opt))
print("worst ALG/LB: ", float(worst_vs_lb))
# Tight family: alternate 1/2 and a tiny item.
n, eps = 20, F(1, 100)
tight = [F(1, 2), eps] * n
alg = len(next_fit(tight))
lb = ceil(sum(tight))
print("tight instance: ALG =", alg, " LB = OPT =", lb, " ratio =", float(F(alg, lb)))The assertion never fails, because the proof guarantees it. The last instance shows the analysis is close to tight. Next Fit puts each 1/2 with one tiny item, so it uses 20 bins. An optimal packing pairs the halves into 10 bins and puts all 20 tiny items (total 0.2) into one more bin, for 11 bins. That equals LB = ⌈10.2⌉ = 11. As n grows, the ratio approaches 2.
The Bound Limits the Analysis
Any proof of the form ALG ≤ α · LB can show at best α ≥ OPT / LB on the worst instance. If your lower bound can be a factor g below OPT, then no analysis against that bound can prove a ratio better than g, however clever the algorithm.
For example, suppose you analyzed bin packing using only LB' = 1 (at least one bin is needed). That bound is valid, but OPT can be n times larger, so it proves nothing useful. The volume bound ⌈S⌉ is much better. Even so, OPT can exceed it: three items of size 0.6 have ⌈S⌉ = 2 but need 3 bins.
When the bound is a relaxation, this worst-case ratio OPT / LB has a name, the integrality gap. It comes back in the LP rounding chapter. The practical lesson: if an analysis seems stuck at some factor, check whether the bound itself is the obstacle before trying to improve the algorithm.
Common Errors
- Bounding in the wrong direction. For minimization you need LB ≤ OPT. An upper bound on OPT tells you nothing about how bad ALG is. For maximization you need UB ≥ OPT.
- Mixing up which side the algorithm is on. For minimization ALG ≥ OPT always holds, so the work is the upper inequality ALG ≤ α · LB. Proving ALG ≥ LB is trivially true and proves nothing.
- Using a bound that is too weak. A trivial bound such as "at least one bin" or "at least one vertex" is valid but makes α grow with the input size.
- Losing integrality steps. In the Next Fit proof, turning k < 2⌈S⌉ + 1 into k ≤ 2⌈S⌉ used the fact that k is an integer. Skipping or misusing such steps produces off-by-one errors in the stated ratio.
- Claiming tightness without an example. A proved bound of 2 does not mean the algorithm ever reaches 2. Only an explicit instance family shows that.
A Reusable Proof Template
- Name a quantity B and prove that B ≤ OPT (minimization) or B ≥ OPT (maximization) by reasoning about an arbitrary feasible solution.
- Find a structural property of the algorithm's output, such as "consecutive bins hold more than 1 unit."
- Use that property to prove ALG ≤ α · B (or ALG ≥ ρ · B).
- Chain the inequalities to get the ratio against OPT.
- Build an instance family where ALG / B approaches α, to show the analysis is tight.
The next four chapters apply this template with different bounds: a maximal matching for vertex cover, a pricing argument for set cover, average and maximum load for scheduling, and the minimum spanning tree for metric TSP.
Exercise
First Fit for bin packing places each item into the lowest-numbered open bin that has room, and opens a new bin only if no bin fits. Using LB = ⌈S⌉, prove that First Fit uses at most 2·⌈S⌉ bins. Hint: how many bins can be at most half full?
Show answer
At most one bin can have load ≤ 1/2 at the end. If two bins Bi and Bj with i < j were both at most half full, then every item in Bj has size ≤ 1/2 and would have fit into Bi when it arrived, and First Fit would have put it there. So of the k bins, at least k − 1 have load > 1/2, giving S > (k − 1)/2. Then k < 2S + 1 ≤ 2⌈S⌉ + 1, and since k is an integer, k ≤ 2⌈S⌉ ≤ 2·OPT.
Exercise
In the 0/1 knapsack problem (maximize the total value of the items you pick, subject to a weight limit), the fractional knapsack optimum F is found by sorting items by value/weight and allowing one item to be taken partially. Explain why F is a valid bound for analyzing an approximation algorithm, and say which direction it goes.
Show answer
Fractional knapsack is a relaxation, because it allows any amount between 0 and 1 of each item instead of only 0 or 1. Every 0/1 solution is also a fractional solution, so the fractional optimum is at least as large: F ≥ OPT. Knapsack is a maximization problem, so this is the correct direction. Proving ALG ≥ ρ·F then gives ALG ≥ ρ·OPT.
Exercise
A student proves that an algorithm for a minimization problem satisfies ALG ≤ 3·B, where B is a lower bound on OPT, and observes that on some instances OPT = 3·B. Can a different analysis against the same bound B prove ALG ≤ 2·OPT?
Show answer
No. On those instances ALG ≥ OPT = 3·B, so no proof of the form ALG ≤ 2·B can hold for them. A better ratio against OPT might still be true, but proving it requires a stronger bound than B.