Lecture 6
NP-completeness
: Polynomial-time Solvable
: Class of decision problems such that there is a polynomial-time algorithm that correctly answers yes or not for every instance .
Algorithm " decides ". If algorithm always correctly answers for any instance .
Example:
Is the number prime? Best algorithm so far: , 2002
Introduction to NP
- NP Non-polynomial (Non-deterministic polynomial time)
- Let be a decision problem.
- Let be an instance of the problem that the answer happens to be "yes".
- A certificate c(l) for is a "proof" that the answer for is true. [ is a true instance]
- For canonical decision problems for optimization problems, the certificate is often a feasible solution for the corresponding optimization problem.
Example of certificates
- Problem: Is there a path from to
- Instance: graph .
- Certificate: path from to .
- Problem: Can I schedule intervals in the room so that they do not conflict.
- Instance:
- Certificate: set of non-conflicting intervals.
- Problem: ISET
- Instance: .
- Certificate: vertices with no edges between them.
If the answer to the problem is NO, you don't need to provide anything to prove that.
Useful certificates
For a problem to be in NP, the problem need to have "useful" certificates. What is considered a good certificate?
- Easy to check
- Verifying algorithm which can check a YES answer and a certificate in
- Not too long: []
Verifier Algorithm
Verifier algorithm is one that takes an instance and a certificate and says yes if the certificate proves that is a true instance and false otherwise.
is a poly-time verifier for is it is a verifier and runs in time. (c=)
- The runtime must be polynomial
- Must check every problem constraint
- Not always trivial
Class NP
NP: A class of decision problems such that exists a certificate schema and a verifier algorithm such that:
- certificate is in size.
- in time.
P: is a class of problems that you can solve in polynomial time
NP: is a class of problems that you can verify TRUE instances in polynomial time given a poly-size certificate
Millennium question
? ?
is true.
Proof: Let be a problem in , we want to show that there is a polynomial size certificate with a poly-time verifier.
There is an algorithm which solves in polynomial time.
Certificate: empty thing.
Verifier:
- Discard .
- Run on and return the answer.
Nobody knows the solution . Sad.
Class of problem: NP complete
Informally: hardest problem in NP
Consider a problem .
- We want to show if , then
NP-hard: A decision problem is NP-hard if for any problem , .
is at least as hard as all the problems in NP. If we have an algorithm for , we have an algorithm for any problem in NP with only polynomial time extra cost.
MindMap:
Lemma
Let be an NP-hard problem. If , then .
Proof:
Say has a poly-time solution, some problem in .
For any , , , then .
NP-complete: is NP-complete if it is both NP-hard and .
NP-optimization: is NP-optimization problem if the canonical decision problem is NP-complete.
Claim: If any NP-optimization problem have polynomial-time solution, then .
Is ?
- Answering this problem is hard.
- But for any NP-complete problem, if you could find a poly-time algorithm for , then you would have answered this question.
- Therefore, finding a poly-time algorithm for is hard.
NP-Complete problem
Satisfiability (SAT)
Boolean Formulas:
A set of Boolean variables:
they take values true or false.
A boolean formula is a formula of Boolean variables with and, or and not.
Examples:
, the formula is .
SAT: given a formula , is there a setting of variables such that the evaluates to True under this setting.
If there is such assignment, then is satisfiable. Otherwise, it is not.
Example: is not satisfiable.
A seminar paper by Cook and Levin in 1970 showed that SAT is NP-complete.
- SAT is in NP
Proof:
a certificate schema and a poly-time verifier.
satisfying assignment and check that makes true. - SAT is NP-hard. we can just accept it has a fact.
How to show a problem is NP-complete?
Say we have a problem .
- Show that .
Exists certificate schema and verification algorithm in polynomial time. - Prove that we can reduce SAT to . (NOT ) Solving also solve SAT.
CNF-SAT
CNF: Conjugate normal form of SAT
The formula must be an "and of ors"
: clause
3-CNF-SAT
3-CNF-SAT: where every clauses has exactly 3 literals.
is NP complete [not all version of them are, 2-CNF-SAT is in P]
Input: 3-CNF expression with variables and clauses in the form:
number of total literals:
Output: An assignment of the variables such that at least one literal from each clauses evaluates to true.
Note:
- One variable can be used to satisfy multiple clauses.
- and cannot both evaluate to true.
Example: ISET is NP-complete.
Proof:
Say we have a problem
- Show that
Certificate: set of vertices:
Verifier: checks that there are no edges between them - ISET is NP-hard. We need to prove
- Construct a reduction from to .
- Show that is harder than .
We need to prove is satisfiable if and only if the constructed has an of size
Reduction mapping construction
We construct an ISET instance from .
Suppose the formula has variables and clauses
- for each clause, we construct vertex for each literal and connect them (for , we connect together)
- then we connect all the literals with their negations (connects and )
If has a satisfiable assignment, then has an independent set of size ,
For a set we pick exactly one true literal from every clause and take the corresponding vertex to that clause,
Must also argue that is an independent set.
Example: picked a set of vertices .
A literal has edges:
- To all literals in the same clause: We never pick two literals form the same clause.
- To its negation.
Since it is a satisfiable 3-SAT assignment, and cannot both evaluate to true, those edges are not a problem, so is an independent set.
If has an independent set of size , then is satisfiable.
Say that is an independent set of , we need to construct a satisfiable assignment for the original .
- If contains a vertex corresponding to literal , then set to true.
- If contains a vertex corresponding to literal , then set to false.
- Other variables can be set arbitrarily
Question: Is it a valid 3-SAT assignment?
Your ISET can contain at most vertex from each clause. Since vertices in a clause are connected by edges.
- Since contains vertices, it must contain exactly vertex from each clause.
- Therefore, we will make at least literals form each clause to be true.
- Therefore, all the clauses are true and is satisfied.
Conclusion: NP-completeness
- Prove NP-Complete:
- If NP-optimization, convert to canonical decision problem
- Certificate, Verification algorithm
- Prove NP-hard: reduce from existing NP-Complete problems
- 3-SAT Problem:
- Input, output, constraints
- A well-known NP-Complete problem
- Reduce from 3-SAT to ISET to show ISET is NP-Complete
On class
NP-complete
, if we have a certificate schema and a verifier algorithm.
NP-complete proof
P is in NP
what a certificate would looks like, show that if has a polynomial time o the problem size.
design a verifier algorithm that checks a certificate if it indeed prove tha the answer is YES and has a polynomial time complexity. Inputs: certificate and the problem input
P is NP hard
select an already known NP-hard problem: eg. 3-SAT, ISET, VC,...
show that
- present an algorithm that given any instance of 3-SAT (on the chosen NP hard problem) to an instance of .
- show that the construction is done in polynomial time.
- show that if 's instance answer is YES, then the instance of 3-SAT is YES.
- show that if 3-SAT's instance answer is YES then the instance of is YES.