BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Randomized Complexity Classes

Lecture 8 |2026-08-20
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. Deterministic vs. Randomized Verifiers — building on Lecture 7’s NP verifier.
  2. The Big Four Classes — RP, co-RP, BPP, and ZPP in plain English.
  3. Class Containment — proving RP \subseteq NP and ZPP = RP \cap co-RP.
  4. Polynomial Identity Testing (PIT) — testing polynomials by plugging in random numbers.
  5. The Schwartz–Zippel Lemma — bounding the error probability of PIT.

Randomized Turing Machines: Verifier Model

Recall from Lecture 7 that NP uses a verifier V(x, y) with a certificate y: x \in L \iff \exists y \text{ s.t. } V(x, y) = 1

We can define a Randomized Turing Machine (RTM) by replacing the certificate y with random bits r:

  • Let A(x, r) be a deterministic machine.
  • x is the input.
  • r is a string of random bits (flipped coins), chosen uniformly at random.
  • A runs in polynomial time.
  • Output is either 1 (Accept) or 0 (Reject).
Input x Random bits r Verifier A deterministic 0 / 1

From NP to Randomized Classes

How do randomized classes differ from NP?

  • NP (Existential): There exists at least one lucky guess y that makes the verifier say Accept.
  • RP (Probabilistic): A huge fraction of random coin flips (at least 50%) must make the verifier say Accept.
  • Instead of relying on a magical witness, we just run the machine with random bits. If the answer is YES, we have a \ge 50\% chance of finding a witness by accident in a single run.

The Complexity Matrix (Simplified)

We define classes based on how they behave on YES and NO inputs:

Class If the true answer is YES If the true answer is NO Error Type
RP Says YES \ge 50\% of the time Says NO 100\% of the time One-sided: May say NO by mistake.
co-RP Says YES 100\% of the time Says NO \ge 50\% of the time One-sided: May say YES by mistake.
BPP Says YES \ge 66\% of the time Says NO \ge 66\% of the time Two-sided: Can err in both directions.
ZPP Always correct (100\%), expected poly time Always correct (100\%), expected poly time Zero error (Las Vegas). Running time is random.
  • Why these constants? 50% (RP) and 66% (BPP) are arbitrary! Running the algorithm k times (majority vote) amplifies success to \approx 100\% (like we proved in Lecture 7).

Class Containment: RP \subseteq NP

  • The Theorem: RP \subseteq NP and \text{co-RP} \subseteq \text{co-NP}.
  • The Intuition:
    • If a problem is in RP, then for any YES input x \in L, at least 50% of the choices of random bits r will make the verifier accept: \Pr_r[A(x, r) = 1] \ge 1/2
    • Since at least half of the random strings work, there must exist at least one working string r^*.
    • We can use this r^* as our NP certificate!
    • Thus, any RP problem can be verified in NP.

Zero-Error Class: ZPP = RP \cap \text{co-RP}

Theorem

ZPP = RP \cap \text{co-RP}.

  • A decision problem has an expected polynomial-time, zero-error randomized algorithm (ZPP) if and only if it has both an RP algorithm and a co-RP algorithm.
  • To prove this containment, we can construct a ZPP algorithm by running both RP and co-RP verifiers in tandem.

Proof: RP \cap \text{co-RP} \subseteq ZPP

  • Suppose L \in RP \cap \text{co-RP} via RP algorithm A_{RP} (never lies on NO) and co-RP algorithm A_{coRP} (never lies on YES).
  • Combined Zero-Error Algorithm:
    1. Run A_{RP}(x, r_1) on fresh random bits. If it outputs YES, return YES (guaranteed correct).
    2. Run A_{coRP}(x, r_2) on fresh random bits. If it outputs NO, return NO (guaranteed correct).
    3. Otherwise, both are inconclusive. Rerun with fresh coins.
  • Expected Runtime: Each round succeeds with probability \ge 1/2. The expected number of rounds is \le 2, yielding expected polynomial time with zero error.

