Theory of Computation: Lecture 7
Worst-case time complexity, asymptotic notation, TIME and P, polynomial-time verification, NP, nondeterministic polynomial time, and the P versus NP question.
Worst-Case Time
Decidability asks whether a Turing machine always gives the right answer and halts. Complexity asks how long a decider takes as the input length grows. Recognizers are not enough for this purpose: if a machine may loop on no-instances, its worst-case time may be infinite.
Worst-case running time. Let be a Turing-machine decider over alphabet . The running time, or time complexity, of is the function defined by
The maximum exists because there are finitely many strings of length , and halts on every one of them.
For each input length, keep the slowest input of that length and forget the easier ones.
If a decider has step counts on the length- inputs over some alphabet, then . If its length- inputs take at most steps, then . Different deciders for the same language may have different running-time functions.
Asymptotic Time Classes
Exact step counts are too sensitive to machine details. Complexity theory compares the eventual growth of running-time functions, ignoring constant factors and finitely many small inputs.
Big-O notation. For functions , write if there exist constants and such that for every ,
Small-o notation. Write if for every constant , there exists such that for every ,
Big-O means "eventually no more than a constant multiple." Small-o means "eventually smaller than every constant multiple."
Recipe: comparing growth rates.
- To prove , choose concrete constants and , then prove for all .
- To disprove , show that is unbounded.
- To prove , show that .
Example 1. Common comparisons.
because exponentials eventually dominate polynomials. But because the ratio grows like . Also , while an eventually positive function never satisfies .
Time complexity class. For a time bound ,
A language belongs to if some decider for it has that asymptotic worst-case bound. A slower decider for the same language does not affect membership in the class.
Typical containments follow directly from growth rates:
Every regular language is in : simulate its DFA and take one constant-time transition per input symbol.
Polynomial time (). is the class of languages decidable in polynomial time by a deterministic Turing machine:
P is the coarse mathematical model of efficient deterministic decision.
Example 2. Languages in .
The language of sorted integer arrays is in : scan adjacent entries and reject at the first inversion. The graph path language
is in by breadth-first search. The language of connected graphs is in by running one graph search from an arbitrary vertex and checking whether every vertex is reached.
Certificates and Verification
Many decision problems have a useful split between finding a solution and checking a proposed solution. The proposed solution is extra data, not part of the original instance.
Certificate. A string intended to prove that an instance is a yes-instance. A verifier receives and checks whether really proves membership.
A decider must answer from alone. A verifier is allowed to be handed the missing clue.
Conjunctive normal form (CNF). A Boolean formula in CNF is an AND of clauses, where each clause is an OR of literals, and each literal is a variable or its negation.
Satisfying assignment. A Boolean assignment to the variables of a formula that makes true.
SAT-verify. The language
is in . Substitute the assignment into the formula and check that every clause contains at least one true literal.
SAT. The satisfiability problem is
Equivalently,
A brute-force decider for SAT tries every truth assignment and runs the verifier on each one. This always halts, but for variables it may check assignments.
Example 3. SAT certificate.
For
the assignment , , is a certificate: each clause has at least one true literal.
Graph problems show the same pattern with certificates that are mappings or subsets.
Graph isomorphism. A graph isomorphism from to is a bijection that preserves adjacency:
Two graphs are isomorphic if at least one such bijection exists.
GI-verify.
This verifier is polynomial-time: check that is a bijection, then check the adjacency equivalence for every pair of vertices.
Graph isomorphism language.
Equivalently, iff some certificate makes .
Independent set. An independent set in a graph is a subset such that no two vertices in are adjacent.
INDSET-verify.
This verifier is polynomial-time: check that , then check every pair and reject if .
Independent set language.
Equivalently, iff some certificate makes .
For SAT, GI, and INDSET, verification is polynomial. The direct search algorithms are still expensive: enumerate all assignments, all bijections, or all vertex subsets.
Verifiers and NP
The certificate pattern becomes a machine model when quantified over all instances.
Verifier for a language. A Turing machine is a verifier for if it halts on certificate pairs and, for every input ,
- if , then there exists a certificate such that accepts ;
- if , then for every certificate , rejects .
Polynomial-time verifier. A verifier is polynomial-time if there is a polynomial such that yes-instances have relevant certificates of length at most , and checks those pairs in time polynomial in .
Equivalently, has a polynomial-time verifier if there is a polynomial-time TM and a polynomial such that
For , no certificate of the allowed length can make accept.
NP. The class is the class of languages that have polynomial-time verifiers.
NP means yes-instances have short certificates that can be checked quickly.
| Model | Input | Yes-instance condition | No-instance condition |
|---|---|---|---|
| Decider | accepts | rejects | |
| Verifier | some is accepted | every is rejected |
By the verifiers above,
Nondeterministic Polynomial Time
The name comes from an equivalent nondeterministic machine definition.
Nondeterministic Turing machine (NTM). A Turing machine whose transition rule may offer several legal next moves:
One input may therefore generate a tree of computations rather than a single run.
A nondeterministic machine accepts if at least one branch finds a successful path.
Nondeterministic decider. An NTM decides if every computation branch halts and, for every input ,
- if , then at least one computation of on accepts;
- if , then every computation of on rejects.
Polynomial-time NTM. An NTM runs in polynomial time if the longest computation branch on any input of length has length bounded by a polynomial in .
Theorem. A language has a polynomial-time verifier if and only if it has a polynomial-time nondeterministic decider.
Proof sketch.
- Verifier to NTM. On input , nondeterministically write a certificate of polynomial length, then run the verifier on . If a valid certificate exists, one branch accepts. If no valid certificate exists, every branch rejects.
- NTM to verifier. Let encode the sequence of nondeterministic choices along one computation branch. The verifier simulates the NTM on , following the choices in , and accepts exactly when that branch accepts.
Nondeterministic time class.
Using the theorem,
This is the same class defined by polynomial-time verifiers.
P versus NP. Every language in is in : a polynomial-time decider can be used as a verifier that ignores the certificate. Thus
Whether is open. The question asks whether every problem whose yes-instances can be checked quickly also has yes/no answers that can be found quickly by a deterministic algorithm.
Cook-Levin theorem (informal). SAT is complete for : a polynomial-time algorithm for SAT would give polynomial-time algorithms for every language in . Therefore
The same is true for INDSET: