Complexity Classes

4–5 hours ~13 min read

Complexity Classes

An algorithm being possible is the cheap part — the previous lesson settled that. The expensive part is how the cost grows. Complexity theory sorts decision problems into classes by the resources (time, space, randomness) a machine needs, and then asks which classes are equal. Almost every interesting equality is open — including the one (P=?NP\mathrm P \overset?= \mathrm{NP}) that a million-dollar prize rides on. We build the map carefully, because the quantum class BQP\mathrm{BQP} will have to find its place on it.

Learning Objectives

By the end of this lesson you will be able to:

  1. Use asymptotic notation (O,Ω,Θ,o,ωO, \Omega, \Theta, o, \omega) precisely and state the definitions.
  2. Formalize a computational problem as a decision problem / language and explain why this loses no generality.
  3. Define P\mathrm P, NP\mathrm{NP}, coNP\mathrm{coNP}, BPP\mathrm{BPP}, and PSPACE\mathrm{PSPACE} via the Turing-machine model, and state the standard inclusions.
  4. Define polynomial-time reductions and NP-completeness, and explain the role of SAT / 3-SAT (Cook–Levin).
  5. State clearly what is known and what is open (notably P=?NP\mathrm P\overset?=\mathrm{NP}), and locate the question "where does quantum fit?" relative to these classes.

Intuition

Two problems can both be "solvable" yet live in entirely different universes of practicality. Sorting nn numbers takes nlogn\sim n\log n steps — double the input, the work barely more than doubles. Brute-forcing a length-nn password over an alphabet of size kk takes kn\sim k^n — add one character, multiply the work by kk. The first is polynomial, the second exponential, and that single dichotomy — polynomial vs. exponential — is the coarse but astonishingly durable line between "tractable" and "intractable."

Three resources matter:

  • Time — number of steps. The class P\mathrm P = polynomial time = "efficient."
  • Nondeterminism / verification — can you check a claimed solution fast even if finding it is hard? That is NP\mathrm{NP}: easy to verify, maybe hard to find.
  • Space — memory cells used. PSPACE\mathrm{PSPACE} allows polynomial memory but possibly exponential time; you can reuse memory, which is why it contains so much.

A fourth resource, randomness, gives BPP\mathrm{BPP} (efficient with coin flips and a bounded error probability). It is the classical benchmark against which quantum's BQP\mathrm{BQP} is measured: a quantum speedup only "counts" if it beats randomized classical algorithms, not just deterministic ones.

Hold one picture in mind for the whole lesson — the inclusion chain we will justify:

P    BPP    BQP    PSPACE,P    NP    PSPACE. \mathrm P \;\subseteq\; \mathrm{BPP} \;\subseteq\; \mathrm{BQP} \;\subseteq\; \mathrm{PSPACE}, \qquad \mathrm P \;\subseteq\; \mathrm{NP} \;\subseteq\; \mathrm{PSPACE}.

Almost none of these inclusions is known to be strict, and where NP\mathrm{NP} sits relative to BQP\mathrm{BQP} is a central open question. Quantum lives inside PSPACE\mathrm{PSPACE} — it is not magic — but is conjectured to escape BPP\mathrm{BPP}.


Theory

1. Asymptotic notation (refresher)

We measure cost as a function of input size nn, ignoring constants and low-order terms. For eventually-nonnegative f,g:NR0f, g : \mathbb N \to \mathbb R_{\ge 0} [Sip §7.1], [AB §0.3]:

Notation Definition Reading
f=O(g)f = O(g) c>0,n0: nn0, f(n)cg(n)\exists\,c>0,\,n_0:\ \forall n\ge n_0,\ f(n) \le c\,g(n) ff grows no faster than gg (upper bound)
f=Ω(g)f = \Omega(g) c>0,n0: nn0, f(n)cg(n)\exists\,c>0,\,n_0:\ \forall n\ge n_0,\ f(n) \ge c\,g(n) ff grows at least as fast as gg (lower bound)
f=Θ(g)f = \Theta(g) f=O(g)f = O(g) and f=Ω(g)f = \Omega(g) ff and gg grow at the same rate
f=o(g)f = o(g) c>0,n0: nn0, f(n)<cg(n)\forall\,c>0,\,\exists\,n_0:\ \forall n\ge n_0,\ f(n) < c\,g(n) ff is strictly dominated: f/g0f/g \to 0
f=ω(g)f = \omega(g) c>0,n0: nn0, f(n)>cg(n)\forall\,c>0,\,\exists\,n_0:\ \forall n\ge n_0,\ f(n) > c\,g(n) ff strictly dominates: f/gf/g \to \infty

