Lecture 4.1: Design Methods I
Catalogue of randomized-design methods; the first beats the worst case by randomizing the strategy. Paging k-hard; two-job scheduling 9/8-hard deterministically but →1 randomized; Yao's principle.
Last updated 27 June 2026
Lecture 4 (part 1) — Eliminating the Adversary
Course 2-INF-135/15 Pravdepodobnostné algoritmy, LS 2025/26. Source slides:
04_metody1.pdf(12 pages) + start of04_metody23.pdf(slides 1–4).
Where we are: the methods block
Lectures 1–3 built individual algorithms and then the complexity-class scaffolding (RP, BPP, ZPP, …). Now begins the methods block — the recurring tricks that keep producing randomized algorithms. The whole catalogue, in one breath:
| Method (Slovak) | Idea | Examples |
|---|---|---|
| Eliminating the adversary (eliminácia protihráča) | Randomly choose the strategy/element that drives the computation, so the worst case becomes unlikely → focus on expected cost. | DB equality, QuickSort, universal hashing, online problems |
| Fingerprints (odtlačky) | Replace comparing complex objects by comparing simpler fingerprints. | databases, hashing, Freivalds |
| Error reduction by repetition (znižovanie chyby) | Amplify confidence — but sometimes it is smarter not to repeat the whole computation. | (recurring throughout) |
| Witnesses (svedkovia) | Randomly hunt for a witness that confirms/refutes a property. | primality — a divisor witnesses compositeness |
| Optimization + random rounding | Relax a discrete problem ( |
LP-rounding |
| Random walks (náhodné prechádzky) | Find an object with a property by walking randomly through the object space. | 2-SAT walk, s-t connectivity |
This part of the lecture is entirely the first method, applied to its most striking arena: online problems.
1. The core idea — eliminating the adversary
By randomly choosing the strategy (or the element) that steers a computation, the worst case stops being a fixed target the adversary can aim at. We trade worst-case guarantees for expected-case ones — and that trade is often a landslide win.
The mental model is a game: you (the algorithm) move, an adversary picks the input to hurt you most. A deterministic algorithm is fully predictable, so the adversary can compute your single worst input in advance and hand it to you. A randomized algorithm makes a coin-flip the adversary cannot see — so it cannot tune one input to be bad for all your possible coin outcomes. The adversary is eliminated not by being beaten head-on, but by being denied a fixed target.
Online problems — the natural battlefield
In an online problem the input is not given all at once. It dribbles in:
and you must irrevocably react to
Competitive ratio — grading an online algorithm
We compare an online algorithm
- For a minimization problem (paging, scheduling: smaller cost is better) this is
just
— how many times worse than optimal you are. - For a maximization problem (selection: bigger value is better) people instead say
is -competitive if with — how large a fraction of optimum you secure. (Watch this flip of convention; both appear in this very lecture.)
-hard problem (δ-ťažký): a problem with no -competitive algorithm for any . In words, is a barrier — a proven floor on how good ANY online algorithm can be. Proving -hardness means: for every algorithm there is an input that drags its ratio up to . That “for every , there exists a bad ” is the adversary talking.
Two flavours of “probabilistic approximation”
For a randomized online algorithm
is probabilistic -approximation if (Expected ratio is good.)is probabilistic -approximation if (Ratio is good at least half the time — then amplify.)
Both demand a correct (feasible) answer with probability 1; only the quality is random. This is the online analogue of a Las Vegas algorithm.
2. Warm-up: Paging is -hard
The problem
A cache (cash) of size
Claim. Paging is
-hard: no deterministic online algorithm is better than -competitive.
The adversary’s construction
There are
Always request the page the algorithm just evicted (equivalently, the one page currently not in cache).
Then the online algorithm faults on every single request. Walk it through with
| request | online cache (faults every step) | optimal offline (1 fault per block) |
|---|---|---|
| start | {1,2,3,4} |
{1,2,3,4} |
| 5 | fault → evict 3 → {1,2,5,4} |
fault → evict 4 → {1,2,3,5} |
| 3 | fault → evict 1 → {3,2,5,4} |
hit ✓ |
| 1 | fault → evict 2 → {3,1,5,4} |
hit ✓ |
| 2 | fault → evict … → {3,1,5,?} |
hit ✓ |
The online algorithm pays
The deep point
The offline optimum is Bélády’s rule: evict the page whose next use is furthest in the future. The online algorithm cannot run it because it does not know the future — and the adversary weaponizes exactly that ignorance. The gap is fundamentally about information, not cleverness.
Punchline. Determinism online is hopeless here: a
-fold gap, and is the whole cache. (Randomization — the “marking algorithm” — later cuts this to ; that is the payoff of eliminating the adversary, though it is beyond this slide.)
3. The main event: two-job scheduling
This example is the heart of the lecture, because it shows the whole arc: a deterministic lower bound, a deterministic upper bound, a hardness theorem, and then a randomized algorithm that smashes through the deterministic barrier.
Setup
types of machines . - A job = a permutation of machine indices: the order in which it wants to visit the machines. Each visit takes 1 time unit.
- For simplicity the input is 2 jobs:
Jobvisits machines in order ; job in the order .
Two jobs collide when they want the same machine at the same time — one must wait. A machine serves one job at a time.
The schedule as a lattice path
Picture an
advance only ( waits this tick), advance only ( waits), advance both in one tick — allowed only when their next machines differ, (no collision, so they truly run in parallel).
A collision cell is one where
Cost. The time is the number of ticks. With
diagonal steps you spend . Writing for the number of collisions your path was forced through, The ideal is (all diagonal, perfect parallelism); every unavoidable collision adds 1.
Crucial counting fact. Each machine
3a. Deterministic lower bound:
The adversary builds
- start
(immediate collision); - whenever
resolves a collision by going , set ; - whenever
goes , set , where = number of ’s so far.
Whichever way
So every deterministic online algorithm can be pushed to
3b. Deterministic upper bound:
Now the offline side — how good is the best schedule (it may inspect all of
The averaging argument (this is the elegant part). Each of the
Add up the total excess over the ideal
So the average excess over the
Since some strategy is no worse than the average, there exists one with
The averaging trick (“there exists one no worse than the average”) is the probabilistic method in miniature — and it is the bridge to the randomized algorithm below.
3c. Hardness: the problem is -hard
Combine the two bounds. The lower bound gives a bad instance with
No deterministic online algorithm beats
. A hard, fixed floor — because a deterministic algorithm is a fixed target.
3d. The randomized algorithm DIAG — through the barrier
DIAG: pick
uniformly, then run strategy .
That is the entire algorithm: a random diagonal. The analysis is just the averaging
argument re-read as an expectation. Because the
Using the trivial
Punchline. Deterministic is stuck at
; randomized DIAG drives the expected ratio all the way to . Same strategies, the only change is choosing which diagonal at random. The adversary built its trap assuming it knew your diagonal — randomizing the diagonal eliminates that knowledge, and the forced delay collapses from down to . This is “eliminating the adversary” in its purest form.
4. The selection problem and Yao’s minimax principle
The problem (the secretary problem in disguise)
Values
Result 1 — determinism is worthless: no deterministic algorithm beats
- If
takes : feed input . Then but holds , ratio . ✗ - If
passes : feed input . The only good value is gone; ends with , ratio . ✗
A deterministic algorithm’s decision on seeing “
Result 2 — a trivial randomized algorithm is
Yao’s minimax principle
Yao (for minimization). Let
be a random variable over deterministic algorithms , and a random variable over inputs . Then
Read it as a sentence: the best randomized algorithm’s cost on its worst input is at least the best deterministic algorithm’s cost against a (well-chosen) random input. This is the workhorse for lower bounds on randomized algorithms, and it makes them easy: instead of reasoning about all possible coin-flip distributions, you just
- invent one input distribution
(your choice — make it nasty), and - show every deterministic algorithm is expensive on average against it.
That number is then a valid lower bound for every randomized algorithm.
Proof — two one-line inequalities. With
$$
\begin{aligned}
\max_{x} E[c(A,x)]
&= \max_{x} \sum_{a} \Pr[A{=}a],c(a,x) \
&\ge \sum_{x} \Pr[X{=}x] \sum_{a} \Pr[A{=}a],c(a,x)
&& \text{(a max is
The two steps are just “max
average” and “average min.” That is all Yao is — yet it is exactly von Neumann’s minimax / LP duality for the zero-sum game you vs. the input. For a maximization problem, set to flip it:
Applying Yao: you cannot select the maximum with probability
Work over values
= the position at which selects (if it never selects, ), iff selected the maximum.
We want
A random-length increasing prefix, then zeros. Take any deterministic
- if
: the prefixes and agree up to position , so selects the same position — and that is the maximum of iff (the peak sits at ); - if
: by then is in the all-zeros tail, so it selects a — never the max.
Either way,
So
Why the increasing prefix is diabolical. When the algorithm stands at position
seeing value , it cannot tell whether the sequence stops here ( , so this is the max) or keeps climbing ( , more is coming). Every position looks identically tempting — that ambiguity is precisely what caps it at . (Oral-exam nuance.) This is the select-the-exact-maximum version. The classic secretary problem reaches
— but that relies on a uniformly random arrival order and rank comparisons; Yao’s adversary is allowed to choose this particular non-uniform monotone distribution, against which no strategy beats .
Competitive version: no randomized algorithm is -competitive for
The “probability of hitting the max” bound upgrades to a competitive-ratio bound by scaling the values exponentially so that missing the max is nearly worthless.
Suppose
Competitiveness says
Choosing
No randomized online algorithm for selection is
-competitive for . The trivial “pick a random position” algorithm is essentially optimal.
Punchline of Yao. A lower bound over all randomized algorithms — a quantifier over infinitely many coin-flip distributions — collapses into analyzing deterministic algorithms against one input distribution you design. Hard becomes easy because the design freedom moves to your side of the game.
Recurring themes from this part
| Theme | Where it appeared |
|---|---|
| Eliminate the adversary = deny it a fixed target by randomizing your strategy | DIAG (§3d), random-position selection (§4) |
| Online ⇒ the cost of not knowing the future | paging vs. Bélády (§2), scheduling lower bound (§3a) |
| Averaging / probabilistic method (“ |
scheduling upper bound (§3b) → DIAG (§3d) |
| Deterministic barrier, randomized breakthrough (9/8 → 1) | scheduling (§3) |
| Yao’s minimax (randomized lower bound ⇐ deterministic-vs-random-input) | selection (§4) |
| Exponential value-scaling to turn “hit the max” into a competitive ratio | selection competitive bound (§4) |
The one sentence tying it together:
A deterministic online algorithm is a fixed target the adversary aims at; a coin flip the adversary cannot see turns the worst case into a merely unlikely case — and Yao’s principle tells us exactly how far that trick can ever go.