BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Las Vegas to Monte Carlo and Back

Lecture 7 |2026-08-18
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. Two-Sided Error Amplification — boosting with majority vote.
  2. Conversions — Las Vegas \rightleftarrows Monte Carlo.
  3. Deterministic Turing Machines — states, tape, and transition function.
  4. The Class P — deterministic polynomial time.
  5. The Class NP — verifier definition of NP.

Two-Sided Error Amplification

  • Suppose the algorithm errs in both directions with probability \le 1/2 - \varepsilon (where \varepsilon > 0 is the bias).
  • Run the algorithm k times and output the majority vote.
  • By Chernoff bounds, majority error probability decays exponentially: \Pr(\text{majority error}) \le e^{-O(k \varepsilon^2)}
  • Note: This requires independent coin flips across runs; correlated runs do not amplify.

Converting Las Vegas → Monte Carlo

How do we convert an expected-time algorithm (Las Vegas) into a fixed-time algorithm (Monte Carlo)?

  • Stopping Prematurely (The Cutoff Strategy): Run the Las Vegas algorithm for a fixed time limit t. If it has not finished, stop it prematurely and output a default answer.
  • Error Probability Bound: By Markov’s Inequality, the probability that running time T exceeds cutoff t is: \Pr(T \ge t) \le \frac{\mathbb{E}[T]}{t}
  • Setting t = c \cdot \mathbb{E}[T] guarantees a failure probability \le 1/c.
  • Example: t = 10 \times \mathbb{E}[T] yields failure \le 10\%.
Time (T) Start E[T] Cutoff t = c·E[T] Runs normally (Correct) Cutoff (Error) Failure probability: Pr(T ≥ t) ≤ E[T]/t = 1/c

Converting Monte Carlo → Las Vegas

We can convert a Monte Carlo algorithm into a Las Vegas algorithm whenever a cheap verification algorithm (checker) exists.

Run Monte Carlo Get candidate x Verification Is x correct? Yes Return x (Las Vegas Output) No (Rerun)

Expected Runtime Analysis:

  • Let T_{MC} be the Monte Carlo runtime, T_{check} the verification time, and p the success probability.
  • The round count N is Geometric: \mathbb{E}[N] = 1/p.
  • Each round independently costs T_{MC} + T_{check}, so the total expected time is: \mathbb{E}[T] = \mathbb{E}\!\left[\sum_{i=1}^N (T_{MC} + T_{check})\right] \qquad = \mathbb{E}[N]\,(T_{MC} + T_{check}) = \frac{T_{MC} + T_{check}}{p}
  • Constraint: Requires a checker cheaper than the algorithm itself.

Deterministic Turing Machines

A Deterministic Turing Machine (DTM) is the standard mathematical model of computation:

  • Components:
    • A state control Q with start state q_0, accept state q_{acc}, and reject state q_{rej}.
    • An infinite tape with symbols from \Gamma (including blank \sqcup).
    • A tape head that reads/writes symbols and moves Left/Right.
  • Transition Function: \delta: Q \times \Gamma \to Q \times \Gamma \times \{L, R\}
  • Time Complexity: The machine halts in at most p(|x|) steps for some polynomial p.
... 1 0 1 1 0 ... Infinite Tape (Input/Memory) Read/Write Head State Control (Q) Current State: q_i

Class P (Polynomial Time)

We classify decision problems that can be solved efficiently:

  • Definition: Languages decidable by a DTM in polynomial time.
  • Formal Definition: L \in \text{P} if there exists a polynomial-time DTM M such that for all x: x \in L \iff M(x) = \text{Accept}
  • Intuition: “Easy to solve” deterministically. Examples: Sorting, Shortest Path, Primality Testing.

Class NP (Nondeterministic Polynomial Time)

We classify decision problems whose solutions can be verified efficiently:

  • Definition: Languages verifiable in polynomial time given a short certificate (witness).
  • Formal Definition: L \in \text{NP} if there exists a polynomial p and a polynomial-time DTM V (verifier) such that for all x: x \in L \iff \exists y \in \{0,1\}^{p(|x|)} \text{ s.t. } V(x, y) = \text{Accept}
  • Intuition: “Easy to verify”, possibly hard to solve. Examples: SAT, Clique, Traveling Salesperson.

Next Lecture

Randomized Complexity Classes — motivation, randomized Turing machines, RP, co-RP, BPP, ZPP, and the Probabilistic Method.