Useful facts: any polynomial kdaknk\sum_{k\le d} a_k n^k is Θ(nd)\Theta(n^d); logs beat polynomials beat exponentials, logn=o(nε)=o(2n)\log n = o(n^\varepsilon) = o(2^n) for any ε>0\varepsilon>0; and O,Ω,ΘO,\Omega,\Theta are transitive. The "==" here is a traditional abuse — "f=O(g)f = O(g)" means "fO(g)f \in O(g)," set membership, not equality.

Why polynomials are the dividing line. Polynomials are closed under addition, multiplication, and composition. That closure is exactly what makes P\mathrm P robust: composing two polynomial-time subroutines, or simulating one polynomial model on another with polynomial overhead (the Extended Church–Turing thesis from Lesson 1), keeps you in polynomial time. Exponentials are not so forgiving.

2. Decision problems and languages

A decision problem asks a yes/no question of an input. We encode inputs as strings over Σ={0,1}\Sigma=\{0,1\} and identify the problem with its language — the set of yes-instances:

L  =  {x{0,1}:the answer on x is "yes"}. L \;=\; \{\, x \in \{0,1\}^* : \text{the answer on } x \text{ is "yes"} \,\}.

For example PRIMES={p:p is prime}\mathrm{PRIMES} = \{\, \langle p\rangle : p \text{ is prime}\,\}, where \langle\cdot\rangle denotes a binary encoding. "Deciding LL" means a TM that halts on every input and accepts exactly LL (Lesson 1).

This costs no generality. A search problem ("output a satisfying assignment") or optimization problem ("find the largest clique") reduces to polynomially many decision queries by binary search / self-reduction: e.g. ask "is the max clique k\ge k?" for each kk, then fix vertices one at a time. So classifying languages by difficulty classifies all of computation, and lets us use the clean machine-decides-a-language framework.

3. The class P

P  =  c1 TIME ⁣(nc),TIME(t(n))={L:L is decided by some DTM in O(t(n)) time}. \mathrm P \;=\; \bigcup_{c \ge 1}\ \mathrm{TIME}\!\left(n^c\right), \qquad \mathrm{TIME}(t(n)) = \{\, L : L \text{ is decided by some DTM in } O(t(n)) \text{ time}\,\}.

P\mathrm P is the class of problems a deterministic TM solves in polynomial time. By the Extended Church–Turing thesis it is machine-independent: multi-tape TMs, RAM machines, and your laptop all agree on P\mathrm P. Examples: sorting, shortest paths, linear programming, and — famously — primality testing (PRIMESP\mathrm{PRIMES}\in\mathrm P, Agrawal–Kayal–Saxena 2002). P\mathrm P is our formal stand-in for "efficiently solvable."

4. The class NP, verifiers, and certificates

NP\mathrm{NP} ("nondeterministic polynomial time") is most cleanly defined by efficient verification [AB §2.1], [Sip §7.3]:

A language LNPL \in \mathrm{NP} iff there is a polynomial pp and a polynomial-time DTM VV (the verifier) such that for all xx,

xL    u{0,1}p(x)  with  V(x,u)=1. x \in L \iff \exists\, u \in \{0,1\}^{p(|x|)} \ \text{ with } \ V(x,u) = 1.

The string uu is a certificate (or witness). The point: finding uu may be hard, but checking a proposed uu is polynomial. Equivalently, NP\mathrm{NP} is what a nondeterministic TM decides in polynomial time — the machine "guesses" uu and verifies it.

Examples: SAT (does a Boolean formula have a satisfying assignment? — certificate: the assignment); CLIQUE (does a graph have a kk-clique? — certificate: the kk vertices); HAMPATH, SUBSET-SUM, integer factoring as a decision problem. Each yes-instance has a short, checkable proof.

