Unit 4

NP and coNP

Polynomial certificates, their equivalence to nondeterministic computation, and the asymmetric evidence captured by NP and coNP.

Goals

  • Move fluently between the nondeterministic-machine and verifier definitions of NP.
  • Explain exactly why the certificate and verifier must have polynomial bounds.
  • Read coNP as short evidence for universal/no claims, without treating it as “everything outside NP.”
  • Prove the standard containments and recognize which separations remain open.

1. NP: search hidden inside verification

An NP question often has the form “does there exist a small object with an efficiently checkable property?” For SAT the object is an assignment; for CLIQUE it is a vertex set; for Hamiltonian Cycle it is an ordering of the vertices. A deterministic exhaustive search may inspect exponentially many candidates, but one proposed candidate can be checked quickly.

This does not say that NP means “not polynomial,” and it does not prove that any NP-complete problem is outside P. It says that yes-instances possess polynomially bounded evidence checkable in deterministic polynomial time.

The nondeterministic definition

A nondeterministic Turing machine NN accepts xx if at least one computation branch accepts. It decides a language in time p(n)p(n) if every branch halts within p(∣x∣)p(|x|) steps and

x∈L  ⟺  some branch of N(x) accepts.x\in L \iff \text{some branch of }N(x)\text{ accepts}.

Thus

NP=⋃k≥1NTIME(nk).\mathrm{NP}=\bigcup_{k\ge 1}\mathrm{NTIME}(n^k).

The quantifiers matter. On a no-instance, every branch must reject; swapping accept and reject would turn “some accepts” into “some rejects,” not into the required universal condition.

The verifier definition

A deterministic polynomial-time verifier is a machine V(x,w)V(x,w) that receives the instance xx and a certificate ww. A language LL is in NP iff there are polynomials p,qp,q and such a verifier satisfying

x∈L  ⟺  ∃w∈{0,1}≤p(∣x∣)V(x,w)=1,x\in L \iff \exists w\in\{0,1\}^{\le p(|x|)}\quad V(x,w)=1,

where VV halts in at most q(∣x∣+∣w∣)q(|x|+|w|) steps on every pair. Some formulations require ∣w∣=p(∣x∣)|w|=p(|x|); padding a shorter certificate with a marked block makes the versions equivalent.

The certificate bound is essential. If ww could be exponentially long, merely reading it could take exponential time in ∣x∣|x|. The verifier’s runtime is polynomial in its actual input ∣x∣+∣w∣|x|+|w|; because ∣w∣≤p(∣x∣)|w|\le p(|x|), composition gives a polynomial in ∣x∣|x|.

Guided construction

NP and coNP

Step 1 of 6
Known: P⊆NP
Known containments among P, NP, and coNPDashed schematic NP and coNP boundaries overlap. P is contained in their intersection. SAT and UNSAT show known certificate memberships, while P versus NP and NP versus coNP remain open.NPshort yes-certificates
schematic class boundary

2. Why verifiers and NTMs are equivalent

Theorem (NP characterization). A language has a polynomial-time nondeterministic decider iff it has polynomial-size certificates checked by a deterministic polynomial-time verifier.

This is an equivalence, so it needs two constructions.

NTM ⇒\Rightarrow verifier

Assume NN decides LL and every branch uses at most c∣x∣dc|x|^d steps. Encode one accepting branch by listing the nondeterministic choice made at each step. For a fixed machine, each transition choice needs only a constant number of bits, so the transcript has length at most ac∣x∣da c|x|^d for a machine-dependent constant aa.

The verifier V(x,w)V(x,w) deterministically simulates N(x)N(x), forcing at each branching point the choice encoded by ww. It rejects if a choice is illegal, the transcript ends incorrectly, or the simulated branch does not accept. It accepts exactly legal accepting transcripts.

  • If x∈Lx\in L, an accepting branch exists, and its transcript is an accepting certificate.
  • If x∉Lx\notin L, no accepting branch exists, so no transcript can make VV accept.
  • Simulation takes polynomial time because the branch and transcript are polynomially long.

