Approximation Algorithms
For NP-hard objectives, polynomial methods with proven fractions of optimal beat exact search that never finishes.
Why Does This Exist?
Exact data selection, clustering, and routing are NP-hard at ML scales, yet decisions must ship. Approximation algorithms run in polynomial time with proven ratios: the answer is always within a stated fraction of optimal (maximization) or factor above it (minimization). The ratio replaces hope with bookkeeping: a guarantee on a -concept coverage problem certifies regardless of instance. Hardness context is P versus NP; sublinear data access is sketching.
The one idea you need first
An -approximation for maximization returns value at least with (for minimization, at most with ). Smaller above one (minimization) or larger below one (maximization) is better; a PTAS approaches in polynomial time per fixed accuracy.
Think of It Like This
Packing a moving truck against the clock
The movers cannot try every loading order: the truck leaves in an hour. They place the bulkiest fitting box first, then the next, never unloading. The truck fills to a proven share of the best packable volume because each placement captures at least its fair fraction of the remaining gap.
Exact packing (try every order) is the exponential search; greedy loading is the approximation. The guarantee is the lease with the customer: whatever the optimal pack, this truck carries a certified fraction. Different cargo (fragile, nested) needs different rules, which is why ratios come with structural premises.
How It Actually Works
Greedy submodular maximization. For monotone submodular (diminishing returns) with cardinality , iteratively add the element with largest marginal gain. Guarantee: of optimal (Nemhauser). LP rounding. Solve the linear relaxation, round fractionally: vertex cover via maximal matching gives factor ; metric TSP via MST doubling gives (Christofides). Schemes. Knapsack has an FPTAS: -optimal in time polynomial in and .
Tightness: the greedy is best possible for submodular maximization with value queries alone (information-theoretic wall), so beating it needs more structure.
Worked example
Cover reachable concepts with sensors, each sensor covering a known subset. Optimum . Greedy picks: new concepts per step (diminishing, as submodularity predicts), totaling . Certificate delivered with greedy steps against exact search. Vertex-cover twin: maximal matching of edges certifies a cover of vertices against optimum at least : factor in one line.
Code
def greedy(values: list[list[float]], k: int) -> float: covered, total = set(), 0.0 pool = [set(v) for v in values] # each sensor's concept set for _ in range(k): nxt = max(pool, key=lambda s: len(s - covered)) # best marginal gain total += len(nxt - covered) covered |= nxt return total
sensors = [{i} for i in range(10)] + [{0, 1, 2}]print(greedy(sensors, 2)) # -> 2.0 (two fresh singletons beat the triple)Marginal-gain picks total : the diminishing-returns rule choosing breadth over overlap.
Watch Out For
Quoting 0.63 for non-submodular scores
With repulsion or synergy between picks (diverse batches, interacting features), marginal gains need not diminish and greedy can score arbitrarily poorly. Test diminishing returns on your objective (pairwise swap checks) before certifying anything.
Rounding LPs without checking integrality gaps
A relaxation with a large integrality gap caps every rounding scheme: the fractional optimum itself is far above integer OPT, so no rounding recovers the ratio you hoped. Compute the gap on small instances first; reformulate (stronger cuts) when it yawns.
The Quick Version
- Approximation certifies fractions of optimal in polynomial time on NP-hard tasks.
- Greedy submodular maximization guarantees ; the example reaches of .
- Vertex cover rounds to factor ; metric TSP tours to ; knapsack admits an FPTAS.
- The is information-theoretically tight for value-query methods.
- Verify diminishing returns before quoting greedy ratios.
- Check integrality gaps before designing rounding schemes.