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

CSE347
模块
Cse347 L7

Lecture 7

Known NP-Complete Problems

  • SAT and 3-SAT
  • Vertex Cover
  • Independent Set

How to show a problem LL is NP-Complete

  • Show LL \in NP
    • Give a polynomial time certificate
    • Give a polynomial time verifier
  • Show LL is NP-Hard: for some known NP-Complete problem KK, show KpLK \leq_p L
    • Construct a mapping ϕ\phi from instance in KK to instance in LL, given an instance kKk\in K, ϕ(k)L\phi(k)\in L.
    • Show that you can compute ϕ(k)\phi(k) in polynomial time.
    • Show that kKk \in K is true if and only if ϕ(k)L\phi(k) \in L is true.

Example 1: Subset Sum

Input: A set SS of integers and a target positive integer tt.

Problem: Determine if there exists a subset SSS' \subseteq S such that aiSai=t\sum_{a_i\in S'} a_i = t.

We claim that Subset Sum is NP-Complete.

Step 1: Subset Sum \in NP

  • Certificate: SSS' \subseteq S
  • Verifier: Check that aiSai=t\sum_{a_i\in S'} a_i = t

Step 2: Subset Sum is NP-Hard

We claim that 3-SAT p\leq_p Subset Sum

Given any 33-CNF formula Ψ\Psi, we will construct an instance (S,t)(S, t) of Subset Sum such that Ψ\Psi is satisfiable if and only if there exists a subset SSS' \subseteq S such that aiSai=t\sum_{a_i\in S'} a_i = t.

How to construct Ψ\Psi?

Reduction construction:

Assumption: No clause contains both a literal and its negation.

3-SAT problem: Ψ\Psi has nn variables and mm clauses.

Need to: construct SS of positive numbers and a target tt

Idea of construction:

For 3-SAT instance Ψ\Psi:

  • At least one literal in each clause is true
  • A variable and its negation cannot both be true

SS contains integers with n+mn+m digits (base 10)

p1p2pnq1q2qmp_1p_2\cdots p_n q_1 q_2 \cdots q_m

where pip_i are representations of variables that are either 00 or 11 and qjq_j are representations of clauses.

For each variable xix_i, we will have two integers in SS, called viv_i and vi\overline{v_i}.

  • For each variable xix_i, both viv_i and vi\overline{v_i} have digits pi=1p_i=1. all other pp positions are zero

  • Each digit qjq_j in viv_i is 11 if xix_i appears in clause jj; otherwise qj=0q_j=0

For example:

Ψ=(x1¬x2x3)(¬x1x2x3)\Psi=(x_1\lor \neg x_2 \lor x_3) \land (\neg x_1 \lor x_2 \lor x_3)

p1p_1p2p_2p3p_3q1q_1q2q_2
v1v_110010
v1\overline{v_1}10001
v2v_201001
v2\overline{v_2}01010
v3v_300111
v3\overline{v_3}00100
t11111

Let's try to prove correctness of the reduction.

Direction 1: Say subset sum has a solution SS'.

We must prove that there is a satisfying assignment for Ψ\Psi.

Set xi=1x_i=1 if viSv_i\in S'

Set xi=0x_i=0 if viS\overline{v_i}\in S'

  1. We want set xix_i to be both true and false, we will pick (in SS') either viv_i or vi\overline{v_i}
  2. For each clause we have at least one literal that is true since qjq_j has a 11 in the clause.

Direction 2: Say Ψ\Psi has a satisfying assignment.

We must prove that there is a subset SS' such that aiSai=t\sum_{a_i\in S'} a_i = t.

If xi=1x_i=1, then viSv_i\in S'

If xi=0x_i=0, then viS\overline{v_i}\in S'

Problem: 1,2 or 3 literals in every clause can be true.

Fix

Add 2 numbers to SS for each clause jj. We add yj,zjy_j,z_j.

  • All pp digits are zero
  • qjq_j of yjy_j is 11, qjq_j of zjz_j is 22, for all jj, other digits are zero.
  • Intuitively, these numbers account for the number of literals in clause jj that are true.

New target are as follows:

p1p_1p2p_2p3p_3q1q_1q2q_2
y1y_100010
z1z_100020
y2y_200001
z2z_200002
tt11144

Time Complexity of construction for Subset Sum

  • O(n+m)O(n+m)
  • nn is the number of variables
  • mm is the number of clauses

How many integers are in SS?

  • 2n2n for variables
  • 2m2m for new numbers
  • Total: 2n+2m2n+2m integers

How many digits are in each integer?

  • n+mn+m digits
  • Time complexity: O((n+m)2)O((n+m)^2)

Proof of reduction for Subset Sum

Claim 1: If Subset Sum has a solution, then Ψ\Psi is satisfiable.

Proof:

Say SS' is a solution to Subset Sum. Then there exists a subset SSS' \subseteq S such that aiSai=t\sum_{a_i\in S'} a_i = t. Here is an assignment of truth values to variables in Ψ\Psi that satisfies Ψ\Psi:

  • Set xi=1x_i=1 if viSv_i\in S'
  • Set xi=0x_i=0 if viS\overline{v_i}\in S'

This is a valid assignment since:

  • We pick either viv_i or vi\overline{v_i}
  • For each clause, at least one literal is true

EOP

Claim 2: If Ψ\Psi is satisfiable, then Subset Sum has a solution.

Proof:

If AA is a satisfiable assignment for Ψ\Psi, then we can construct a subset SS' of SS such that aiSai=t\sum_{a_i\in S'} a_i = t.