One may instead use a sequence of configurations as the certificate. That encoding is larger but still polynomial, and adjacent configurations are locally checkable.

Verifier ⇒\Rightarrow NTM

Assume V,p,qV,p,q satisfy the verifier definition. On input xx, the NTM computes p(∣x∣)p(|x|), nondeterministically chooses that many certificate bits, and runs V(x,w)V(x,w). It accepts iff VV accepts.

  • If x∈Lx\in L, some valid ww exists, hence one branch chooses it and accepts.
  • If x∉Lx\notin L, every possible ww is rejected, hence all branches reject.
  • Guessing costs p(∣x∣)p(|x|) steps; verification costs
q(∣x∣+p(∣x∣)),q(|x|+p(|x|)),

which is polynomial because a composition and sum of polynomials remain polynomial.

This proof also clarifies “guess and check”: guessing is not random sampling. The NTM semantics existentially ranges over all certificates.

3. Worked certificate examples

SAT

For a CNF formula φ\varphi over nn variables, w∈{0,1}nw\in\{0,1\}^n gives an assignment. Scan every literal and clause and accept iff every clause has a true literal. A straightforward implementation is polynomial in ∣⟨φ⟩∣|\langle\varphi\rangle|.

For

φ=(x1∨¬x2)∧(x2∨x3),\varphi=(x_1\lor \neg x_2)\land(x_2\lor x_3),

w=(1,1,0)w=(1,1,0) certifies membership: the first clause is true through x1x_1, the second through x2x_2. A certificate that fails proves nothing; NP asks whether some certificate works.

CLIQUE

An instance is (G,k)(G,k), not just GG. A certificate can list kk distinct vertices. Verify the range, distinctness, and each of the (k2)\binom{k}{2} required edges. If kk is binary and larger than ∣V∣|V|, reject before trying to allocate kk objects. This small guard prevents a numeric parameter from hiding exponential work.

COMPOSITE

For a binary integer NN, factors a,ba,b with 1<a,b<N1<a,b<N and ab=Nab=N form a certificate. Their binary lengths are O(log⁡N)O(\log N) and grade-school multiplication is polynomial in bit length. This is a certificate for COMPOSITE, not automatically a certificate for PRIMES.

4. Complements and coNP evidence

For L⊆{0,1}∗L\subseteq\{0,1\}^*, define

L‾={0,1}∗∖L,coNP={L:L‾∈NP}.\overline L=\{0,1\}^*\setminus L, \qquad \mathrm{coNP}=\{L:\overline L\in\mathrm{NP}\}.

coNP is a class of languages; it is not the set-theoretic complement of the collection NP. A language can belong to both.

Applying the verifier characterization to L‾\overline L yields a useful quantifier view:

L∈coNP  ⟺  ∃V,p  ∀x:x∈L  ⟺  ∀w∈{0,1}≤p(∣x∣)  V(x,w)=1,L\in\mathrm{coNP} \iff \exists V,p\;\forall x: \quad x\in L \iff \forall w\in\{0,1\}^{\le p(|x|)}\;V(x,w)=1,

after complementing the verifier’s output. Equivalently, if x∉Lx\notin L, there is a short witness exposing failure. This is why coNP is often described as efficiently checkable evidence for no-instances.

TAUT versus SAT

TAUT contains formulas true under every assignment. Its complement consists of formulas with a falsifying assignment. That assignment is a short NP certificate, so

TAUT∈coNP.\mathrm{TAUT}\in\mathrm{coNP}.

UNSAT is likewise in coNP because its complement SAT is in NP. Notice the evidence asymmetry: one satisfying assignment establishes SAT; a failed search over a few assignments does not establish UNSAT.

A subtle but useful example

PRIMES is in P, and therefore in both NP and coNP. Historically, certificates for primality and compositeness illustrated that membership in NP∩coNP\mathrm{NP}\cap\mathrm{coNP} does not by itself imply a known deterministic algorithm; today primality is known to be in P. Always specify the integer encoding and how malformed strings are handled.

5. Containments and consequences

Proposition. P⊆NP∩coNP\mathrm P\subseteq\mathrm{NP}\cap\mathrm{coNP}.