Clearly PNP\mathrm P \subseteq \mathrm{NP}: if you can solve in polynomial time, you can verify by ignoring the certificate and re-solving. The converse — is verifying-easy the same as solving-easy? — is the P\mathrm P vs. NP\mathrm{NP} question.

5. co-NP

coNP\mathrm{coNP} is the class of languages whose complements are in NP\mathrm{NP}: LcoNP    LNPL\in\mathrm{coNP}\iff \overline L\in\mathrm{NP}. Where NP\mathrm{NP} has short proofs of yes, coNP\mathrm{coNP} has short proofs of no. TAUTOLOGY ("is this formula true under every assignment?") is the canonical coNP\mathrm{coNP} problem: a no-instance has a short certificate (a falsifying assignment), but it is not obvious how to certify yes succinctly. We have PNPcoNP\mathrm P \subseteq \mathrm{NP} \cap \mathrm{coNP}, and whether NP=coNP\mathrm{NP}=\mathrm{coNP} is open (believed false). If NPcoNP\mathrm{NP}\ne\mathrm{coNP} then PNP\mathrm P\ne\mathrm{NP}.

6. Reductions and NP-completeness

A polynomial-time many-one reduction from AA to BB, written ApBA \le_p B, is a polynomial-time computable map ff with

xA    f(x)B. x \in A \iff f(x) \in B .

Intuition: ff rewrites a question about AA into an equivalent question about BB, cheaply. The payoff is transfer of difficulty: if ApBA \le_p B and BPB \in \mathrm P, then APA \in \mathrm P (run ff, then the fast algorithm for BB). Reductions are transitive.

BB is NP-hard if every ANPA \in \mathrm{NP} satisfies ApBA \le_p B ("at least as hard as all of NP\mathrm{NP}"). BB is NP-complete if it is NP-hard and BNPB \in \mathrm{NP} — the hardest problems inside NP\mathrm{NP}. The decisive consequence:

If any NP-complete problem is in P\mathrm P, then P=NP\mathrm P = \mathrm{NP} — all of NP\mathrm{NP} collapses to polynomial time.

Cook–Levin and SAT / 3-SAT

The Cook–Levin theorem [AB §2.3], [Sip §7.4] proves that SAT (satisfiability of Boolean formulas in CNF) is NP-complete: the polynomial-time computation of any NP\mathrm{NP} verifier on (x,u)(x,u) can be encoded as a CNF formula that is satisfiable iff a valid certificate uu exists. That single theorem bootstraps the entire NP-complete universe — once SAT is complete, you show a new problem BB is NP-complete by reducing a known complete problem to it: SATpB\mathrm{SAT}\le_p B.

3-SAT (CNF with exactly 3 literals per clause) is also NP-complete via a clause-splitting reduction SATp3-SAT\mathrm{SAT}\le_p 3\text{-}\mathrm{SAT}: a long clause (1k)(\ell_1\lor\cdots\lor\ell_k) is replaced by a chain of 3-literal clauses linked by fresh variables ziz_i,

(12z1)  (¬z13z2)    (¬zk3k1k), (\ell_1\lor\ell_2\lor z_1)\ \land\ (\lnot z_1\lor\ell_3\lor z_2)\ \land\ \cdots\ \land\ (\lnot z_{k-3}\lor\ell_{k-1}\lor\ell_k),

