🎉 从330转为WashU帮助手册啦!

CSE347
模块
Cse347 L6

Lecture 6

NP-completeness

PP: Polynomial-time Solvable

PP: Class of decision problems LL such that there is a polynomial-time algorithm that correctly answers yes or not for every instance lLl\in L.

Algorithm "AA decides LL". If algorithm AA always correctly answers for any instance lLl\in L.

Example:

Is the number nn prime? Best algorithm so far: O(log6n)O(\log^6 n), 2002

Introduction to NP

  • NP\neq Non-polynomial (Non-deterministic polynomial time)
  • Let LL be a decision problem.
  • Let ll be an instance of the problem that the answer happens to be "yes".
  • A certificate c(l) for ll is a "proof" that the answer for ll is true. [ll 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 ss to tt
    • Instance: graph G(V,E),s,tG(V,E),s,t.
    • Certificate: path from ss to tt.
  • Problem: Can I schedule kk intervals in the room so that they do not conflict.
    • Instance: l:(I,k)l:(I,k)
    • Certificate: set of kk non-conflicting intervals.
  • Problem: ISET
    • Instance: G(V,E),kG(V,E),k.
    • Certificate: kk 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 poly(l)poly(l)
  • Not too long: [poly(l)poly(l)]

Verifier Algorithm

Verifier algorithm is one that takes an instance lLl\in L and a certificate c(l)c(l) and says yes if the certificate proves that ll is a true instance and false otherwise.

VV is a poly-time verifier for LL is it is a verifier and runs in poly(l,c)poly(|l|,|c|) time. (c=poly(l)poly(l))

  • 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 cc and a verifier algorithm VV such that:

  1. certificate is poly(l)poly(l) in size.
  2. V:poly(l)V:poly(l) 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

PNPP\subseteq NP? NPPNP\subseteq P?

PNPP\subseteq NP is true.

Proof: Let LL be a problem in PP, we want to show that there is a polynomial size certificate with a poly-time verifier.

There is an algorithm AA which solves LL in polynomial time.

Certificate: empty thing.

Verifier: (l,c)(l,c)

  1. Discard cc.
  2. Run AA on ll and return the answer.

Nobody knows the solution NPPNP\subseteq P. Sad.

Class of problem: NP complete

Informally: hardest problem in NP

Consider a problem LL.

  • We want to show if LPL\subseteq P, then NPPNP\subseteq P

NP-hard: A decision problem LL is NP-hard if for any problem KNPK\in NP, KpLK\leq_p L.

LL is at least as hard as all the problems in NP. If we have an algorithm for LL, we have an algorithm for any problem in NP with only polynomial time extra cost.

MindMap:

K    L    sol(L)    sol(K)K\implies L\implies sol(L)\implies sol(K)

Lemma P=NPP=NP

Let LL be an NP-hard problem. If LPL\in P, then P=NPP=NP.

Proof:

Say LL has a poly-time solution, some problem KK in NPNP.

For any KNPK\in NP, NPPNP\subset P, PNPP\subset NP, then P=NPP=NP.

NP-complete: LL is NP-complete if it is both NP-hard and LNPL\in NP.

NP-optimization: LL is NP-optimization problem if the canonical decision problem is NP-complete.

Claim: If any NP-optimization problem have polynomial-time solution, then P=NPP=NP.

Is P=NPP=NP?

  • Answering this problem is hard.
  • But for any NP-complete problem, if you could find a poly-time algorithm for LL, then you would have answered this question.
  • Therefore, finding a poly-time algorithm for LL is hard.

NP-Complete problem

Satisfiability (SAT)

Boolean Formulas:

A set of Boolean variables:

x,y,a,b,c,w,z,...x,y,a,b,c,w,z,... they take values true or false.

A boolean formula is a formula of Boolean variables with and, or and not.

Examples:

ϕ:x(¬yz)¬(yw)\phi:x\land (\neg y \lor z)\land\neg(y\lor w)

x=1,y=0,z=1,w=0x=1,y=0,z=1,w=0, the formula is 11.

SAT: given a formula ϕ\phi, is there a setting MM of variables such that the ϕ\phi evaluates to True under this setting.

If there is such assignment, then ϕ\phi is satisfiable. Otherwise, it is not.

Example: xy¬(xy)x\land y\land \neg(x\lor y) is not satisfiable.

A seminar paper by Cook and Levin in 1970 showed that SAT is NP-complete.

  1. SAT is in NP
    Proof:
    \exists a certificate schema and a poly-time verifier.
    cc satisfying assignment MM and vv check that MM makes ϕ\phi true.
  2. 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 LL.

  1. Show that LNPL\in NP.
    Exists certificate schema and verification algorithm in polynomial time.
  2. Prove that we can reduce SAT to LL. SATpLSAT\leq_p L (NOT LpSATL\leq_p SAT) Solving LL also solve SAT.

CNF-SAT

CNF: Conjugate normal form of SAT

The formula ϕ\phi must be an "and of ors"

ϕ=i=1n(j=1mili,j)\phi=\land_{i=1}^n(\lor^{m_i}_{j=1}l_{i,j})

li,jl_{i,j}: 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 nn variables and mm clauses in the form:

number of total literals: 3m3m

Output: An assignment of the nn variables such that at least one literal from each clauses evaluates to true.

Note:

  1. One variable can be used to satisfy multiple clauses.
  2. xix_i and ¬xi\neg x_i cannot both evaluate to true.

Example: ISET is NP-complete.

Proof:

Say we have a problem LL

  1. Show that ISETNPISET\in NP
    Certificate: set of kk vertices: S=kpoly(g)|S|=k\in poly(g)
    Verifier: checks that there are no edges between them O(Ek2)O(E k^2)
  2. ISET is NP-hard. We need to prove 3SATpISET3SAT\leq_p ISET
    • Construct a reduction from 3SAT3SAT to ISETISET.
    • Show that ISETISET is harder than 3SAT3SAT.

We need to prove ϕ3SAT\phi\in 3SAT is satisfiable if and only if the constructed GG has an ISETISET of size k=m\geq k=m

Reduction mapping construction

We construct an ISET instance from 3SAT3-SAT.

Suppose the formula has nn variables and mm clauses

  1. for each clause, we construct vertex for each literal and connect them (for x¬yzx\lor \neg y\lor z, we connect x,¬y,zx,\neg y,z together)
  2. then we connect all the literals with their negations (connects xx and ¬x\neg x)

    \implies

If ϕ\phi has a satisfiable assignment, then GG has an independent set of size m\geq m,

For a set SS we pick exactly one true literal from every clause and take the corresponding vertex to that clause, S=m|S|=m

Must also argue that SS is an independent set.

Example: picked a set of vertices S=4|S|=4.

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, xx and ¬x\neg x cannot both evaluate to true, those edges are not a problem, so SS is an independent set.

    \impliedby

If GG has an independent set of size m\geq m, then ϕ\phi is satisfiable.

Say that SS is an independent set of mm, we need to construct a satisfiable assignment for the original ϕ\phi.

  • If SS contains a vertex corresponding to literal xix_i, then set xix_i to true.
  • If contains a vertex corresponding to literal ¬xi\neg x_i, then set xix_i to false.
  • Other variables can be set arbitrarily

Question: Is it a valid 3-SAT assignment?

Your ISET SS can contain at most 11 vertex from each clause. Since vertices in a clause are connected by edges.

  • Since SS contains mm vertices, it must contain exactly 11 vertex from each clause.
  • Therefore, we will make at least 11 literals form each clause to be true.
  • Therefore, all the clauses are true and ϕ\phi 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

pNPp\in NP, 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 poly(l,c)=poly(p)poly(|l|,|c|)=poly(|p|)

P is NP hard

select an already known NP-hard problem: eg. 3-SAT, ISET, VC,...

show that 3SATpp3-SAT\leq_p p

  • present an algorithm that given any instance of 3-SAT (on the chosen NP hard problem) to an instance of pp.
  • show that the construction is done in polynomial time.
  • show that if pp'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 pp is YES.