If xi=1x_i=1, then viSv_i\in S'

If xi=0x_i=0, then viS\overline{v_i}\in S'

Say t=t=\sum elements we picked from SS.

  • All pip_i in tt are 11
  • All qjq_j in tt are either 11 or 22 or 33.
    • If qj=1q_j=1, then yj,zjSy_j,z_j\in S'
    • If qj=2q_j=2, then zjSz_j\in S'
    • If qj=3q_j=3, then yjSy_j\in S'

EOP

Example 2: 3 Color

Input: Graph GG

Problem: Determine if GG is 3-colorable.

We claim that 3-Color is NP-Complete.

Proof of NP for 3-Color

Homework

Proof of NP-Hard for 3-Color

We claim that 3-SAT p\leq_p 3-Color

Given a 3-CNF formula Ψ\Psi, we will construct a graph GG such that Ψ\Psi is satisfiable if and only if GG is 3-colorable.

Construction:

  1. Construct a core triangle (3 vertices for 3 colors)
  2. 2 vertices for each variable xi:vi,vix_i:v_i,\overline{v_i}
  3. Clause widget

Clause widget:

  • 3 vertices for each clause Cj:yj,zj,tjC_j:y_j,z_j,t_j (clause widget)
  • 3 edges extended from clause widget
  • variable vertex connected to extended edges

Key for dangler design:

Connect to all viv_i with true to the same color. and connect to all viv_i with false to

// TODO: fix the picture put picture in public folder

Proof of reduction for 3-Color

Direction 1: If Ψ\Psi is satisfiable, then GG is 3-colorable.

Proof:

Say Ψ\Psi is satisfiable. Then viv_i and vi\overline{v_i} are in different colors.

For the color in central triangle, we can pick any color.

For each dangler color is connected to blue, all literals cannot be blue.

...

EOP

Direction 2: If GG is 3-colorable, then Ψ\Psi is satisfiable.

Proof:

EOP

Example 3:Hamiltonian cycle problem (HAMCYCLE)

Input: G(V,E)G(V,E)

Output: Does GG have a Hamiltonian cycle? (A cycle that visits each vertex exactly once.)

Proof is too hard.

but it is an existing NP-complete problem.

On lecture

Example 4: Scheduling problem (SCHED)

scheduling with release time, deadline and execution times.

Given nn jobs, where job ii has release time rir_i, deadline did_i, and execution time tit_i.

Example:

S={2,3,7,5,4}S=\{2,3,7,5,4\}. we created 5 jobs release time is 0, deadline is 26, execution time is 11.

Problem: Can you schedule these jobs so that each job starts after its release time and finishes before its deadline, and executed for tit_i time units?

Proof of NP-completeness

Step 1: Show that the problem is in NP.

Certificate: (hi,ji),(h2,j2),,(hn,jn)\langle (h_i,j_i),(h_2,j_2),\cdots,(h_n,j_n)\rangle, where hih_i is the start time of job ii and jij_i is the machine that job ii is assigned to.

Verifier: Check that hi+tidih_i + t_i \leq d_i for all ii.

Step 2: Show that the problem is NP-hard.

We proceed by proving that SSSpSSS\leq_p Scheduling.

Consider an instance of SSS: {a1,a2,,an}\{ a_1,a_2,\cdots,a_n\} and sum bb. We can create a scheduling instance with release time 0, deadline bb, and execution time 11.

Then we prove that the scheduling instance is a "yes" instance if and only if the SSS instance is a "yes" instance.

Idea of proof:

If there is a subset of {a1,a2,,an}\{a_1,a_2,\cdots,a_n\} that sums to bb, then we can schedule the jobs in that order on one machine.

If there is a schedule where all jobs are finished by time bb, then the sum of the scheduled jobs is exactly bb.

Example 5: Component grouping problem (CG)

Given an undirected graph which is not necessarily connected. (A component is a subgraph that is connected.)

Problem: Component Grouping: Give a graph GG that is not connected, and a positive integer kk, is there a subset of its components that sums up to kk?

Denoted as CG(G,k)CG(G,k).

Proof of NP-completeness for Component Grouping

Step 1: Show that the problem is in NP.

Certificate: S\langle S\rangle, where SS is the subset of components that sums up to kk.

Verifier: Check that the sum of the sizes of the components in SS is kk. This can be done in polynomial time using breadth-first search.

Step 2: Show that the problem is NP-hard.

We proceed by proving that SSSpCGSSS\leq_p CG. (Subset Sum p\leq_p Component Grouping)

Consider an instance of SSS: a1,a2,,an,b\langle a_1,a_2,\cdots,a_n,b\rangle.

We construct an instance of CG as follows:

For each aiSa_i\in S, we create a chain of aia_i vertices.

WARNING: this is not a valid proof for NP hardness since the reduction is not polynomial for nn, where nn is the number of vertices in the SSS instance.