which is satisfiable (by some setting of the ziz_i) iff at least one original literal j\ell_j is true. The reduction is polynomial and preserves satisfiability — the template for thousands of NP- completeness proofs (Karp's 21 problems, and onward).

7. Randomized computation: BPP

Allow the machine fair coin flips. BPP\mathrm{BPP} (Bounded-error Probabilistic Polynomial time) is the class of LL for which a polynomial-time probabilistic TM MM satisfies [AB §7.1]

xL  Pr[M(x)=1]23,xL  Pr[M(x)=1]13. x \in L \ \Rightarrow\ \Pr[M(x)=1] \ge \tfrac23, \qquad x \notin L \ \Rightarrow\ \Pr[M(x)=1] \le \tfrac13 .

The constants 23,13\tfrac23,\tfrac13 are not special: by running MM independently kk times and taking the majority vote, the error drops to 2Ω(k)2^{-\Omega(k)} (a Chernoff bound), so any gap bounded away from 12\tfrac12 amplifies to near-certainty with polynomially many repetitions. Thus BPP\mathrm{BPP} errors are a non-issue in practice.

PBPP\mathrm P \subseteq \mathrm{BPP} trivially (ignore the coins). Whether the inclusion is strict is open; in fact it is widely conjectured that P=BPP\mathrm{P}=\mathrm{BPP} (derandomization, under standard hardness assumptions). BPP\mathrm{BPP} is the right classical yardstick for quantum speedup: BQP\mathrm{BQP} is the quantum analogue of BPP\mathrm{BPP}, and the interesting claim is BPPBQP\mathrm{BPP}\subsetneq\mathrm{BQP}.

8. Space: PSPACE

PSPACE  =  c1 SPACE ⁣(nc), \mathrm{PSPACE} \;=\; \bigcup_{c \ge 1}\ \mathrm{SPACE}\!\left(n^c\right),

problems decidable using polynomial memory, with no time bound. Reusing memory is powerful: PSPACE\mathrm{PSPACE} contains all of NP\mathrm{NP} (and coNP\mathrm{coNP}). To see $\mathrm{NP}\subseteq \mathrm{PSPACE},deterministicallyenumerateeverycandidatecertificate, deterministically enumerate every candidate certificate u\in{0,1}^{p(n)}$, running the verifier on each, reusing the same p(n)p(n) cells — exponential time, but polynomial space. The canonical PSPACE\mathrm{PSPACE}-complete problem is TQBF (true quantified Boolean formulas, \forall\exists\cdots). The inclusions PNPPSPACE\mathrm P\subseteq\mathrm{NP}\subseteq\mathrm{PSPACE} hold; whether any is strict is open, though PPSPACE\mathrm P\ne\mathrm{PSPACE} is strongly believed.

9. The map, and what is (not) known

Putting it together, with \subseteq proven and =?\overset?= open:

P  NP,coNP  PSPACE,P  BPP  BQP  PSPACE. \mathrm P \ \subseteq\ \mathrm{NP},\,\mathrm{coNP} \ \subseteq\ \mathrm{PSPACE}, \qquad \mathrm P \ \subseteq\ \mathrm{BPP} \ \subseteq\ \mathrm{BQP} \ \subseteq\ \mathrm{PSPACE}.
Inclusion Status
PNP\mathrm P \subseteq \mathrm{NP} proven \subseteq; strictness open (P=?NP\mathrm P\overset?=\mathrm{NP}, Clay Millennium Prize)
PBPP\mathrm P \subseteq \mathrm{BPP} proven; conjectured equal (derandomization)
BPPBQP\mathrm{BPP}\subseteq\mathrm{BQP} proven; conjectured strict (Shor)
BQPPSPACE\mathrm{BQP}\subseteq\mathrm{PSPACE} proven (a classical machine can sum amplitudes in poly space)
NP\mathrm{NP} vs. BQP\mathrm{BQP} incomparable as far as anyone knows; NPBQP\mathrm{NP}\subseteq\mathrm{BQP} is not believed

Two cultural points worth internalizing. First, almost everything here is open: we cannot even prove PPSPACE\mathrm P\ne\mathrm{PSPACE}, despite overwhelming belief. Second — a common misconception — quantum computers are not believed to solve NP-complete problems efficiently. Grover's algorithm (Term 3.2) gives only a quadratic speedup for unstructured search, O(2n/2)O(2^{n/2}), which is provably optimal for the black-box model — far from polynomial. Quantum's exponential wins (Shor) attach to structured problems like factoring that are not known to be NP-complete.

Where does quantum fit? BQP\mathrm{BQP} sits between BPP\mathrm{BPP} and PSPACE\mathrm{PSPACE}. The central conjectures are BPPBQP\mathrm{BPP}\subsetneq\mathrm{BQP} (quantum genuinely helps) and NP⊈BQP\mathrm{NP}\not\subseteq\mathrm{BQP} (it does not help on the hardest verification problems). The full development — the definition of BQP\mathrm{BQP}, the BQPPSPACE\mathrm{BQP}\subseteq\mathrm{PSPACE} proof, and the landscape — is Term 3.6 · BQP & Quantum Complexity.


Worked Examples

Example 1 — A reduction: 3-SAT p\le_p INDEPENDENT-SET

We show the technique of a reduction by transforming a 3-CNF formula φ\varphi into a graph GG and a target kk so that φ\varphi is satisfiable iff GG has an independent set of size kk (an independent set = vertices, no two adjacent).

Construction. For each clause Cj=(j1j2j3)C_j = (\ell_{j1}\lor\ell_{j2}\lor\ell_{j3}) create a triangle of three vertices, one per literal. Add edges (i) inside each triangle (so an independent set picks 1\le 1 literal per clause), and (ii) between any two vertices labeling contradictory literals xx and ¬x\lnot x (so we never select both a variable and its negation). Set k=k = number of clauses.

Correctness. An independent set of size kk must take exactly one vertex per triangle (it can take at most one, and needs kk total from kk triangles) — i.e. one true literal per clause — and the contradiction edges guarantee these choices are consistent, defining a satisfying assignment. Conversely a satisfying assignment picks one true literal per clause, and those vertices form an independent set of size kk. The map is computable in polynomial time (size O(φ)O(|\varphi|)). Hence 3-SATpIND-SET3\text{-}\mathrm{SAT}\le_p \mathrm{IND\text{-}SET}, so INDEPENDENT-SET is NP-hard; since it is also in NP\mathrm{NP} (certificate = the vertex set), it is NP-complete. \square

Example 2 — Verifier vs. solver: factoring's exponential gap

Consider FACTOR\mathrm{FACTOR}-decision: "given NN and a bound BB, does NN have a prime factor B\le B?" The input size is n=log2Nn = \lceil \log_2 N\rceil bits.

  • Verification is easy: a certificate is a factor dd with 1<dB1<d\le B. Checking dNd\mid N is one long division, O(n2)O(n^2) time — polynomial in nn. So FACTORNPcoNP\mathrm{FACTOR}\in\mathrm{NP}\cap\mathrm{coNP}.
  • Naïve solving is exponential: trial-dividing by 2,3,,N2,3,\dots,\lfloor\sqrt N\rfloor takes Θ(N)=Θ(2n/2)\Theta(\sqrt N) = \Theta(2^{n/2}) divisions. Doubling the bit length nn squares the work.

This O(n2)O(n^2)-to-verify but 2Θ(n)2^{\Theta(n)}-to-solve gap is the texture of NP\mathrm{NP}. Factoring is not believed NP-complete (it is in NPcoNP\mathrm{NP}\cap\mathrm{coNP}, and NP-complete problems there would imply NP=coNP\mathrm{NP}=\mathrm{coNP}), and — crucially — Shor's quantum algorithm factors in polynomial time, O(n3)O(n^3)-ish, placing FACTORBQP\mathrm{FACTOR}\in\mathrm{BQP}. That is the quantum speedup, on a structured problem, and it is the concrete evidence for BPPBQP\mathrm{BPP}\subsetneq\mathrm{BQP}.


Hands-on (Python)

Self-contained, dependency-free. A brute-force 3-SAT solver lets us feel the exponential blow-up: its work scales as 2v2^v in the number of variables vv, while a verifier given an assignment is instant. We also implement the 3-SAT \to INDEPENDENT-SET reduction from Example 1 and check the two answers agree.

"""Complexity Classes — brute-force SAT + a reduction demo (plain Python)."""

from itertools import product
import time

# A CNF formula is a list of clauses; a clause is a list of literals.
# A literal is a signed int: +i means variable x_i, -i means NOT x_i.  (i >= 1)

def satisfies(formula, assignment):
    """VERIFIER: O(size) check that `assignment` (dict var->bool) sat's formula."""
    for clause in formula:
        if not any(assignment[abs(l)] == (l > 0) for l in clause):
            return False                      # clause unsatisfied -> formula false
    return True

def brute_force_sat(formula, n_vars):
    """SOLVER: try all 2**n_vars assignments. Exponential by construction."""
    for bits in product((False, True), repeat=n_vars):       # 2**n_vars rows
        assignment = {i + 1: bits[i] for i in range(n_vars)}
        if satisfies(formula, assignment):
            return assignment
    return None                                              # UNSAT

# A satisfiable 3-CNF: (x1 ∨ x2 ∨ ¬x3) ∧ (¬x1 ∨ x2 ∨ x3) ∧ (x1 ∨ ¬x2 ∨ x3)
phi = [[1, 2, -3], [-1, 2, 3], [1, -2, 3]]
sol = brute_force_sat(phi, n_vars=3)
print("Satisfying assignment:", sol)
print("Verifier agrees:", satisfies(phi, sol))

# Watch the search space double per added variable.
print("\nSearch-space size 2**v as v grows (the exponential wall):")
for v in (10, 15, 20, 22):
    # A trivially-UNSAT formula forces examining all 2**v rows.
    unsat = [[1], [-1]]                       # x1 AND NOT x1  -> always UNSAT
    t0 = time.perf_counter()
    brute_force_sat(unsat, n_vars=v)
    dt = time.perf_counter() - t0
    print(f"  v={v:2d}:  2**v = {2**v:>10,}   brute-force time ≈ {dt*1e3:7.1f} ms")


# ---------------------------------------------------------------------------
# Reduction demo: 3-SAT  ->  INDEPENDENT-SET  (Example 1).
# Build the graph, brute-force the independent set, compare to SAT answer.
# ---------------------------------------------------------------------------

def reduce_3sat_to_indset(formula):
    """Return (vertices, edges, k). Vertex = (clause_index, literal)."""
    vertices = [(j, lit) for j, clause in enumerate(formula) for lit in clause]
    edges = set()
    for a in range(len(vertices)):
        for b in range(a + 1, len(vertices)):
            (cj, la), (ck, lb) = vertices[a], vertices[b]
            same_triangle = (cj == ck)                 # (i) one literal per clause
            contradictory = (la == -lb)                # (ii) consistency edges
            if same_triangle or contradictory:
                edges.add((a, b))
    return vertices, edges, len(formula)               # k = #clauses

def has_independent_set(vertices, edges, k):
    """Brute-force: is there a k-subset with no internal edge?"""
    from itertools import combinations
    for subset in combinations(range(len(vertices)), k):
        s = set(subset)
        if not any(a in s and b in s for (a, b) in edges):
            return True
    return False

V, E, k = reduce_3sat_to_indset(phi)
sat_answer = brute_force_sat(phi, 3) is not None
ind_answer = has_independent_set(V, E, k)
print(f"\nReduction check: SAT={sat_answer}, INDEPENDENT-SET(k={k})={ind_answer}")
assert sat_answer == ind_answer, "Reduction must preserve the yes/no answer!"
print("3-SAT and its reduced INDEPENDENT-SET instance agree. ✓")

Expected output (timings are machine-dependent, but the doubling is the lesson):

Satisfying assignment: {1: False, 2: False, 3: False}   # the first one found
Verifier agrees: True

Search-space size 2**v as v grows (the exponential wall):
  v=10:  2**v =      1,024   brute-force time ≈     1.0 ms
  v=15:  2**v =     32,768   brute-force time ≈    38.0 ms
  v=20:  2**v =  1,048,576   brute-force time ≈  1340.0 ms
  v=22:  2**v =  4,194,304   brute-force time ≈  5980.0 ms

Reduction check: SAT=True, INDEPENDENT-SET(k=3)=True
3-SAT and its reduced INDEPENDENT-SET instance agree. ✓

Each added variable roughly doubles the brute-force time — the exponential wall, live. No known algorithm avoids it in the worst case; whether one exists is P=?NP\mathrm P\overset?=\mathrm{NP}.


Exercises

1. (Easy) Asymptotics drill. Rank by growth rate (slowest first) and give the Θ\Theta class of each:   100n,  nlog2n,  210n2,  n2.5,  2n,  2n/n.\;100n,\ \ n\log_2 n,\ \ 2^{10}n^2,\ \ n^{2.5},\ \ 2^{\sqrt n},\ \ 2^{n}/n.

Solution

Order: $100n\ (\Theta(n)) \prec n\log_2 n\ (\Theta(n\log n)) \prec 2^{10}n^2\ (\Theta(n^2)) \prec n^{2.5}\ (\Theta(n^{2.5})) \prec 2^{\sqrt n}\ (\text{sub-exponential}) \prec 2^n/n$. Constants (100100, 2102^{10}) vanish inside Θ\Theta. Note 2n2^{\sqrt n} beats every polynomial ($\sqrt n,\log 2 = \omega(\log n))butisdominatedby) but is dominated by 2^n/n$.

