Sub topic 2
The Nondeterministic Definition of NP
This chapter assumes you already know the verifier definition of NP from the previous chapter. It also assumes you are comfortable with Big-O notation and basic graph terms.
The Nondeterministic Definition of NP
A nondeterministic Turing machine can branch at each step and accepts if any branch accepts. NP is the set of decision problems such a machine solves in polynomial time. This matches the verifier definition: the machine "guesses" a certificate on one branch, then runs the verifier on it.
Reductions: Comparing the Difficulty of Problems
A polynomial-time many-one reduction from A to B is a function f, computable in polynomial time, where x is a yes-instance of A exactly when f(x) is a yes-instance of B. We write A ≤p B. Hardness flows from A to B. If B is easy, A is easy too. If A is hard, B is at least as hard.
What It Means to Be NP-Hard
A problem is NP-hard if every problem in NP reduces to it. An NP-hard problem does not have to be in NP, and it does not have to be a decision problem.
NP-Complete: The Hardest Problems in NP
A problem is NP-complete if it is in NP and is also NP-hard. If any NP-complete problem has a polynomial-time algorithm, then P = NP.
Cook-Levin: SAT Is NP-Complete
The Cook-Levin theorem shows that SAT (is a Boolean formula satisfiable?) is NP-complete. The proof encodes any polynomial-time verifier's computation as a CNF formula. That gives the first NP-complete problem. After that, you show a new problem is NP-hard by reducing SAT, or any problem already known to be NP-complete, to it. SAT is also in NP, because checking an assignment is fast:
def verify_cnf(clauses, assignment):
for clause in clauses:
if not any(assignment[abs(lit)] == (lit > 0) for lit in clause):
return False
return True
# (x1 OR NOT x2) AND (x2 OR x3)
print(verify_cnf([[1, -2], [2, 3]], {1: True, 2: False, 3: True})) # TrueA Tour of Classic NP-Complete Problems
| Problem | Question |
|---|---|
| 3-SAT | Is a CNF formula with 3 literals per clause satisfiable? |
| Vertex Cover | Do k vertices touch every edge? |
| Independent Set | Are there k vertices with no edges between them? |
| 3-Coloring | Can the vertices get 3 colors with no edge joining two vertices of the same color? |
| Subset Sum | Does some subset of the numbers add up to the target? |
Exercise
You find a polynomial-time reduction from your new problem X to 3-SAT. Does this show X is NP-hard?
Show answer
No. It shows only that X is no harder than 3-SAT, which places X in NP. To show X is NP-hard, reduce 3-SAT (or another NP-complete problem) to X.