9.4 KiB
CSE347 Analysis of Algorithms (Lecture 7)
Known NP-Complete Problems
- SAT and 3-SAT
- Vertex Cover
- Independent Set
How to show a problem L is NP-Complete
- Show
L \inNP- Give a polynomial time certificate
- Give a polynomial time verifier
- Show
Lis NP-Hard: for some known NP-Complete problemK, showK \leq_p L- Construct a mapping
\phifrom instance inKto instance inL, given an instancek\in K,\phi(k)\in L. - Show that you can compute
\phi(k)in polynomial time. - Show that
k \in Kis true if and only if\phi(k) \in Lis true.
- Construct a mapping
Example 1: Subset Sum
Input: A set S of integers and a target positive integer t.
Problem: Determine if there exists a subset S' \subseteq S such that \sum_{a_i\in S'} a_i = t.
We claim that Subset Sum is NP-Complete.
Step 1: Subset Sum \in NP
- Certificate:
S' \subseteq S - Verifier: Check that
\sum_{a_i\in S'} a_i = t
Step 2: Subset Sum is NP-Hard
We claim that 3-SAT \leq_p Subset Sum
Given any $3$-CNF formula \Psi, we will construct an instance (S, t) of Subset Sum such that \Psi is satisfiable if and only if there exists a subset S' \subseteq S such that \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 n variables and m clauses.
Need to: construct S of positive numbers and a target t
Ideas 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
S contains integers with n+m digits (base 10)
p_1p_2\cdots p_n q_1 q_2 \cdots q_m
where p_i are representations of variables that are either 0 or 1 and q_j are representations of clauses.
For each variable x_i, we will have two integers in S, called v_i and \overline{v_i}.
-
For each variable
x_i, bothv_iand\overline{v_i}have digitsp_i=1. all otherppositions are zero -
Each digit
q_jinv_iis1ifx_iappears in clausej; otherwiseq_j=0
For example:
\Psi=(x_1\lor \neg x_2 \lor x_3) \land (\neg x_1 \lor x_2 \lor x_3)
p_1 |
p_2 |
p_3 |
q_1 |
q_2 |
|
|---|---|---|---|---|---|
v_1 |
1 | 0 | 0 | 1 | 0 |
\overline{v_1} |
1 | 0 | 0 | 0 | 1 |
v_2 |
0 | 1 | 0 | 0 | 1 |
\overline{v_2} |
0 | 1 | 0 | 1 | 0 |
v_3 |
0 | 0 | 1 | 1 | 1 |
\overline{v_3} |
0 | 0 | 1 | 0 | 0 |
| t | 1 | 1 | 1 | 1 | 1 |
Let's try to prove correctness of the reduction.
Direction 1: Say subset sum has a solution S'.
We must prove that there is a satisfying assignment for \Psi.
Set x_i=1 if v_i\in S'
Set x_i=0 if \overline{v_i}\in S'
- We want set
x_ito be both true and false, we will pick (inS') eitherv_ior\overline{v_i} - For each clause we have at least one literal that is true since
q_jhas a1in the clause.
Direction 2: Say \Psi has a satisfying assignment.
We must prove that there is a subset S' such that \sum_{a_i\in S'} a_i = t.
If x_i=1, then v_i\in S'
If x_i=0, then \overline{v_i}\in S'
Problem: 1,2 or 3 literals in every clause can be true.
Fix
Add 2 numbers to S for each clause j. We add y_j,z_j.
- All
pdigits are zero q_jofy_jis1,q_jofz_jis2, for allj, other digits are zero.- Intuitively, these numbers account for the number of literals in clause
jthat are true.
New target are as follows:
p_1 |
p_2 |
p_3 |
q_1 |
q_2 |
|
|---|---|---|---|---|---|
y_1 |
0 | 0 | 0 | 1 | 0 |
z_1 |
0 | 0 | 0 | 2 | 0 |
y_2 |
0 | 0 | 0 | 0 | 1 |
z_2 |
0 | 0 | 0 | 0 | 2 |
t |
1 | 1 | 1 | 4 | 4 |
Time Complexity of construction for Subset Sum
O(n+m)nis the number of variablesmis the number of clauses
How many integers are in S?
2nfor variables2mfor new numbers- Total:
2n+2mintegers
How many digits are in each integer?
n+mdigits- Time complexity:
O((n+m)^2)
Proof of reduction for Subset Sum
Claim 1: If Subset Sum has a solution, then \Psi is satisfiable.
Proof
Say S' is a solution to Subset Sum. Then there exists a subset S' \subseteq S such that \sum_{a_i\in S'} a_i = t. Here is an assignment of truth values to variables in \Psi that satisfies \Psi:
- Set
x_i=1ifv_i\in S' - Set
x_i=0if\overline{v_i}\in S'
This is a valid assignment since:
- We pick either
v_ior\overline{v_i} - For each clause, at least one literal is true
Claim 2: If \Psi is satisfiable, then Subset Sum has a solution.
Proof
If A is a satisfiable assignment for \Psi, then we can construct a subset S' of S such that \sum_{a_i\in S'} a_i = t.
If x_i=1, then v_i\in S'
If x_i=0, then \overline{v_i}\in S'
Say t=\sum elements we picked from S.
- All
p_iintare1 - All
q_jintare either1or2or3.- If
q_j=1, theny_j,z_j\in S' - If
q_j=2, thenz_j\in S' - If
q_j=3, theny_j\in S'
- If
Example 2: 3 Color
Input: Graph G
Problem: Determine if G 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 \leq_p 3-Color
Given a 3-CNF formula \Psi, we will construct a graph G such that \Psi is satisfiable if and only if G is 3-colorable.
Construction:
- Construct a core triangle (3 vertices for 3 colors)
- 2 vertices for each variable
x_i:v_i,\overline{v_i} - Clause widget
Clause widget:
- 3 vertices for each clause
C_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 v_i with true to the same color. and connect to all v_i with false to another color.
Tip
TODO: Add dangler design image here.
Proof of reduction for 3-Color
Direction 1: If \Psi is satisfiable, then G is 3-colorable.
Proof
Say \Psi is satisfiable. Then v_i and \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.
...
Direction 2: If G is 3-colorable, then \Psi is satisfiable.
Proof
Example 3:Hamiltonian cycle problem (HAMCYCLE)
Input: G(V,E)
Output: Does G 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 n jobs, where job i has release time r_i, deadline d_i, and execution time t_i.
Example:
S=\{2,3,7,5,4\}. we created 5 jobs release time is 0, deadline is 26, execution time is 1.
Problem: Can you schedule these jobs so that each job starts after its release time and finishes before its deadline, and executed for t_i time units?
Proof of NP-completeness
Step 1: Show that the problem is in NP.
Certificate: \langle (h_i,j_i),(h_2,j_2),\cdots,(h_n,j_n)\rangle, where h_i is the start time of job i and j_i is the machine that job i is assigned to.
Verifier: Check that h_i + t_i \leq d_i for all i.
Step 2: Show that the problem is NP-hard.
We proceed by proving that SSS\leq_p Scheduling.
Consider an instance of SSS: \{ a_1,a_2,\cdots,a_n\} and sum b. We can create a scheduling instance with release time 0, deadline b, and execution time 1.
Then we prove that the scheduling instance is a "yes" instance if and only if the SSS instance is a "yes" instance.
Ideas of proof:
If there is a subset of \{a_1,a_2,\cdots,a_n\} that sums to b, then we can schedule the jobs in that order on one machine.
If there is a schedule where all jobs are finished by time b, then the sum of the scheduled jobs is exactly b.
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 G that is not connected, and a positive integer k, is there a subset of its components that sums up to k?
Denoted as CG(G,k).
Proof of NP-completeness for Component Grouping
Step 1: Show that the problem is in NP.
Certificate: \langle S\rangle, where S is the subset of components that sums up to k.
Verifier: Check that the sum of the sizes of the components in S is k. 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 SSS\leq_p CG. (Subset Sum \leq_p Component Grouping)
Consider an instance of SSS: \langle a_1,a_2,\cdots,a_n,b\rangle.
We construct an instance of CG as follows:
For each a_i\in S, we create a chain of a_i vertices.
WARNING: this is not a valid proof for NP hardness since the reduction is not polynomial for n, where n is the number of vertices in the SSS instance.