2. (Easy–Medium) Closure of P. Prove that if ApBA\le_p B and BPB\in\mathrm P then APA\in\mathrm P. Where exactly is closure of polynomials under composition used?

Solution

Let ff be the reduction, computable in time O(na)O(n^a), and let MBM_B decide BB in time O(mb)O(m^b). On input xx of size nn: compute y=f(x)y=f(x) in O(na)O(n^a); crucially yO(na)|y|\le O(n^a) (a TM writes at most one symbol per step). Then run MB(y)M_B(y) in O(yb)=O(nab)O(|y|^b)=O(n^{ab}). Total O(na+nab)=O(nab)O(n^a + n^{ab})=O(n^{ab}), polynomial. Composition is used twice: y|y| is polynomial in nn, and a polynomial of a polynomial (nabn^{ab}) is again polynomial. \blacksquare

3. (Medium) Verifier for CLIQUE. Give a formal NP\mathrm{NP} verifier for CLIQUE={G,k:G has a k-clique}\mathrm{CLIQUE}=\{\langle G,k\rangle : G\text{ has a }k\text{-clique}\}: state the certificate, the check, and its running time, confirming CLIQUENP\mathrm{CLIQUE}\in\mathrm{NP}.

Solution

Certificate uu = a list of kk vertices, length O(klogV)=poly(n)O(k\log|V|) = \mathrm{poly}(n). Verifier $V(\langle G,k\rangle, u):(i)check: (i) check ulists lists kdistinctverticesof *distinct* vertices of G;(ii)checkall; (ii) check all \binom{k}{2}$ pairs are edges of GG. Step (ii) is O(k2)O(k^2) adjacency lookups, polynomial in the input. VV accepts iff a valid clique is presented, so G,kCLIQUE    u:V=1\langle G,k\rangle\in\mathrm{CLIQUE}\iff\exists u: V=1. Hence CLIQUENP\mathrm{CLIQUE}\in\mathrm{NP}.

