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 .
- 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 .
In other words, we will construct 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.
ify!=w: rejectify==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 (complexity class)
[EXP]
Definition 2. EXP (complexity class) [EXP]
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? 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”. Come up with a language that the “fast” Turing machines cannot possibly decide, that is decidable by a “slow” 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 and P.
The Time Hierarchy theorem tells us that there is something in EXP P. (why? still not clear)
NP and Time Complexity
[cpsc/NP-complexity]
NP and Time Complexity [cpsc/NP-complexity]
NP is very important! Contains a large about of natural problems.
- ex. Hamilton path, 3COLORGRAPH, graph isomorphism, satisfiable boolean formulas
Many problems in NP have “identical complexity”, i.e., are complete. (We’ll talk about this later.)
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!
Recall:
Definition 2. TIME(t(n))
[TIME-tn]
Definition 2. 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:
Definition 3. NTIME(t(n))
[NTIME-tn]
Definition 3. NTIME(t(n)) [NTIME-tn]
NTIME(𝑡(𝑛))={language𝐿:∃NTM𝑀thatdecides𝐿in time𝑂(𝑡(𝑛))}
NP (complexity class)
[cpsc/NP]
NP (complexity class) [cpsc/NP]
Let’s prove that 3colormap is in NP.
Proof: Design a nondeterministic Turing machine to decide 3colormap in polynomial time.
- Iterate through vertices
- Nondetermistically pick a color for each vertex (a “lucky guess”)
- Check all pairs of neighbors to see if they are the same color
- If so reject, otherwise accept
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 :
ifcolor(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. Why?
Because 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?
- Claim: Clique Np (complexity class) ()
- 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, then all of them are in P. NP-completeness!
Definition 4. Polytime Reduction
[polytime-reduction]
Definition 4. Polytime Reduction [polytime-reduction]
Definition 1. Polytime Computable
[polytime-computable]
Definition 1. Polytime Computable [polytime-computable]
For some function , it is polytime computable if there exists a Turing machine that when given as input terminates with on the tape and runs in time .
Let (Let and be languages). is a polytime reduction from to if:
- is a polytime computable function
- ()
- ()
We then may say .
…helpful image…
Example. Polytime Reduction
Suppose , and . Claim:
What does this mean? It means there exists some function that can take a string, map it, and manipulate it so that if , then , and same for converses.
- Proof.
-
Let be the function that flips the bits of its input. Then, we’re done.
Note: these do not need to be bijections!
- A reduction that simply sends all satisfiable inputs to 0 is fine.
Facets of Reductions
[cpsc/reduction-facets]
Facets of Reductions [cpsc/reduction-facets]
Reductions are helpful!
Method: find a way to map:
- yes-instances of to yes-instances of
- no-instances of to no-instances of
- Notation:
- Logic: if is easy, is easy
- Contrapositive: if is hard, is hard
- Theorem.
-
If and , then .
- There is a polytime Turing machine N that decides .
- There is a polytime reduction from to .
- Proof.
-
We want a Turing machine that decides in polynomial time.
- On input : compute and then simulate on input . Accept iff accepts.
- If .
- If .
Question. If we know reduces to and is in , is in ?
Answer. Yes, is a subset of . Mind the direction!
When we talked about Turing machines, we had a notion of what it meant to be hard: undecidability. But now we’re talking about NP. So which problems in NP are hard?
Maybe , and so all problems in NP are easy.
Definition 5. NP-Hardness
[NP-hard]
Definition 5. NP-Hardness [NP-hard]
A language L is NP-hard if it is at least as hard as every problem in NP, i.e. .
There’s nothing in this definition that’s really specific for NP. We could switch it out for other complexity classes if we’d like.
Note: we don’t require our language to be in NP! is NP-hard.
Definition 1. NP-Completeness
[NP-complete]
Definition 1. NP-Completeness [NP-complete]
A language is NP-complete if is NP-hard and .
- Theorem. Cook-Levin Theorem
-
SAT is NP-complete.
- Corollary.
-
3SAT is also NP-complete.
- Theorem.
-
If B is NP-complete, , and , then is NP-complete.
- Proof.
-
- Need to show:
We know , i.e. you can solve in terms of .
- So a polytime computable .
- We know : a polytime computable
Let be . This is polytime computable.
- Has the properties: .
Problem. CLIQUE
[CLIQUE]
Problem. CLIQUE [CLIQUE]
Given and , does there exist with such that for all distinct vertices ?
- No specification on size: in our example above, there are cliques of size 0 through 3
- Theorem.
-
CLIQUE is NP-complete: i.e. CLIQUE is NP-hard, and CLIQUE is in NP.
- Proof.
-
CLIQUE is in NP: because there exists a verifier that can check a possible clique in polytime.
CLIQUE is NP-hard: because 3SAT (known NP-hard problem) reduces to CLIQUE. How can we do that?
- Proof. (reduction)
-
maps to
- If where is a satisfiable 3CNF formula, then where has a clique of size .
maps to
- If where has no satisfiable assignments, then where has no clique of size .
- junk can map to junk
We can show 3SAT can be solved by finding a clique of size .
- Connect every vertex in a block to every other vertex that is not its inverse.
- Then, every clique of size is a possible satisfiable assignment.
- We can’t have and both being true: which is represented by no connecting edges.
We still need to “decode” to … i.e. .
- Let be a clique of size . We must divy it up so that there is exactly one vertex in each group.
- Given a constructed from a problem, then we find a satisfying .
Aside: suppose we want to ensure there is a clique of at least size . We can make a separate, disconnected clique of vertices. What’s this useful for? Don’t know yet…
When designing a reduction: if you want to show that your reduction is correct: you need to show that
- f is polytime computable
- (the converse)
- or, (the inverse)
In a reduction, it’s more typical to show (often straightforward).
- Often want to “decode” to obtain .
Theorem 3. Cook-Levin Theorem
[cook-levin]
Theorem 3. Cook-Levin Theorem [cook-levin]
- Theorem.
-
SAT is in NP (you can construct a verifier that runs in polynomial time)
- Corollary.
-
SAT is NP-complete.
- Proof.
-
To prove this, we must show that .
- What do we know about ? It’s in NP, i.e., there is a nondeterministic Turing machine that decides in polytime
Idea: given a deterministic Turing machine and an input , we can create a circuit such that accepts if and only if evaluates to
true.That’s great, but we really want to construct it for a nondeterministic Turing machine : how can we do that?
- Given and an input , construct a boolean formula with variables as inputs such that accepts if and only if is satisfiable.
- i.e. the nondeterminism is each permutation of the variables, then it’s deterministic to satisfy it
Recall: Behavior of a deterministic Turing machine
- Start = Config(1)
- Config(2) = …
- Config(3) = …
- Config(i) uniquely determines Config(i+1)
- The total amount of configurations we have to look at is , and the total amount of tape we have to look at is also .
Simulating a Turing machine with a tableau
[cpsc/tm-tableau]
Simulating a Turing machine with a tableau [cpsc/tm-tableau]
Main idea: an algorithm can be converted to a Boolean circuit
…table…
M accepts w if and only if the tableau can be filled such that:
- The first row is the starting configuration of M on input w
- configuration follows from the configuration
- Eventually reach an accepting configuration
So how can this tableau be converted into a boolean formula? We’ll come up with some boolean variables to represent what is happening in the cells.
Let refer to the according tableau entry.
- Note: row i: time step, column j: head position,
- Our cell entries are not boolean values: but we still want to encode them as such!
- Create boolean variables where and
For a nondeterministic Turing machine:
- The same table as the deterministic Turing machine:
- only the configuration follows from the configuration using some nondeterministic choice
- : check if any cell is accepting
Window[i,j]: six cells of the table (six cells is convenient: 3x2, we need three to read the current, state, and next items)
- i.e. the window is size 3x2 because that’s exactly what we need to check that it is valid
note: pull examples, when there is no head the last two columns cannot change
… online lecture …
Definition 6. Probabilistic Turing machine
[prob-turing-machine]
Definition 6. Probabilistic Turing machine [prob-turing-machine]
A computation model that begins with a tree. When you reach a branch, you flip a coin!
We can define complexity classes based on the probability of reaching accept/reject leaves.
Definition 1. Randomized Polynomial Time
[RP]
Definition 1. Randomized Polynomial Time [RP]
(Randomized Polytime) if there is a probabilistic Turing machine that, on input , runs in time , and has a greater than or equal to 50% chance of reaching an accepting leaf.
- if the probabilistic Turing machine has a 0% chance of reaching an accepting leaf. (must reach reject state)
Algorithm’s Output Accept Reject Correct Output Accept / true positive / false negative Reject 0 / false positive 1 / true negative if there is a PTM that, on input , runs in time and has behavior:
- :
- :
if there exists a deterministic polytime TM V such that:
- : for at least half of all with ,
- : for all y with ,
Question. Why is RP useful?
Answer. Because we can build things that compute in RP, but we cannot easily simulate NP.
…useful picture…
If there was an NP-complete language in RP, then RP would equal NP.
if there is a TM that, on input , runs in time and has behavior:
- Definition. co-RP
-
if there is a PTM that, on input , runs in time , and has the following behavior:
- (strings in the language) have a 100% chance of being accepted
- have at least or equal to 50% chance of being rejected
Example. A Probabilistic Puzzle
Let be a vector of bits.
There are two possibilities:
- is all zeros
- exactly half of are zeros
Question. How many bits must you look at to tell?
Answer.
- Non-probabilistically: n/2 + 1
- Probabilistically: just one!
Definition 2. Bounded-error Probabilistic Polynomial Time
[BPP]
Definition 2. Bounded-error Probabilistic Polynomial Time [BPP]
(Bounded-error Probabilistic Polytime) if there is a probabilistic Turing machine that, on input , runs in time and has behavior:
- if the probability of accepting is greater than
- if the probability of rejecting is greater than
- ( is arbitrary: we just need )
| Correct Output / Algorithm’s Output | Accept | Reject |
| Accept | / true positive | / false negative |
| Reject | / false positive | / true negative |
…helpful diagram…
Definition 3. Amplification
[amplification]
Definition 3. Amplification [amplification]
Modifying the definition of a little bit: if there is a PTM that, on input , runs in time and has behavior:
Example. Claim:
- Proof.
-
Let . There exists PTM such that , .
Let be the Turing machine on input
- Run on input
- Run on input
ifeither accepted, then acceptelsereject
Advertisement: take CPSC 436R! Nick Harvey’s other course, on Randomized Algorithms
Definition 7. Chemoff Bound
[chemoff-bound]
Definition 7. Chemoff Bound [chemoff-bound]
A Chemoff Bound will let us assert that .