Proof walkthrough. A deterministic polynomial-time machine is an NTM with one branch, so P⊆NP\mathrm P\subseteq\mathrm{NP}. If L∈PL\in\mathrm P, take its total polynomial-time decider and swap accepting and rejecting states; this decides L‾\overline L in the same time. Hence L‾∈P⊆NP\overline L\in\mathrm P\subseteq\mathrm{NP} and L∈coNPL\in\mathrm{coNP}. □\square

The same accept/reject swap does not prove NP closed under complement because nondeterministic acceptance is existential.

Proposition. If P=NP\mathrm P=\mathrm{NP}, then NP=coNP\mathrm{NP}=\mathrm{coNP}.

Proof. P is closed under complement. If NP equals P, NP inherits that closure. Thus L∈NPL\in\mathrm{NP} implies L‾∈NP\overline L\in\mathrm{NP}, which is equivalent to L∈coNPL\in\mathrm{coNP}. Applying complement again gives the reverse containment. □\square

Neither P≠NP\mathrm P\ne\mathrm{NP} nor NP≠coNP\mathrm{NP}\ne\mathrm{coNP} is currently known. A Venn diagram must therefore mark uncertain boundaries.

A particularly important consequence is:

If an NP-complete language KK is in coNP, then NP=coNP\mathrm{NP}=\mathrm{coNP}.

For every A∈NPA\in\mathrm{NP}, A≤mpKA\le_m^p K. coNP is closed downward under polynomial many-one reductions, so A∈coNPA\in\mathrm{coNP}. Thus NP⊆coNP\mathrm{NP}\subseteq\mathrm{coNP}, and complementation gives equality. The closure proof is developed in the reductions lesson.

6. Encodings are part of the language

A language is a set of strings, so “the input is a graph” is shorthand for a chosen encoding. A robust decider first checks syntax. For malformed strings, choose and document a convention—normally reject. A reduction must also map malformed source encodings consistently, often to one fixed no-instance.

Numeric values are not unit-cost merely because they are written as one mathematical symbol. A binary integer kk occupies Θ(log⁡k)\Theta(\log k) bits. An algorithm that performs kk iterations may therefore be exponential in input length unless a semantic guard such as k≤∣V∣k\le |V| has already been established.

7. Three quantifier patterns worth separating

It helps to write the logical shape before searching for a certificate:

x∈SAT  ⟺  ∃α  [α satisfies φ],x∈TAUT  ⟺  ∀α  [α satisfies φ],x∈UNSAT  ⟺  ∀α  [α does not satisfy φ].\begin{aligned} x\in\mathrm{SAT} &\iff \exists\alpha\;[\alpha\text{ satisfies }\varphi],\\ x\in\mathrm{TAUT} &\iff \forall\alpha\;[\alpha\text{ satisfies }\varphi],\\ x\in\mathrm{UNSAT} &\iff \forall\alpha\;[\alpha\text{ does not satisfy }\varphi]. \end{aligned}

The predicate inside each bracket is polynomial-time computable. The first line directly has the NP verifier form. The second and third have the coNP form because a counterexample to membership is existentially witnessed. This syntactic comparison explains the evidence asymmetry without asserting a separation: perhaps a clever, non-obvious polynomial certificate for UNSAT exists, but proving that every coNP language has NP certificates is exactly the unresolved equality NP=coNP\mathrm{NP}=\mathrm{coNP}.

Graph problems show the same distinction. A proposed kk-clique is immediately checkable, whereas “this graph has no kk-clique” appears to quantify over all kk-subsets. The latter language is in coNP because one clique refutes it. That observation alone neither proves nor disproves that it is also in NP.

A more explicit branch encoding

Suppose each configuration of NN has at most bb legal successors, where bb depends only on the fixed transition table. Number the choices 0,…,b−10,\ldots,b-1 and let

r=⌈log⁡2b⌉.r=\lceil\log_2 b\rceil.