4. (Medium) coNP certificates. Explain why TAUTOLOGY (every assignment satisfies φ\varphi) is in coNP\mathrm{coNP} but not obviously in NP\mathrm{NP}. What would a short yes-certificate need to do, and why is that suspicious?

Solution

TAUT={φ:φ is falsifiable}\overline{\mathrm{TAUT}} = \{\varphi : \varphi \text{ is falsifiable}\} is in NP\mathrm{NP}: certificate = a falsifying assignment, checked in polynomial time. Hence $\mathrm{TAUT}\in \mathrm{coNP}.For. For \mathrm{TAUT}\in\mathrm{NP}$ we would need a short, poly-checkable proof that φ\varphi is true under all 2v2^v assignments. No such proof system is known; if one existed for all tautologies it would imply NP=coNP\mathrm{NP}=\mathrm{coNP}, which is believed false. (Indeed TAUT\mathrm{TAUT} is coNP\mathrm{coNP}-complete.)

5. (Hard) Self-reducibility. Show that if SAT (the decision problem) is in P\mathrm P, then one can find a satisfying assignment in polynomial time. Conclude that the search and decision versions of SAT are polynomially equivalent.

Solution

Suppose a poly-time decider DD for SAT. Given satisfiable φ(x1,,xv)\varphi(x_1,\dots,x_v): set x1:=Tx_1:=\text{T} and ask D(φx1=T)D(\varphi|_{x_1=T}). If satisfiable, fix x1=Tx_1=\text{T}; else D(φx1=F)D(\varphi|_{x_1=F}) must return satisfiable (since φ\varphi was), so fix x1=Fx_1=\text{F}. Recurse on the remaining variables. This makes 2v\le 2v calls to DD, each on a formula no larger than φ\varphi, so total time is poly(φ)\mathrm{poly}(|\varphi|). The constructed assignment satisfies φ\varphi by induction. Thus decision P\in\mathrm P \Rightarrow search FP\in\mathrm{FP}; the reverse is trivial. SAT is self-reducible.

6. (Hard) Where quantum is not magic. Grover searches an unstructured space of size N=2nN=2^n in Θ(N)=Θ(2n/2)\Theta(\sqrt N)=\Theta(2^{n/2}) queries, provably optimal in the black-box model. (a) Why does this not put NP-complete problems in BQP\mathrm{BQP}? (b) Contrast with factoring.

Solution

(a) For an NP-complete problem with nn-bit certificates, treating verification as a black box and "Grovering" over 2n2^n candidates costs Θ(2n/2)\Theta(2^{n/2}) — still exponential in nn, merely a square-root speedup. Polynomial time would require an exponential speedup, which the optimal-query lower bound forbids for unstructured search. So quantum does not collapse NP\mathrm{NP} into BQP\mathrm{BQP}; NPBQP\mathrm{NP}\subseteq\mathrm{BQP} is not believed. (b) Factoring is structured: Shor exploits the periodicity of axmodNa^x\bmod N via the quantum Fourier transform to get a genuine polynomial-time algorithm — an exponential speedup that does place FACTORBQP\mathrm{FACTOR}\in\mathrm{BQP}. The lesson: quantum exponential speedups need structure; brute force only gets a quadratic discount.


Checkpoint

1. Define $f=\Theta(g)$ and give one $f,g$ with $f=O(g)$ but $f\ne\Theta(g)$.

