Complexity Theory
[complexity-theory]
Complexity Theory [complexity-theory]
Definition 1. Elephant Jokes
[elephant-jokes]
Definition 1. Elephant Jokes [elephant-jokes]
- How do you shoot a blue elephant?
- With a blue elephant gun.
- How do you shoot a red elephant?
- Hold its trunk shut until it turns blue, then shoot it with a blue elephant gun.
- How do you shoot a purple elephant?
- Paint it red, hold its trunk shut until it turns blue, then shoot it with a blue elephant gun.
Elephants are much like reductions.
Definition 2. Reductions
[reductions]
Definition 2. Reductions [reductions]
Say we have two problems.
- Problem 1.
- Shoot a red elephant.
- Problem 2.
- Shoot a blue elephant.
We can say that reduces to if we can design an algorithm for solving that uses . The following are equivalent:
- reduces to
- can be solved in terms of
- can be solved using as a subroutine
IMPORTANT: Note the order! This is easy to flip-flop!
Given our original problems: this means that the problem of shooting a red elephant can be solved by shooting a blue elephant.
What else does this tell us?
- If is easy, then is easy
- If is hard, then is hard (we’ll use this idea a lot)
- is no harder than
- is at least as hard as
We can similarly talk about languages this way.
means:
- deciding is no harder than deciding , or
- deciding is at least as hard as deciding .
Example. Showing the Halting problem to be undecidable
Last time: is undecidable.
Recall: is recognizable
- You can create a Turing machine that takes an and simulate it: if halts, our original Turing machine accepts
We want to show that . Proof by contradiction:
- Suppose there is a Turing machine that decides (it doesn’t exist).
We want to use to design a Turing machine that decides . Design:
- Use to reject if the input runs forever
- Otherwise, simply simulate the input (it is now guaranteed to be decidable)
- So we can, and we do, and we arrive at a contradiction: as we know there is no such decider for .
Then as reduces to : is at least as hard as , which is undecidable. So is undecidable.
Aside: reduction can go both ways! reduces to , and vice versa. There are (probably) problems that cannot be related, however.
Example. Showing that is undecidable
We will show by reduction: by reducing to , i.e. show a Turing-machine for deciding that uses as a subroutine.
- (i.e. accepts nothing)
Proof: Assume we have a decider that decides . Idea: create a new Turing machine with hardcoded inside.
if y != w: rejectif y == w: then run on input- So the language is either or .
Simulating a Turing machine on input :
- if not of form then reject
- Construct the Turing-machine above
- Run on input
- If accepts, then we know does not accept
- If accepts, rejects, and if rejects, accepts.
Computability vs. Complexity
[computability-complexity]
Computability vs. Complexity [computability-complexity]
What is the difference between this theory of computation and Turing machines, vs. complexity?
Computability-theory studies whether problems have any algorithmic solution whatsoever.
Complexity theory studies whether problems have efficient algorithmic solutions.
- How much time is required?
- How much space is required?
- Does randomness help?
Definition 1. Worst case analysis
[worst-case-analysis]
Definition 1. Worst case analysis [worst-case-analysis]
Usually theorists do worst case analysis, i.e. as a function of the input length , what is the maximum amount of resources used over all inputs of length ? (note: is a commonly used variable!)
The idea here is that it’s helpful to analyze the worst case, as every input will then result in equal or better time.
Definition 1. Runtime
[runtime]
Definition 1. Runtime [runtime]
-
- The runtime of a Turing machine is : . (the number of steps of on input until it halts) (assume is a decider for simplicity)
- The runtime of a nondeterministic Turing machine on input is max-length of any root-leaf path. For deciders – no infinite paths!
Definition 2. Class
[class]
Definition 2. Class [class]
- Complexity theory. A class is a set of languages (or equivalently, computational problems).
Definition 3. Complexity class
[complexity-class]
Definition 3. Complexity class [complexity-class]
A complexity class is a class defined by Turing machine resource constraints.
Definition 4. TIME(t(n))
[time-tn]
Definition 4. TIME(t(n)) [time-tn]
is the class of all languages such that there exists a Turing machine with runtime that decides .
In briefer notation:
Definition 1. P (complexity class)
[p]
Definition 1. P (complexity class) [p]
Why is P a good definition for efficient computation?
- Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
- Closed under composition: can use polynomial time algorithm as a subroutine
- In practice: algorithms usually can be improved. If we find an time algorithm, it typically can be improved to, say, time.
Example. 2COLORMAP
Let be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.
Question. The two color map does not work for every map. So consider it as a problem: . Is 2COLORMAP P?
Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.
It’s unknown if the three color map is in P. It’s known to be in EXP:
Recall: different machine models have different efficiencies: our multi-tape Turing machines were broadly more efficient than our single-tape Turing machines.
Example.
- Decided by a single-tape Turing machine in time
- Decided by a multi-tape Turing machine in time
Revising the Church-Turing thesis
[extended-church-turing]
Revising the Church-Turing thesis [extended-church-turing]
The extended Church-Turing thesis is the belief that Turing machines capture our intuitive notion of what is efficiently computable. It postulates that everything we can compute in time on any physical computer can be computed on a Turing machine in time , for some constant .
Is this true, does it hold? Maybe not, with newer forms of computation like quantum computers.
Definition 3. P and EXP
[p-exp]
Definition 3. P and EXP [p-exp]
Definition 1. P (complexity class)
[p]
Definition 1. P (complexity class) [p]
Why is P a good definition for efficient computation?
- Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
- Closed under composition: can use polynomial time algorithm as a subroutine
- In practice: algorithms usually can be improved. If we find an time algorithm, it typically can be improved to, say, time.
Example. 2COLORMAP
Let be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.
Question. The two color map does not work for every map. So consider it as a problem: . Is 2COLORMAP P?
Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.
It’s unknown if the three color map is in P. It’s known to be in EXP:
Definition 2. EXP
[exp]
Definition 2. EXP [exp]
$`\text{EXP}` = \bigcup_{k > 0}\text{TIME}\left( 2^{n^{k}} \right)$
The four color map works for all maps, so .
Theorem 1. Time Hierarchy Theorem
[time-hierarchy]
Theorem 1. Time Hierarchy Theorem [time-hierarchy]
Question: is Exp P (complexity class)? Answer: No!
The time hierarchy theorem tells us that given an that is “reasonable” where , then the .
Notably, !
Corollary.
for any .
Corollary.
for any .
Question. How do you prove the Time hierarchy theorem?
Answer. By diagonalization. Look at Turing machines that are “fast” and Turing machines that are “slow”.
Idea: Look at all Turing machines that run in “fast” time, and come up with a language that they cannot possibly decide.
But we want that language to be decidable by a “slow” Turing machine.
Time Complexity
[time-complexity]
Time Complexity [time-complexity]
Where is 3COLORMAP? We know it is in Exp, and either in Np (complexity class) or in both Np (complexity class) and P (complexity class).
The Time Hierarchy theorem tells us that there is something in Exp P (complexity class). (why? still not clear)
Theorem 2. Certificates and Verifiers
[certificates-verifiers]
Theorem 2. Certificates and Verifiers [certificates-verifiers]
NP has two main, equivalent definitions:
- There exists a nondeterministic polytime TM that decides .
There exists a deterministic polytime TM and a constant s.t.:
- where is the “input”, is the “certificate”, is the “verifier”
i.e. for the three color graph, give us a colored graph and we can verify it
The certificate serves as the verifier ’s substitute for nondeterminism.
Example. Verifying 3colormap
Claim: 3colormap Np (complexity class).
- Must find a deterministic polytime TM V s.t.
Code for : on input
- If not of form , where is a Graph, reject
- From , extract values for each
- For every edge :
if color(u) == color(v), reject - Otherwise accept
- does exist, it’s simply a valid coloring of the graph
To show correctness of , we need three things:
If and G is 3-colorable: need and .
- It does exist, can be a valid 3 coloring of . Note: and
If where G is 3-colorable: then no certificate should make erroneously accept.
- If not of form : definitely rejects.
- If of form by not 3-colorable, then must reject because it always checks that is a valid coloring.
Must check that runs in time polynomial in .
Example. Proofs of equivalence of our NP definitions
Proof.
- Given verifier , must construct a NTM deciding
Inputs to the verifier are and , with
- : input string
- : certificate (like a proof that is in the language)
Code for :
- On input , nondeterministically pick with
- Run on input
- Accept if accepts. Reject if rejects.
i.e. Suppose . If , so does not accept .
Proof.
- Given an NTM , you can convert that into a verifier for .
- Input to is , runtime is at most
Idea: simulates the tree, but only on a single branch of configuration tree. specifies which branch. nondeterminism comes into play by letting us pick the correct branch.
- our nondeterminism lets us pick the correct branch: then the term is the depth of the path, which is at most polynomial
Code for :
- Simulate deterministically on input , using as the sequence of nondeterministic decisions
- Accept if accepts. Reject if rejects.
Why NP is nice
[cpsc/why-np]
Why NP is nice [cpsc/why-np]
We’ll spend the next couple of lectures talking about Np (complexity class). Why? Nondeterministic Turing machines are ridiculously impractical!
Many problems that we’re interested in have the form (where is the problem input and is the object we are seeking).
Efficient test: is a valid solution?
We showed 3COLOR Np (complexity class).
- Claim: Clique Np (complexity class) (Clique={⟨𝐺,𝐾⟩:𝐺contains acliqueof size𝑘})
- Claim: Hampath Np (complexity class) (Hamiltonian path problem)
Np (complexity class) has lots of problems that are interesting and nice to solve, but that we don’t know of any polynomial time solution. But: if any of these problems are in P (complexity class), then all of them are in P (complexity class). NP-completeness!