For a T(n)T(n)-step computation, use exactly rT(n)rT(n) certificate bits, partitioned into T(n)T(n) blocks. At step tt, interpret block tt as a successor index. Reject if it denotes no legal successor. If NN halts early, require the remaining blocks to encode a designated padding move. This convention makes the verifier total and removes ambiguity about short transcripts. Its deterministic simulation stores the current configuration, looks up one transition, and updates it for at most T(n)T(n) rounds.

Conversely, an NTM simulating a verifier need not materialize all 2p(n)2^{p(n)} certificates. It branches once per guessed bit, creating a depth-p(n)p(n) computation tree. Complexity measures the longest branch, not the total number of nodes in that tree. Each branch spends p(n)p(n) steps guessing and then one polynomial verifier run. This is the precise reason exponentially many possible witnesses are compatible with nondeterministic polynomial time.

8. Consequences around complete languages

The statement “an NP-complete language KK is in coNP” has more force than merely placing one language in an intersection. For each A∈NPA\in\mathrm{NP} choose a reduction ff with

x∈A  ⟺  f(x)∈K.x\in A\iff f(x)\in K.

Because complementation preserves this same biconditional,

x∈A‾  ⟺  f(x)∈K‾.x\in\overline A\iff f(x)\in\overline K.

Now K∈coNPK\in\mathrm{coNP} means K‾∈NP\overline K\in\mathrm{NP}. Composing ff with an NP verifier for K‾\overline K proves A‾∈NP\overline A\in\mathrm{NP}, hence A∈coNPA\in\mathrm{coNP}. Therefore NP⊆coNP\mathrm{NP}\subseteq\mathrm{coNP}. Taking complements gives the reverse inclusion.

This argument relies on many-one reductions. Their single output and biconditional make the complement step immediate. With other reduction notions, closure must be checked rather than assumed.

An analogous warning applies to NP-hardness: if KK is NP-hard but not known to lie in NP, then K∈coNPK\in\mathrm{coNP} still implies NP⊆coNP\mathrm{NP}\subseteq\mathrm{coNP} by downward closure. To call KK NP-complete, however, one must separately prove K∈NPK\in\mathrm{NP}.

Common mistakes

  1. “NP means exponential.” NP defines nondeterministic polynomial time, not a deterministic lower bound.
  2. Swapping NTM accept/reject states. This changes existential acceptance incorrectly; it does not decide the complement.
  3. Polynomial in the wrong quantity. Runtime must be polynomial in encoded input length, not numeric value.
  4. Unbounded certificates. A fast verifier with exponentially long evidence does not establish NP membership.
  5. Confusing a bad witness with a no-instance. A no-instance rejects every witness; one rejection is insufficient.
  6. Drawing known strict containments. The boundaries among P, NP, and coNP are unresolved.

Exercises

Exercise 1 — P⊆NP∩coNP\mathrm P\subseteq\mathrm{NP}\cap\mathrm{coNP}

Prove P⊆NP\mathrm P\subseteq\mathrm{NP} and P⊆coNP\mathrm P\subseteq\mathrm{coNP}. State what you did not prove about NP∩coNP\mathrm{NP}\cap\mathrm{coNP}.

Solution

A deterministic polynomial machine is an NTM with one branch, so P⊆NP\mathrm P\subseteq\mathrm{NP}. If L∈PL\in\mathrm P, swap accept and reject in its total decider to decide L‾\overline L in the same time, so L‾∈P⊆NP\overline L\in\mathrm P\subseteq\mathrm{NP} and L∈coNPL\in\mathrm{coNP}.

Not proved: NP∩coNP=P\mathrm{NP}\cap\mathrm{coNP}=\mathrm P (open). Only P⊆NP∩coNP\mathrm P\subseteq\mathrm{NP}\cap\mathrm{coNP} is known.

Exercise 2 — Hamiltonian-path certificate

Prove that the language of directed Hamiltonian paths is in NP\mathrm{NP}: define certificate, checks, completeness, and soundness.

Solution

Certificate: a sequence of ∣V∣|V| IDs. Check it is a permutation of VV and consecutive pairs (and closing edge if cycles) are edges. Length O(∣V∣log⁡∣V∣)O(|V|\log|V|), polynomial time. Completeness/soundness follow the path definition.

Exercise 3 — coNP certificate for nontautology

Let LL be the language of formulas that are not tautologies. Prove L∈NPL\in\mathrm{NP}, hence tautologies lie in coNP\mathrm{coNP}.

Solution

Certificate for LL: a falsifying assignment. Verify by evaluation in polynomial time. Thus L∈NPL\in\mathrm{NP} and its complement (tautologies) is in coNP\mathrm{coNP}.

Exercise 4 — Bounding ∣w∣|w|

Prove why a verifier definition must bound ∣w∣≤q(∣x∣)|w|\le q(|x|). What breaks without the bound?

Solution

The matching NTM guesses ww; without a bound the guess is not polynomial in ∣x∣|x|. Even reading ww may not be polynomial in the input length. The bound ensures NP=⋃kNTIME(nk)\mathrm{NP}=\bigcup_k\mathrm{NTIME}(n^k).

Exercise 5 — NP-complete language in P\mathrm P

Prove: if some NP-complete language lies in P\mathrm P, then P=NP\mathrm P=\mathrm{NP}.

Solution

Let AA be NP-complete and A∈PA\in\mathrm P. For every L∈NPL\in\mathrm{NP} there is a polynomial reduction L≤pAL\le_p A. Compose with a polynomial decider for AA to decide LL in polynomial time. Thus NP⊆P\mathrm{NP}\subseteq\mathrm P, hence equality.

Summary

NP\mathrm{NP} is short efficiently checkable yes-evidence; coNP\mathrm{coNP} is no-evidence. Containments with P\mathrm P are known; the interesting equalities remain open.

Guided practice

Task 1 — Verifiers do not find certificates

Explain why a polynomial verifier need not find a certificate, and how that differs from a search algorithm.

Solution

The verifier is given (x,w)(x,w) and checks. Finding ww is a search problem that may be hard even when verification is easy. Membership in NP\mathrm{NP} does not yield a finder.

Task 2 — Closure under complement

Prove P\mathrm P is closed under complement. Explain why the same proof fails for NP\mathrm{NP} without extra assumptions.

Solution

In P\mathrm P, swap accept/reject on a deterministic decider. In NP\mathrm{NP}, swapping tree leaves changes ∃\exists into “∃\exists rejecting branch”, not ∀\forall. Closure of NP\mathrm{NP} under complement is equivalent to NP=coNP\mathrm{NP}=\mathrm{coNP}, which is open.

Task 3 — NP∩coNP\mathrm{NP}\cap\mathrm{coNP}

Give a natural problem historically associated with NP∩coNP\mathrm{NP}\cap\mathrm{coNP}, and state what is known about the intersection.

Solution

PRIMES is a classic example (now known to be in P\mathrm P). In general P⊆NP∩coNP\mathrm P\subseteq\mathrm{NP}\cap\mathrm{coNP} is known; equality is not. An NP-complete language cannot lie in coNP\mathrm{coNP} unless NP=coNP\mathrm{NP}=\mathrm{coNP}.

Sources

Course evidence

  • Current Semester A transcripts 7–8: certificate checking, nondeterministic computation, and the verifier/NTM characterization. No finer transcript line or timestamp locator is asserted here.
  • Merged course summary, pp. 39–42: the core NP definitions, polynomial certificates, and verifier/nondeterministic-machine viewpoint.
  • Merged course summary, pp. 81–85: complements, coNP, asymmetric evidence, and the NP-versus-coNP discussion. These page ranges are cited as course evidence; no wording is reproduced from the scanned summary.

Textbook verification

  • Sipser, Introduction to the Theory of Computation, 3rd ed., §7.3, pp. 293–299: verifier definition of NP and equivalence with nondeterministic polynomial time.
  • Arora–Barak, Computational Complexity: A Modern Approach (draft), §2.1–2.2, especially pp. 38–45 in the draft pagination: NP, certificates, and coNP.
  • Papadimitriou, Computational Complexity, Ch. 9, pp. 181–187: NP certificates, nondeterminism, and complementary evidence. These references verify the standard claims; the sequencing and examples above follow the current course.