Chapter 11
■
hard problems and (lImIted) sloppIness
231
The thing is, we don’t really know what kind of a world we’re living in. To use
The Wizard of Oz as an analogy—we
may
think we’re living in Kansas, but if someone were to prove that P = NP, we’d most definitely not be in Kansas
anymore. Rather, we’d be in some kind of wonderland on par with Oz, a world Russel
Impagliazzo has christened
Algorithmica.
5
What’s so grand about Algorithmica, you say? In Algorithmica, to quote a well-known song, “You never
change your socks, and little streams of alcohol come trickling down the rocks.” More seriously, life would be a lot less
problematic. If you could state a mathematical problem, you could also solve it automatically. In fact, programmers
no longer would have to tell the computer what to do—they’d only need to give a clear description of the desired
output. Almost any kind of optimization would be trivial.
On the other hand, cryptography would now be very hard
because breaking codes would be so very, very easy.
The thing is, P and NP are seemingly
very different beasts, although they’re both classes of problems. In fact,
they’re classes of
decision problems, problems that can be answered with
yes or
no. This could be a problem such as
“Is there a path from
s to
t with
a weight of at most w?” or “Is there a way of stuffing items in this knapsack that gives
me a value of at least
v?” The first class, P, is defined to consist of those problems we can
solve in polynomial time (in
the worst case). In other words, if you turn almost any of the problems we’ve looked at so far into a decision problem,
the result would belong to P.
NP seems to have a much laxer definition
6
: It consists of any decision problems that can be solved in polynomial
time by a “magic computer” called a
nondeterministic Turing machine, or NTM. This is where the N in NP comes
from—NP stands for “nondeterministically polynomial.” As far as we know, these nondeterministic machines are
super-powerful. Basically, at any time where they need to make a choice, they can just guess, and
by magic, they’ll
always guess right. Sounds pretty awesome, right?
Consider the problem of finding the shortest path from
s to
t in a graph, for example. You already know quite a bit
about how to do this with algorithms of the more … nonmagical kind. But what if you had an NTM? You’d just start in
s and look at the neighbors. Which way should you go? Who knows—just take a guess. Because of the machine you’re
using, you’ll always be right, so you’ll just magically walk along the shortest path with no detours.
For such a problem
as the shortest path in a DAG, for example, this might not seem like such a huge win. It’s a cute party trick, sure, but
the running time would be linear either way.
But consider the first problem in Chapter 1: visiting all the towns of Sweden exactly once, as efficiently as possible.
Remember how I said it took about 85 CPU-years to solve this problem with state-of-the-art technology a few years ago?
If you had an NTM, you’d just need one computation step per town. Even if your machine were mechanical with a hand
crank, it should finish the computation in a matter of seconds. This
does seem pretty powerful, right? And magical?
Another way of describing NP (or, for that matter, nondeterministic computers) is to look at the difference
between
solving a problem and
checking a solution. We already know what solving a problem means. If we are to
Do'stlaringiz bilan baham: