Lecture 7
Known NP-Complete Problems
- SAT and 3-SAT
- Vertex Cover
- Independent Set
How to show a problem is NP-Complete
- Show NP
- Give a polynomial time certificate
- Give a polynomial time verifier
- Show is NP-Hard: for some known NP-Complete problem , show
- Construct a mapping from instance in to instance in , given an instance , .
- Show that you can compute in polynomial time.
- Show that is true if and only if is true.
Example 1: Subset Sum
Input: A set of integers and a target positive integer .
Problem: Determine if there exists a subset such that .
We claim that Subset Sum is NP-Complete.
Step 1: Subset Sum NP
- Certificate:
- Verifier: Check that
Step 2: Subset Sum is NP-Hard
We claim that 3-SAT Subset Sum
Given any -CNF formula , we will construct an instance of Subset Sum such that is satisfiable if and only if there exists a subset such that .
How to construct ?
Reduction construction:
Assumption: No clause contains both a literal and its negation.
3-SAT problem: has variables and clauses.
Need to: construct of positive numbers and a target
Idea of construction:
For 3-SAT instance :
- At least one literal in each clause is true
- A variable and its negation cannot both be true
contains integers with digits (base 10)
where are representations of variables that are either or and are representations of clauses.
For each variable , we will have two integers in , called and .
-
For each variable , both and have digits . all other positions are zero
-
Each digit in is if appears in clause ; otherwise
For example:
1 | 0 | 0 | 1 | 0 | |
1 | 0 | 0 | 0 | 1 | |
0 | 1 | 0 | 0 | 1 | |
0 | 1 | 0 | 1 | 0 | |
0 | 0 | 1 | 1 | 1 | |
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 .
We must prove that there is a satisfying assignment for .
Set if
Set if
- We want set to be both true and false, we will pick (in ) either or
- For each clause we have at least one literal that is true since has a in the clause.
Direction 2: Say has a satisfying assignment.
We must prove that there is a subset such that .
If , then
If , then
Problem: 1,2 or 3 literals in every clause can be true.
Fix
Add 2 numbers to for each clause . We add .
- All digits are zero
- of is , of is , for all , other digits are zero.
- Intuitively, these numbers account for the number of literals in clause that are true.
New target are as follows:
0 | 0 | 0 | 1 | 0 | |
0 | 0 | 0 | 2 | 0 | |
0 | 0 | 0 | 0 | 1 | |
0 | 0 | 0 | 0 | 2 | |
1 | 1 | 1 | 4 | 4 |
Time Complexity of construction for Subset Sum
- is the number of variables
- is the number of clauses
How many integers are in ?
- for variables
- for new numbers
- Total: integers
How many digits are in each integer?
- digits
- Time complexity:
Proof of reduction for Subset Sum
Claim 1: If Subset Sum has a solution, then is satisfiable.
Proof:
Say is a solution to Subset Sum. Then there exists a subset such that . Here is an assignment of truth values to variables in that satisfies :
- Set if
- Set if
This is a valid assignment since:
- We pick either or
- For each clause, at least one literal is true
EOP
Claim 2: If is satisfiable, then Subset Sum has a solution.
Proof:
If is a satisfiable assignment for , then we can construct a subset of such that .
If , then
If , then
Say elements we picked from .
- All in are
- All in are either or or .
- If , then
- If , then
- If , then
EOP
Example 2: 3 Color
Input: Graph
Problem: Determine if 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 3-Color
Given a 3-CNF formula , we will construct a graph such that is satisfiable if and only if is 3-colorable.
Construction:
- Construct a core triangle (3 vertices for 3 colors)
- 2 vertices for each variable
- Clause widget
Clause widget:
- 3 vertices for each clause (clause widget)
- 3 edges extended from clause widget
- variable vertex connected to extended edges
Key for dangler design:
Connect to all with true to the same color. and connect to all with false to
// TODO: fix the picture put picture in public folder
Proof of reduction for 3-Color
Direction 1: If is satisfiable, then is 3-colorable.
Proof:
Say is satisfiable. Then and 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 is 3-colorable, then is satisfiable.
Proof:
EOP
Example 3:Hamiltonian cycle problem (HAMCYCLE)
Input:
Output: Does 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 jobs, where job has release time , deadline , and execution time .
Example:
. we created 5 jobs release time is 0, deadline is 26, execution time is .
Problem: Can you schedule these jobs so that each job starts after its release time and finishes before its deadline, and executed for time units?
Proof of NP-completeness
Step 1: Show that the problem is in NP.
Certificate: , where is the start time of job and is the machine that job is assigned to.
Verifier: Check that for all .
Step 2: Show that the problem is NP-hard.
We proceed by proving that Scheduling.
Consider an instance of SSS: and sum . We can create a scheduling instance with release time 0, deadline , and execution time .
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 that sums to , then we can schedule the jobs in that order on one machine.
If there is a schedule where all jobs are finished by time , then the sum of the scheduled jobs is exactly .
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 that is not connected, and a positive integer , is there a subset of its components that sums up to ?
Denoted as .
Proof of NP-completeness for Component Grouping
Step 1: Show that the problem is in NP.
Certificate: , where is the subset of components that sums up to .
Verifier: Check that the sum of the sizes of the components in is . 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 . (Subset Sum Component Grouping)
Consider an instance of SSS: .
We construct an instance of CG as follows:
For each , we create a chain of vertices.
WARNING: this is not a valid proof for NP hardness since the reduction is not polynomial for , where is the number of vertices in the SSS instance.