f=Θ(g)f=\Theta(g) means f=O(g)f=O(g) and f=Ω(g)f=\Omega(g) (same growth rate). Example: f(n)=nf(n)=n, g(n)=n2g(n)=n^2 has f=O(g)f=O(g) but f=o(g)f=o(g), so fΘ(g)f\ne\Theta(g).

2. Why does classifying languages capture all of computation?

Search and optimization problems reduce to polynomially many decision queries via self-reduction / binary search. So the difficulty of languages determines the difficulty of everything.

3. Give the verifier-based definition of $\mathrm{NP}$ in one sentence.

LNPL\in\mathrm{NP} iff there is a poly-time verifier VV and polynomial pp such that xLx\in L exactly when some certificate u{0,1}p(x)u\in\{0,1\}^{p(|x|)} makes V(x,u)=1V(x,u)=1.

4. What is the single consequence of one NP-complete problem being in P?

P=NP\mathrm P=\mathrm{NP}: a polynomial algorithm for any NP-complete problem, composed with the reductions, solves every NP\mathrm{NP} problem in polynomial time.

5. State the inclusion chain placing $\mathrm{BQP}$, and which links are open.

PBPPBQPPSPACE\mathrm P\subseteq\mathrm{BPP}\subseteq\mathrm{BQP}\subseteq\mathrm{PSPACE}. All inclusions are proven; BQPPSPACE\mathrm{BQP}\subseteq\mathrm{PSPACE} is a theorem, while BPPBQP\mathrm{BPP}\subsetneq\mathrm{BQP} is conjectured (Shor) and NP\mathrm{NP} vs. BQP\mathrm{BQP} is open/incomparable.

6. True or false: quantum computers efficiently solve NP-complete problems. Justify.

False (as far as is known). Grover gives only a quadratic speedup for unstructured search, Θ(2n/2)\Theta(2^{n/2}) — still exponential — and that is optimal. Quantum's exponential wins (Shor) are on structured problems like factoring, which is not known to be NP-complete.


Further Reading

  • [Sip §7.1–7.4] Sipser — asymptotics, P\mathrm P, NP\mathrm{NP}, NP-completeness, Cook–Levin. The most readable first treatment; the SAT and 3-SAT material here follows it.
  • [AB §2, §7] Arora & Barak — rigorous NP\mathrm{NP}, reductions, Cook–Levin, BPP\mathrm{BPP} and error amplification; §0.3 for asymptotic notation.
  • [AB §4] Arora & Barak — space complexity and PSPACE\mathrm{PSPACE} (TQBF completeness).
  • [NC §3.2] Nielsen & Chuang — computational complexity classes oriented toward quantum, including BPP\mathrm{BPP} and the lead-in to BQP\mathrm{BQP}.
  • [Aar] Aaronson — sharp intuition for P/NP/BQP\mathrm P/\mathrm{NP}/\mathrm{BQP} and the (mis)belief that quantum solves NP-complete problems.

← Prev: Models of Computation · Up: Term 0 · Next: Reversible Computation