NP Flashcards
(77 cards)
How to show a problem is in NP
Algorithm must be provided that can verify proposed solution (S) given an instance (I) efficiently in polynomial time relative to the size of I.
[SAT]
Input
Boolean formula in CNF with n variables and m clause
[SAT]
Output
Satisfying assignment or NO
[SAT]
NP Proof - Show that SAT is in NP
Given f & assignment x1 … xn:
O(n) time to check that a clause is satisfied for m clauses.
O(nm) total time to verify.
[3SAT]
NP Proof - Show that 3SAT is in NP
Given f & assignment x1 … xn:
Check a clause is satisfied O(1) (bc size of clauses is bounded by a constant)
m clauses, so O(m) and polynomial
[Colorings]
Show that k-colorings is in NP
Given a k-coloring, check each edge to ensure endpoints have different colors, O(n+m)
[MST]
Proof that MST is in NP
We can verify solution in poly-time by 2 checks:
- T is a tree: Run BFS to check connectivity, O(n+m)
- T is minimum weight: Compare MST with a Kruskal’s output, O(m log n)
[MST]
How to prove MST is in P
Prove can solve in poly-time by running Kruskals
[Knapsack, original]
How to verify solution S
sum of weight <= B & sum of value is maximum
[Knapsack]
Why is knapsack not known to be in NP?
No poly-time method exists to verify value sum is maximal.
DP approach takes O(nB) time which is exponential relative to input size.
[Knapsack search]
Difference from original knapsack
Instead of max value sum, verify that subset S exists with at least goal value g and at most weight W
[Knapsack search vs optimization]
How to prove goal value
Binary search on g within the sum of all values (V), with the number of binary search rounds capped by log V. Takes O(log V)
T/F
If the knapsack search version is solvable in polynomial time, so is the original optimization problem.
True
Why: if we can reduce KS to KS search then we show KS search is at least as hard as KS
How to reduce:
1. Compute an upper bound V on the maximum possible value (V = sum of all item values).
2. Perform binary search on g in the range [0, V] to find the maximum value for which the search version returns a solution.
3. For each iteration of binary search, we run the polynomial-time Knapsack-search
[NP]
Significance of P != NP
There are problems that exist outside the class P (solvable in polynomial time), which are termed intractable or NP-complete
[NP]
Contrapositive of “If P != NP, then all NP-complete problems are not in P”
“If a NP-complete problem can be solved in poly-time, then all problems in NP can be solved in poly-time”
T/F
SAT is not in P
True. Considered most difficult problem in NP.
[Reduction]
A -> B in words
If A has a solution then B has a solution
[Reduction]
Key components for a reduction
Verify unknown problem is at least as hard as a known NP-C problem.
1. Input transformation is polynomial in time
2. Output transformation is polynomial in time
3. Bidrectional proof of correctness, ie. if known NP-C problem solution is correct, then unknown problem is correct. If NP-C S not correct, then unknown problem S not correct.
[Reduction]
How to prove NP-Completeness
- Verify in poly-time
- Use an existing NP-Complete problem and reduce it to the current problem
(not the other way!)
[3SAT Definition]
What is the 3SAT problem?
Input & Output
Boolean satisfiability problem
Input: Conjunctive Normal Form (CNF) with the constraint that each clause has at most 3 literals.
Output: Satisfying assignment if one exists, or “NO” if none exists.
[3SAT in NP]
How do we prove that 3SAT is in the class NP?
Show we can verify a proposed solution in polynomial time.
For 3SAT, given a solution S with truth assignments:
1. Check that at least one literal in each clause is satisfied for all clauses.
2. Runtime: Since each clause has at most 3 literals, this takes O(1) time per clause. With m clauses, verification takes O(m) total time, which is polynomial
[Reduction]
In the reduction from SAT to 3SAT, what is the direction of the reduction and why?
Reduce SAT to 3SAT (SAT → 3SAT), not the other way around.
The direction is important because we need to show that “if SAT is hard, then 3SAT is hard.” By reducing from SAT (known to be NP-complete) to 3SAT, we show that 3SAT is at least as hard as SAT. This establishes that 3SAT is NP-hard, and combined with showing 3SAT is in NP, proves it is NP-complete.
[Reduction]
How to reduce SAT to 3SAT (high level)
Transform clauses with more than 3 literals into clauses with at most 3 literals.
Introduce new variables and creating a sequence of smaller clauses that maintain the logical equivalence.
[SAT to 3SAT]
For a clause with 4 literals (a, b, c, d), how would you transform it into clauses with at most 3 literals?
(a ∨ b ∨ y) ∧ (¬y ∨ c ∨ d)