Chapter 11
■
hard problems and (lImIted) sloppIness
235
But Where Do You Start? And Where Do You Go from There?
I hope the basic ideas are pretty clear now: The class NP consists of all decision problems whose “yes” answers can be
verified in polynomial time. The class NPC consists of the hardest problems in NP; all problems in NP can be reduced
to these in polynomial time. P is the set of problems in NP that we can solve in polynomial time. Because of the
way the classes are defined, if there’s the least bit of overlap between P and NPC, we have P = NP = NPC. We’ve also
established that if we have a polynomial-time reduction from an NP-complete problem to some other problem in NP,
that second problem must also be NP-complete. (Naturally, all NP-complete problems can
be reduced to each other
in polynomial time; see Exercise 11-2.)
This has given us what
seems to be a useful notion of hardness—but so far we haven’t even established that there
exists such a thing as an NP-complete problem, let alone
found one. How would we do that? Cook and Levin to the rescue!
In the early 1970s, Steven Cook proved that there is indeed such a problem, and a little later, Leonid Levin
independently proved the same thing. They both showed that a problem called
boolean satisfiability, or SAT, is NP-
complete. This result has been named for them both and is now known as the Cook-Levin theorem.
This theorem,
which gives us our starting point, is quite advanced, and I can’t give you a full proof here, but I’ll try to outline the
main idea. (A full proof is given by Garey and Johnson, for example; see the “References” section.)
The SAT problem takes a logical formula, such as (A or not B) and (B or C), and asks whether there is any
way of making it true (that is, of
satisfying it). In this case, of course, there is. For example, we could set A = B = True.
To
prove that this is NP-complete, consider an arbitrary problem FOO in NP and how you’d reduce it to SAT. The idea
is to first construct an NTM that will solve FOO in polynomial time. This is possible by definition (because FOO is in
NP). Then, for a given instance
bar of FOO (that is, for a given input to the machine), you’d construct (in polynomial
time) a logical formula (of polynomial size) expressing the following:
The input to the machine was
•
bar.
The machine did its job correctly.
•
The machine halts and answers “yes.”
•
The tricky part is how you’d express this using Boolean algebra, but once you do, it seems clear that the NTM is,
in fact,
simulated by the SAT problem given by this logical formula. If the formula is satisfiable—that is, if (and only if)
we can make it true by assigning truth values to the various variables (representing, among other things,
the magical
choices made by the machine), then the answer to the original problem should be “yes.”
To recap, the Cook-Levin theorem says that SAT is NP-complete, and the proof basically gives you a way of
simulating NTMs with SAT problems. This holds for the basic SAT problem and its close relative, Circuit-SAT, where
we use a logical (digital) circuit, rather than a logical formula.
One important idea here is that all logical formulas can be written in what’s called
conjunctive normal form
(CNF), that is, as a conjunction (a sequence of ands) of clauses, where each clause is a sequence of ors.
Each occurrence of a variable can be either of the form A or its negation, not A. The formulas may not be in CNF to
begin with, but they can be transformed automatically (and efficiently). Consider, for example, the formula A and (B
or (C and D)). It is entirely equivalent
with this other formula, which is in CNF: A and (B or C) and (B or D).
Because any formula can be rewritten efficiently to a (not too large) CNF version, it should not come as a surprise
that CNF-SAT is NP-complete. What’s interesting is that even if we restrict the number of variables per clause to
k and
get the so-called
k-CNF-SAT (or simply
k-SAT) problem, we can still show NP-completeness as long as
k > 2. You’ll see
that many NP-completeness proofs are based on the fact that 3-SAT is NP-complete.