NP-Complete Flashcards
Define a search problem
A search problem is specified by a search algorithm C that takes two inputs, an instance I and a proposed solution S, and runs in time polynomial | I |. We say S is a solution if and only if C(I,S) = True
Note: we must be able to find S quickly (in poly-time with respect to I).
Is SAT a search problem? Why or why not?
Yes SAT is a search problem. We can take a proposed solution of variable-assignments and verify that every clause in I is satisfied. This can be done in polynomial time.
What is the input and output to the SAT problem? Is it NP-Complete?
**Input**:
The input is m or-clauses with n boolean variables. The clauses are in conjunctive normal form:
(x1 or ~x2) and (x3 or x2 or x1) and (x5 …)
**Output**:
- Assignments for all variables if the statement can be satisfied
- “No” if not.
NP-Complete? YES! (note if 2SAT, it’s in P)
What is the input to the Independent Set problem? Is it NP-Complete?
**Input**: G=(V,E), k
An undirected, unweighted graph G=(V,E). k is the target size of the IS.
**Output**:
- IS with >= k vertices. An independent is a set such that no two vertices in the set share an edge.
- “No” if not set exists.
NP-Complete? YES!
What is the input and output to the Vertex Cover problem? Is it NP-Complete?
**Input**: G=(V,E), b
An undirected, unweighted graph G=(V,E). b is the budget size of the vertex cover.
**Output**:
- Vertex cover with <= b vertices
- “No” if no vertex cover exists with <= b vertices
NP-Complete? YES!
What is the input and output to the Subset Sum problem? Is it NP-Complete?
**Input**: A, t
A is an array of integers. t is the target integer sum.
**Output**:
- An array of integers which is a subset of A, and sums to t.
- “No” if no such array of ints exists
NP-Complete? YES!
What is the input and output to the Knapsack Search problem? Is it NP-Complete?
**Input**: W, V, B, g
W is the array of weights. V is the array of values. B is the capacity of the knapsack. g is the target value.
**Output**:
- An array of items of total weight <= B and total value >= g.
- “No” if no such collection of items exists.
NP-Complete? YES!
What is the input and output to the clique problem? Is it NP-Complete?
**Input**: G, k
G is an undirected, unweighted graph. k is the target size of the clique.
**Output**:
- A set of at least k vertices that are in a clique. This means each pair of vertices in the clique has an edge between them (directly connected).
- “No” if no such clique exists
NP-Complete? YES!
List all reductions that we can make from Indepdent Set (that we reviewed in lectures)
List all reductions that we can make from SAT
When writting an NP-Complete Proof by reducing A => B, you have to show that A <=> B. What logical statements can you use to do this?
Pick one of the 4 combos below to prove this
A => B AND B => A
A => B AND NO A => NO B
B => A AND NO B => NO A
NO A => NO B AND NO B => NO A
Important:
A => B, NO B => NO A are contrapositives; they have the same logical value. If you were to use this combo then you would have proven the same direction twice.
True or False? Knapsack is in P?
False (there is no known algorithm that runs in polynomial time). The dynamic programming algorithm we discussed in class runs in O(nB), which is not polynomial with respect to the inputs.
Note: If you add a goal, you have the “Knapsack-Search” problem, and this is in NP. We can check that the sum of weights are at most B and that the sum of values is at least the goal.
True or False? MST is in NP? MST is in P?
True and True. We know of two polynomial time algorithm to find an MST: Prims and Kruskals. We can use these algorithms to verify that a given solution is a minimum spanning tree by 1) running BFS or DFS to make sure it’s a tree and 2) running Prims or Kruskals to ensure it’s a minimum spanning tree.
What does NP stand for?
Nondeterministic polynomial time. This means problems that can be solved in poly-time on a nondeterministic machine. A nondeterministic machine is one in which we can guess at each step.
What are NP-complete problems?
They are the hardest problems in the class NP. If P != NP, then all NP-complete problems are not in P. If an algorithm is found to solve an NP-complete problem in polynomial time, this means P=NP.
Ex) If we can solve SAT in poly-time then we can solve every problem in NP in poly-time. If P != NP, SAT is not in P.