Theoretical Computer Science for ML
Complexity, hardness, and approximation set what learning can guarantee, so theory draws the boundary efficient algorithms cannot cross.
Why Does This Exist?
ML practice optimizes without asking what is optimizable: gradient methods attack objectives whose exact minimization is NP-hard, and nobody blinks. Theoretical computer science for ML draws the map so that confidence lands in the right place: which learning tasks admit efficient exact algorithms, which are hard even approximately, and which surrender to approximation, sketching, or cryptographic assumptions. The children each own one region: complexity classes for P and NP, hardness of learning for proper versus improper barriers, cryptographic assumptions for average-case hardness, approximation for guarantees on hard objectives, and sketching for sublinear data. Runtime counting for accelerators is complexity for ML.
The one idea you need first
A reduction converts problem A into problem B efficiently, so B is at least as hard as A: an efficient solver for B would solve A too. Hardness flows along reductions; algorithms must route around where reductions point.
Think of It Like This
A harbor chart with reefs and channels
Sailors chart reefs (provably hard zones), channels (efficient routes), and tidal shortcuts (approximations that work when exact passage is blocked). Nobody sails by staring at one reef; they read the whole chart, then pick a route whose guarantees match the cargo.
TCS is that chart for learning tasks. Complexity classes mark the reefs, reductions draw the currents connecting them, approximation marks the channels that admit heavy cargo with slight delay, and sketching marks the shallow passages for light boats. Practice sails daily; theory keeps the chart honest.
How It Actually Works
Complexity sorts decision problems: P (efficiently solvable), NP (efficiently checkable), NP-complete (hardest in NP, all equivalent via reductions). Learning hardness asks about concept classes: properly learning parities with noise is as hard as decoding random linear codes; improperly, richer hypotheses sometimes bypass the barrier. Cryptography bases average-case hardness on assumptions (factoring, LWE) that learning lower bounds inherit. Approximation guarantees near-optimal values on NP-hard objectives (a share for submodular maximization). Sketching compresses data to sublinear summaries with geometry preserved.
Worked example
Imagine selecting training points from to maximize a submodular coverage score. Exact search over subsets is hopeless (NP-hard). Greedy adding (best marginal gain each step) guarantees of optimum: if the optimum covers concepts, greedy covers at least . A CountSketch of width estimates all point norms within to drive the greedy picks in one pass. Three regions of the map combine on one task: hardness says exact is out, approximation guarantees the greedy share, sketching fits the data in memory.
Code
def greedy_cover(values: list[float], k: int) -> tuple[list[int], float]: picked, total = [], 0.0 remaining = set(range(len(values))) for _ in range(k): nxt = max(remaining, key=lambda i: values[i]) # best marginal gain picked.append(nxt) total += values[nxt] remaining.discard(nxt) return picked, round(total, 1)
vals = [90.0, 85.0, 80.0, 20.0, 15.0]print(greedy_cover(vals, 2)) # -> ([0, 1], 175.0)Top- picks total : the greedy share on a tiny instance where the guarantee is overkill but visible.
Watch Out For
Reading worst-case hardness as typical-case impossibility
NP-hardness constrains the worst input; real data (clustered, smooth, margin-separated) often admits fast exact or near-exact methods. Teams that abandon principled optimization on hardness slogans alone leave guaranteed performance unclaimed. Check average-case and structured-input results before switching to heuristics.
Assuming approximation ratios transfer across objectives
The submodular guarantee evaporates for non-submodular scores (diversity with repulsion, supermodular coverage): greedy can score arbitrarily badly there. Verify submodularity (diminishing returns) on your objective before quoting the ratio.
The Quick Version
- TCS maps efficient, hard, approximable, and sketchable learning tasks on one chart.
- Reductions transfer hardness; algorithms route around the reef lines.
- Greedy submodular selection guarantees of optimum: of concepts in the example.
- Sketching compresses the -point search to a -wide summary within .
- Worst-case hardness rarely bars structured real data; check average-case results.
- Approximation ratios need their structural premise (submodularity) verified per objective.