Sub topic 9
NP-Hardness and NP-Completeness
This chapter assumes you already know polynomial-time (Karp) reductions, that reductions compose by transitivity, and that NP is the class of decision problems whose "yes" answers have certificates you can check in polynomial time. With those three ideas in place, NP-hardness and NP-completeness take only a short step to define.
The Definitions
A decision problem B is NP-hard if every problem A in NP has a polynomial-time reduction A ≤p B. Informally, B is at least as hard as everything in NP. A fast algorithm for B would give a fast algorithm for every NP problem: map the instance, then run B's algorithm.
A problem B is NP-complete if it satisfies both of these conditions:
- B is in NP.
- B is NP-hard.
| Property | Must be in NP? | Every NP problem reduces to it? | Example |
|---|---|---|---|
| In NP | Yes | Not required | Graph connectivity |
| NP-hard | Not required | Yes | Halting problem |
| NP-complete | Yes | Yes | SAT, Vertex Cover |
NP-hardness does not imply membership in NP. The halting problem is NP-hard, because any NP problem can be mapped to a program that halts exactly on "yes" instances. The halting problem is undecidable, though, so it is not in NP.
Why You Don't Reduce from Every NP Problem
Proving NP-hardness straight from the definition means handling every problem in NP at once. The Cook-Levin theorem, covered in the next chapter, does this once for SAT. After that, transitivity does the work. If C is NP-complete and C ≤p B, then for any A in NP:
A ≤p C ≤p B, so A ≤p B.
So one reduction from one known NP-complete problem is enough.
The Recipe
To prove that a new problem B is NP-complete:
- Membership. Describe a certificate and a polynomial-time verifier for B.
- Choose a source. Pick a known NP-complete problem C that resembles B in structure.
- Construct f. Give a polynomial-time map from instances of C to instances of B.
- Prove correctness both ways. Show that x is a yes-instance of C exactly when f(x) is a yes-instance of B.
As a worked case, take Vertex Cover. A certificate is a set C of at most k vertices. The verifier checks every edge for an endpoint in C, which takes O(|E|) time, so Vertex Cover is in NP. For hardness, map an Independent Set instance (G, k) to (G, |V| − k). That works because S is independent exactly when V \ S is a vertex cover. Vertex Cover is therefore NP-complete.
Consequences
Each NP-complete problem captures all of NP. If any single NP-complete problem has a polynomial-time algorithm, then P = NP. If P ≠ NP, then no NP-complete problem is in P. This is why showing a problem NP-complete is useful in practice: it tells you to stop looking for an exact algorithm that is efficient on all inputs. You can switch to heuristics, approximation, or algorithms for restricted cases.
Optimization versions such as "find the largest independent set" are not decision problems, so they can't be in NP. They are usually called NP-hard, because their decision versions reduce to them.
Exercise
Assume Independent Set is NP-complete. Prove that Clique is NP-complete. Name the certificate, the verifier's running time, and the reduction.
Show answer
Membership: the certificate is a set of k vertices. The verifier checks all pairs for edges in O(k^2) time, so Clique is in NP. Hardness: map (G, k) to (complement of G, k). This runs in O(|V|^2) time. S is independent in G exactly when every pair in S is joined in the complement, that is, when S is a clique there. So Independent Set ≤p Clique, and Clique is NP-hard. Being in NP and NP-hard, Clique is NP-complete.
Exercise
A colleague shows that their scheduling problem reduces in polynomial time to SAT and concludes that the scheduling problem is NP-complete. What is wrong?
Show answer
The reduction goes the wrong way. Scheduling ≤p SAT shows only that scheduling is in NP, or at least no harder than SAT. Proving NP-hardness needs a reduction from a known NP-complete problem to the scheduling problem.