Lecture 3: Models & Complexity Classes
Las Vegas vs Monte Carlo, the amplification gap that splits BPP from PP, the class zoo (RP/ZPP/PP/BPP), and why a weak δ-random source is secretly as good as a perfect one.
Last updated 27 June 2026
Lecture 3 — Models of Probabilistic Computation & Complexity Classes
Course 2-INF-135/15 Pravdepodobnostné algoritmy, LS 2025/26. Source slides:
03_slidy.pdf(28 pages).
What this lecture is about
Lectures 1–2 built and analysed randomized algorithms. This lecture steps back and asks the structural questions:
- Where can the randomness sit, and what kind of error does it cause? (Two ways to classify every randomized algorithm.)
- How do we drive the error down? (Repetition + majority — and the one
number, the gap
, that decides whether this is cheap or ruinously expensive.) - Which complexity classes do these algorithms define? (RP, coRP, ZPP, PP, BPP — their definitions, the lemmas that make them robust, and how they nest.)
- What if our coins are bad? (A weak random source — biased and
correlated — can wreck an algorithm; yet we will prove that for
BPPit makes no difference at all.)
The single thread running through all of it: a randomized algorithm is a
deterministic algorithm plus a string of coin flips
1. Two ways to place the randomness
There are two equally valid pictures of where the probability lives.
Model I — a distribution over deterministic strategies.
We have a fixed pool of deterministic algorithms
Picture: roll a die once, then follow the rulebook it selected. The only randomness is the initial choice of strategy. Examples: the database equality test
(the random choice is which position to probe), Freivalds’ (random vector).
Model II — a nondeterministic algorithm with a distribution over its choices. The algorithm branches as it runs, and each branch point is resolved by a coin flip. Randomness is used repeatedly, throughout the computation.
Picture: flip a fresh coin every time the algorithm reaches a fork. Example: randomized QuickSort re-randomizes the pivot at every level of recursion.
The two models have the same power (Model II’s coin-flip choices, read off in
order, are a long random string — exactly the
2. Classification by error: Las Vegas vs Monte Carlo
Let
| Type | Promise | Errs on… | Example |
|---|---|---|---|
| Las Vegas | never (only time is random) | boss-election, R-Select / Lazy-Select | |
| Monte Carlo, one-sided | only on yes-instances | database equality test | |
| Monte Carlo, two-sided | either direction (but biased right) | database inequality test |
The three differ in what they promise:
- Las Vegas never lies. It is always correct; randomness only affects how long it runs (we engineer a good expected time). “I’ll always give you the right answer — I just can’t promise exactly when.”
- One-sided Monte Carlo lies in one direction only. A “yes” is the truth; a “no” might be a miss. (For the equality test: if it ever finds a differing bit it is certain the strings differ; if it sees a match it can only guess they are equal.)
- Two-sided Monte Carlo can be wrong either way, but it is biased toward
the truth — correct with probability strictly above
.
Why the
matters so much. “ ” is not cosmetic. The whole machinery of §4 and the gulf between BPPandPPin §6 turn on whether thatis a constant or is allowed to shrink to as the input grows. Keep your eye on the gap.
3. A worked two-sided example: testing
The cleanest illustration. Computer
Protocol.
Communication cost:
Correctness — check both kinds of input. The worst case for detecting a difference is when the strings differ in exactly one position, $\exists! j: x_j \neq y_j$ (fewest chances to catch it), so we analyse that.
(so , correct answer = reject). Every probe finds , so we always fall into the coin branch and reject with (so , correct answer = accept). With probability we hit the one differing position and accept outright; with probability we hit a matching position and accept via the coin (prob. ):
The point. A single probe and a tiny engineered bias (
) are enough to beat in both directions. That is precisely a two-sided-error Monte Carlo algorithm — correct with probability on every input. The gap here ( ) is not constant, which (foreshadowing §6) is exactly the kind of vanishing gap that lands a problem in PPrather thanBPP.
4. Driving the error down by repetition
4a. Las Vegas has two faces, and they are interchangeable
There are two ways to define Las Vegas, and proving them equivalent is a tiny gem that reuses Markov’s inequality from Lecture 2.
- “Never lies, may shrug”:
outputs or $A^?(x) =
\ ?$ (“don’t know”), with. - “Always correct, random time”:
.
Deep point. “Always right but slow sometimes” and “fast but occasionally admits ignorance” are the same class, convertible for a factor of
. Markov is the bridge from the random-time form to the shrug form — the very same “restart on FAIL, ” move that made R-Select linear in Lecture 2.
4b. Bounded two-sided error: a constant number of repetitions
Suppose
The elementary bound (no Chernoff needed). Write $p(1-p) = (\tfrac12 +
\varepsilon_x)(\tfrac12 - \varepsilon_x) = \tfrac14 - \varepsilon_x^2$. For a
losing term (
Set the target error
The headline. If
and are constants, then is a constant. A bounded-error algorithm can be amplified to any fixed confidence with repetitions — this is exactly what makes BPPa well-behaved class. (Pushand you still only pay repetitions, because the denominator is a constant.)
4c. Unbounded error: the gap can cost you everything
Now suppose
The single most important contrast in this lecture. The amplification formula is the same; only the gap
changes.
- Constant gap (bounded away from
) constant amplification the friendly class BPP.- Vanishing gap (may approach
) exponential amplification the monstrous class PP(which, we’ll see, contains all ofNP).Everything separating
BPPfromPPis whether the gap is bounded.
5. The complexity classes
All classes below use polynomial-time probabilistic Turing machines (PTMs). They differ only in the promise on yes- and no-instances.
RP — one-sided error, “yes” is trustworthy
RPNP. A random stringon which accepts is exactly an NPwitness — this is the “guess = certificate” equivalence from the NP session, read through randomness: whereNPguesses a good, RPsamples one and succeeds with decent probability.- Robustness lemma.
iff the threshold can be replaced by for any polynomial . The reason is one-sided amplification: a no-instance can never produce a false yes, so independent runs with an OR vote err only if all miss: and more runs push it below any. So any polynomially-small success probability is as good as for RP.
coRP is the mirror image: errs only on no-instances (“no” is trustworthy,
“yes” might be a false alarm). coRP coNP.
ZPP — zero error (the Las Vegas class)
- Lemma (the Las Vegas characterisation).
iff there is a PTM with That is exactly the “never lies, may shrug” Las Vegas machine of §4a. (build the shrug machine from the two one-sided machines): run the RPmachineand the coRPmachine— if M(x) = 1 then accept // RP says yes ⇒ truly yes else if coM(x)=1 then reject // coRP says no ⇒ truly no else return ? // neither was sure(recover the two one-sided machines from ): turn “ ” into reject to get an RPmachine, and into accept to get acoRPmachine.
Deep point.
RPerrs one way,coRPthe other; intersecting them cancels both error directions and leaves no error at all — only an occasional “don’t know”, i.e. extra expected time. ZPP = zero-error = Las Vegas. The intersection of two opposite one-sided errors is honesty.
PP — unbounded two-sided error
The threshold is just a strict
NPPP. Take anNPmachine and graft on an equal-sized always-accepting subtree of computations. If there was even one accepting path, the accepting fraction now tips just over; if there were none, it stays at exactly . The tip can be a single path out of — a vanishing gap, which is exactly what PPtolerates.PPPSPACE. Simulate the machine and count accepting computations in polynomial space (reuse the space across the exponentially many branches — the space-reuse principle).
PPis essentially a counting class (it can detect a strict majority of an exponential tree). Its power comes entirely from the unbounded gap; the moment you demand a constant gap you drop toBPP.
BPP — bounded two-sided error (the practical class)
(Any constant
- Lemma.
iff there is a PTM with for some polynomial — i.e. the error is amplifiable to exponentially small. By §4b with , , this costs only repetitions. A polynomial number of runs buys exponentially tiny error.
This is the class of randomized algorithms we actually trust: constant gap, amplifiable to astronomically small error for free.
BPP ⊆ P/poly (Adleman’s theorem)
A BPP language can be decided by polynomial-size circuits — one fixed
“advice string” per input length works for all inputs of that length.
Proof (probabilistic method on the coins, with a union bound over inputs).
First amplify so a single run errs with probability
Same engine as the non-uniform derandomization tool (Adleman,
RPP/poly). Amplify until the bad-fraction is below, union-bound over the inputs, conclude one random string is good for all of them, and freeze it. The probabilistic method applied to the coins themselves. Caveat (same as there): this proves existence of the advice; it does not hand you an efficient way to find it.
The class zoo, nested
with the one-sided wings and the NP connections:
┌── RP ──┐ ┌── NP ──┐
P ── ZPP ──┤ ├── BPP ── PP ── PSPACE
└─ coRP ─┘ └─ coNP ─┘
A reading of the picture: error-free in the middle (P, ZPP), one-sided just
outside (RP/coRP, each tucked under NP/coNP), bounded two-sided wider
still (BPP), unbounded two-sided enormous (PP NP), all swallowed
by PSPACE. The famous open question lives here: is BPP = P? (Lecture 5’s
PRGs say yes, under plausible hardness assumptions — randomness is a
convenience, not a necessity.) Note BPP vs NP is not known either way.
6. Where do the coins come from? Sources of randomness
Every class above silently assumed perfect coins. Time to question that.
The perfect random source
A random variable producing an infinite stream
- Independence — flip
does not depend on the previous flips; - Unbiasedness (correctness) —
exactly.
This is an idealisation. Real physical sources (thermal noise, radioactive decay timings, mouse jitter) are biased and correlated. So:
The δ-random source (Santha–Vazirani)
Drop both guarantees. Fix
Read it as an adversary. A demon sets each bit’s probability, looking at everything you’ve flipped so far, free to bias it as hard as it likes — except it can never push past
or . So no bit is ever fully predictable ( ), but bits can be heavily skewed and tangled. forces every bit to a fair, independent coin (perfect source); lets the demon fix bits outright (no randomness left).
Cautionary tale: 2-SAT random walk
Why we should worry. The classic 2-SAT algorithm (Papadimitriou): start with a
random assignment
With a fair coin,
With a δ-random source, the adversary can bias every flip away from
Lesson. An analysis that leaned on true
-coins (here: the symmetric walk) can be destroyed by a weak source. So: which classes survive a δ-source? That is the question the rest of the lecture answers — and the answer for BPPis wonderfully clean.
δ-RP, δ-BPP and the two easy boundary cases
Define δ-RP and δ-BPP exactly like RP/BPP, but the machine is fed by a
δ-random source. Label each node’s edges
. At the adversary can force any bit, so to be safe every leaf must answer correctly — that is just a deterministic algorithm. Worthless randomness collapses to P., . At every edge is forced to = a perfect source. Trivially unchanged.
The whole game is the strict interior
7. The theorem: a weak source is as good as a perfect one for BPP
Theorem. For every
, .
is trivial: a perfect source can simulate a δ-source. is the substance — simulate near-perfect randomness using only a weak, adversarial δ-source. This is an early randomness extractor.
The construction
Let BPP machine for
Let δ-BPP.
Why inner products extract randomness — three lemmas
Define the bias of an extracted bit as $\mathrm{bias}(\beta_i!\cdot!Z) =
\big(\Pr[\beta_i!\cdot!Z = 1] - \Pr[\beta_i!\cdot!Z = 0]\big)^2$ and the
collision probability of a source block
-
Lemma 1 (a Parseval identity). Summing bias over all seeds equals
times the block collision probability: Proof idea. Write $\Pr[\beta!\cdot!Z = 0] - \Pr[\beta!\cdot!Z = 1] = \sum_\beta (-1)^{\beta\cdot Z}\Pr[\beta]$ (thecharacter). Square, sum over , and use orthogonality: $\sum_Z (-1)^{(\beta_1 + \beta_2)\cdot Z} = 0$ unless (then it is ). The cross-terms vanish, leaving . -
Lemma 2 (collisions decay in
). For a δ-source block, Proof idea. Pair up sequences differing in one bit; through the lens of that bit the contribution is, maximised at the extreme . The block factorises, giving $\sum_{i}\binom{k}{i}\delta^{2i}(1-\delta)^{2(k-i)} = (\delta^2 + (1-\delta)^2)^k . Since $\delta < \tfrac12 , we have $\delta^2 + (1-\delta)^2 = 1 - (2\delta - 2\delta^2) < 1$, so collisions — and hence bias — decay exponentially in. Combining, $\sum_Z \mathrm{bias}(\beta_i!\cdot!Z) \le 2^k(\delta^2 + (1-\delta)^2)^k$. Call an extracted bit skewed if $\mathrm{bias} \ge 1/n^2$; an unskewed bit then satisfies $\Pr[\text{bit}=1] \in (\tfrac12 - \tfrac1{2n},\ \tfrac12 + \tfrac1{2n})$ — nearly fair. The bias budget caps the number of skewed bits across the whole computation at $n^3, 2^k(\delta^2 + (1-\delta)^2)^k
, and the choice $k \ge (5 + 3\log n)/(2\delta - 2\delta^2) forces this. -
Lemma 3 (few bad strings in expectation).
Proof idea. Splitinto the skewed strings plus unskewed ones. For an unskewed string each bit is within of fair, so its chance of landing in is at most $\tfrac{|B|}{2^n}(1 + \tfrac1n)^n \le \tfrac1{32}\cdot e . Adding the $\le 2^k/32 skewed strings:
Finish with Markov.
The punchline. A random source can be biased and adversarially correlated and it still does not matter for
BPP— provided it is not fully predictable (). The recipe: chop the weak stream into blocks, distil near-fair, near-independent bits by inner products, run exponentially many ( ) simulations on the distilled strings, and vote. Bias is bounded by a collision (Lemma 1–2), collision decays in the block size (Lemma 2), so few extracted bits are skewed, so few simulations are bad (Lemma 3), so the majority is right (Markov). Randomness quality is free; only randomness quantity / predictability (the
) is the real resource. The two boundaries pin it exactly: (fully predictable) collapses to P,is already perfect, and everything strictly in between is secretly just as powerful as perfect randomness. This is the historical seed of the entire theory of randomness extractors.
Closing themes
| Idea | One-line takeaway |
|---|---|
| Two placements of randomness | distribution over deterministic strategies (Model I) vs. coin at every fork (Model II) — same power, different intuition. |
| Error taxonomy | Las Vegas (never lies, random time) · one-sided MC (one trustworthy answer) · two-sided MC (biased toward truth). |
| Las Vegas duality | “always correct, random time” |
| The gap |
constant gap BPP; vanishing gap PP. |
| Class zoo | |
| ZPP = zero error | intersecting two opposite one-sided errors cancels both ⇒ honesty (= Las Vegas). |
| BPP ⊆ P/poly | probabilistic method on the coins + union bound over |
| Weak sources | a biased, correlated δ-source (BPP; extract by inner products, simulate, vote. Quality is free; only predictability ( |