The Big Picture

How these classes fit together:

  • P is inside ZPP (no coins needed \subseteq expected coins).
  • ZPP is the intersection of RP and co-RP.
  • RP is inside NP, and co-RP is inside co-NP.
  • All of these sit inside BPP (two-sided error).
BPP RP co-RP ZPP P

The Big Question: Is BPP = P?

Does randomness actually let us solve more decision problems in polynomial time? <

  • Modern Consensus: Most theorists believe BPP = P.
  • Derandomization: If we can build good pseudo-random generators (PRGs), we can replace the random string r with deterministic pseudo-random bits, eliminating the error.
  • The Poster Child for BPP: Polynomial Identity Testing (PIT). We have simple randomized algorithms for PIT, but no known deterministic polynomial-time algorithm!

Independent vs. Correlated Randomness

Why do we believe derandomization (BPP = P) is possible?

  • Perfect Independence (Hard):
    • Standard RTMs assume m truly independent coin flips.
    • In practice, generating truly independent random bits requires a massive physical entropy source.
  • Correlated Randomness (Easy):
    • In most algorithms, the random choices don’t need to be perfectly independent.
    • We can generate m highly correlated bits from a tiny, truly random seed of length s \ll m (e.g. using Pseudo-Random Generators).
    • If the seed is small enough (e.g., s = O(\ln n)), we can search all 2^s = n^{O(1)} possible seeds in polynomial time, completely removing the randomness!

Polynomial Identity Testing (PIT)

The Problem: Given a formula/circuit representing a polynomial P(x_1, \dots, x_n), decide if it is identically zero (evaluates to 0 for all possible inputs).

  • Why is this hard?
    • We cannot just expand the formula to check if all coefficients are zero.
    • Example: P(x) = (x_1 + 1)(x_2 + 1)\dots(x_n + 1) - \dots has 2^n terms. Expanding takes exponential time.
  • The Randomized Hack:
    • Just pick random numbers for x_1, \dots, x_n and evaluate the formula.
    • If the formula evaluates to a non-zero number, it is definitely not the zero polynomial.
    • If it evaluates to 0, can we be confident it is the zero polynomial?

Schwartz–Zippel: Univariate Case

If a polynomial is not zero, how likely are we to get a false zero by accident?

  • Univariate Polynomials (1 Variable):
    • A non-zero single-variable polynomial P(x) of degree d (like x^2 - 4 = 0) has at most d roots.
    • If we choose a random value r from a finite set S \subseteq \mathbb{F}, the chance of picking a root is: \Pr[P(r) = 0] \le \frac{\text{number of roots}}{|S|} \le \frac{d}{|S|}
    • The Argument: Since roots are rare in a large set S, picking a root by accident is highly unlikely if |S| \gg d.

Schwartz–Zippel: Generalization

How does this generalize to multiple variables?

  • Multivariate Generalization (n Variables):
    • The Schwartz–Zippel Lemma states that the exact same simple probability bound holds for any number of variables.
    • If P(x_1, \dots, x_n) is a non-zero polynomial of total degree d, and we pick random values r_1, \dots, r_n from a finite set S \subseteq \mathbb{F}: \Pr[P(r_1, \dots, r_n) = 0] \le \frac{d}{|S|}
    • By choosing a large set S, we can make the error probability as small as we want!

Concept Check

Answer each question based on today’s lecture:

  1. If a problem is in co-RP, and our algorithm says YES, can we be 100% sure the true answer is YES?
  2. If we want to check if a formula of degree 5 is identically zero, and we plug in random numbers from a set of size 1000, what is the maximum chance we get a false zero?
    1. Yes! A co-RP algorithm has one-sided error and never lies when it says YES.
    1. 5/1000 = 0.5\% by the Schwartz–Zippel Lemma.

Next Lecture

Tutte Matrix & Karger’s Min-Cut — completing algebraic matchings and finding min-cuts in graphs via random contractions.