
P versus NP Explained - danielrm26
http://www.danielmiessler.com/study/pvsnp/
======
mjn
A few mild disagreements over interpretation:

1\. NP-hard problems are not necessarily hard for computers to solve; they are
only hard in the _worst_ case, which could be very rare for some NP-hard
problems. SAT, for example, is the original canonical NP-complete problem. But
in AI, it's nowadays seen as almost a canonical "fast bytecode". Other systems
will often want to find a way to reduce their problem to SAT, because that
reduction implies tractability, rather than intractability! If you can target
SAT in your backend, you can rely on it (probably) being easy to solve, since
most instances of SAT can be quickly disposed of by heuristic solvers. (The
more common practical problem here is size blow-up in the reduction to SAT,
rather than the SAT instance itself being hard to solve.)

2\. Partly as a result of #1, the relevance of NP-hardness to cryptography in
practice is often overstated. NP-hard problems aren't really hard in the
relevant sense: worst-case harness is not sufficient for a one-way function.
Attempts to construct one-way functions out of NP-hard primitives have a
pretty poor record (not all have been broken, but a number have, and none have
caught on). The other direction is true, though, that P=NP would imply no one-
way functions.

I wrote a bit more along these lines a while ago:
[http://www.kmjn.org/notes/nphard_not_always_hard.html](http://www.kmjn.org/notes/nphard_not_always_hard.html)

~~~
j2kun
A few more (though I love it when people write about one of my favorite
topics!)

1\. There are known algorithms for NP-complete problems that are "faster" than
checking all possible solutions (in fact, finding such algorithms have very
big implications and make their discoverers very famous). They're just not all
that much faster and certainly not polynomial-time, and hence they don't
resolve P vs NP. For example, the third problem of finding the largest clique
in a graph has the naive algorithm 3^n/3 of checking all solutions, but there
is a long line of research improving this, and the fastest known algorithm
today is a 2^0.249n algorithm.

2\. The question of P vs NP is not the question of whether there are any
genuinely difficult problems to solve, if by genuinely difficult we mean no
poly-time solution. There are many problems out there that are known to have
no polynomial time algorithm. There are even natural problems out there that
are known to have no _singly exponential_ time algorithm (i.e. the lower bound
is 2^2^n).

3\. The traveling salesman example is not correct: the traveller is limited in
that he can only visit each city exactly once.

~~~
algorias
To expand on 2. above: It's a common misconception that the class NP is
important because it stands for hard problems, but in fact there are classes
of hard problems which we know to be distinct from P. Specifically, P !=
EXPTIME (see the time hierarchy theorem).

The reason why the P vs NP question is interesting is the possibility of
verifying solutions. We know there are easy problems, and we know there are
hard problems, but we don't know if there are hard problems that are easy to
verify. Intuitively, for many problems it's much easier to recognize a correct
solution than come up with one. This is formalized by the statement P != NP,
and in that light it's quite clear why the vast majority of researchers
believe it to be true.

------
VLM
Three minor editorial comments:

1) Its not "most real-world challenges" its more like "some easily explainable
problems which don't scale very well". Most real world challenges are simple P
problems or NP problems on a very small scale. Sample the angular position of
all four wheels a thousand times per second, calculate the apparent angular
acceleration, cross check with the other wheels, and if its ridiculous,
modulate the brakes a hundred times per second. Even if that problem wouldn't
scale to 5000 wheeled vehicles, that simply doesn't matter to our 4 wheeled
cars, or even 18 wheel semi trucks. Or TLDR most real world problems are
either P or small enough scale NP not to matter.

2) "computers being able to quickly solve problems" More like anything being
able to solve problems. Classic computer limits are FP multiplier speed,
memory limits, stuff like that. This is a problem solving limitation inherent
to the class of problem, not a computer technology limitation. A classic
Searle Chinese Room emulating a processor, or a single human brain, is just as
limited by NP problem solving limitations. Or something along the lines of
this problem will not be solved by making a better computer.

3) "Unfortunately, many with computer science degrees" rewrite to
"Unfortunately, many computer science degree programs don't require a class in
automata theory..."

Please don't overestimate three minor editorial comments; it is a good
introductory article.

~~~
pdpi
The article describes P vs NP as the difference between decision/optimisation
problems, which doesn't make it seem like what sort of machine you use to
solve them has much to do with it at all.

You can also think of it in terms of those problems that can be solved in poly
time, either by deterministic (P) or non-deterministic (NP) Turing machines.
From that perspective, the fact that you're using a modern computer, which is
effectively a deterministic Turing machine, matters a whole lot.

~~~
VLM
"the fact that you're using a modern computer ... matters a whole lot"

I'd disagree in that its a math / logic problem not a computer problem. Most
of the applications seem to involve a computer or its assumed that if a
solution is found it would be applied by computers.

The Pythagorean theorem does not care if its written with chalk or dry erase
markers. In a similar way most automata theory proofs don't use or rely upon a
computer other than in the word processor and wiki browser sense.

Or maybe another way to say it is the guys who make computers faster at great
effort and expense will never make NP problems P just by making faster
transistors or putting more transistors on a single die.

The whole topic is not really a computer problems.

~~~
pdpi
Algorithmic complexity is predicated on what sort of computational model
you're working on top of. For the most part, that means "Deterministic Turing
Machines", but that's not the only sort of computing machine out there. E.g.
quantum computers can solve a whole class of NP problems (like factorisation)
in poly time.

------
peeters
The terminology in the text misses the mark a bit.

\- P and NP are not disjoint sets. NP just means "verifiable in polynomial
time." There are plenty of easy problems to solve that are verifiable in
polynomial time. P is in fact a subset of NP.

\- NP-hard problems are ones that are difficult for computers to solve

\- NP-complete is the intersection between NP-hard and NP

Furthermore, it presents the P vs NP problem as an attempt by mathematicians
to solve P = NP, whereas almost no mathematicians believe P = NP, they're just
all trying to prove that P != NP.

~~~
danielrm26
Apologies. I was trying to keep it as simple as possible. I don't think people
who need to know it to that degree will even need the summary I provided.

~~~
peeters
I think keeping it simple is great, but you should bring your terminology in
the text to be consistent with the diagram at the start, otherwise it's
confusing.

I don't think it would be difficult to say something like:

> P and NP are two different kinds of problems. P problems are easy for
> computers to solve, and NP problems are easy for computers to check answers
> for. All P problems are NP problems; that is, if it's easy for the computer
> to solve, it's easy to verify the solution. The P vs NP problem asks: within
> the class of NP problems, are there problems which are not P, that is, which
> are not easy for computers to solve?

~~~
danielrm26
Can I use that?

~~~
peeters
By all means.

~~~
danielrm26
Updated. Thanks for the input.

------
ithinkso
I've always enjoyed reading articles about P vs. NP problem but this one
missed the point I think. First of all author stated that _Unfortunately, many
with computer science degrees have a weak understanding of the concept—let
alone those without any training on it._ but the explanation he gave is
actually identical to those that are given in colleges and this is why people
have weak understanding of NP problems.

He then lists three most common examples of NP problems that are not even as
close to the real problems as he thinks they are.

 _This is why the P versus NP problem is so interesting to people. If anyone
were to solve it, it would potentially make very difficult problems very
easy._ and here is where he missed the point completely. This is simply not
true - if for example there is polynomial time algorithm solving NP problem
then P vs. NP is solved but if this algorithm is lower bounded by, I don't
know, n^(10^80) it's not so easy for computers either. It is 'useless' from
real software point of view.

The most profound effect of proving that P=NP is that the ability to check any
answer's correctness 'fast' (in polynomial time) is sufficient to being able
to solve that problem in polynomial time. That's it. Pure theory of
computation. No real life super computing boost.

~~~
danielrm26
> First of all author stated that Unfortunately, many with computer science
> degrees have a weak understanding of the concept—let alone those without any
> training on it. but the explanation he gave is actually identical to those
> that are given in colleges and this is why people have weak understanding of
> NP problems.

In a computer science class you should be going into the details. This was not
designed to do that. It was designed to give a general overview of the
concept, as is clearly stated in the beginning.

And I think the latter is more needed than the former. There are plenty of
deep explanations of this topic, and very few approachable ones.

~~~
VLM
"very few approachable ones."

I give credit to the author for trying, but having "enjoyed" an automata
theory class and having read the textbook there is no "royal road to P/NP"
much like geometry. Have to take the entire long road to get to the end.

Analogy time... how would you explain recursion to a general populace without
first explaining variables, functions, calling by ref vs value (or just the
idea of calling a function at all, and that it returns something), stacks, the
concept of procedural programming, the idea of a flowchart, some level of
error detection so it doesn't run off into the weeds, some basic ideas about
scalability... So Colbert invites you on his show and after the HN cheering
dies down he says "I don't know much about computer science, could you explain
recursion in plain language in a line or two?" Honestly, I'd probably say "No"
or some joke about it being turtles all the way down which the general public
wouldn't find very amusing but those who know would laugh.

~~~
alex-g
There is no royal road; or if we want some mystical woo, we could say that the
journey is the destination, or something. I think that if you're trying to
understand P-vs-NP it's not a matter of proceeding definition by definition.
It's more like simultaneously approaching the question from lots of different
angles, in order to build the mental connections between P-vs-NP and other
topics. That includes Turing machines, formal languages and automata,
reductions, big-O analysis, important concrete problems in P, NP, or neither,
important algorithms and methods, and so forth.

Recursion is probably the same way. For Colbert purposes you could certainly
come up with some glib explanation. When I, or you, or anyone else, have
learned recursion we've probably started with that, but then proceeded to
build connections with induction, PL semantics, computer architecture,
compiler/runtime implementations, and all the other allied topics.

But I do think the earliest, most informal, explanation has its place too,
because you have to start somewhere. The learning process is (at least for me)
more like proceeding through lots of explanations of the same thing, at
greater levels of detail and with different metaphors and external references,
than it is like a linear progression from topic to topic.

------
lifebeyondfife
Good concise explanation. For those who missed it a few months back, I wrote a
blog post which contained an explanation of NP and, more importantly, why it's
important for programmers to recognise NP problems.

The section headings 'Understanding NP-complete completely useless?' and
'Recognising NP-complete problems' are the most relevant.
[http://lifebeyondfife.com/helping/](http://lifebeyondfife.com/helping/)

~~~
prawks
Cool post, and nice tool! Until now I've kind of been one of those that have
been able to identify NP problems and know that "there are ways to optimize
them" but haven't had much experience in actually optimizing any in the real
world.

I enjoyed the explanations of how heuristics and inference fit in to solving
those problems, and it was cool to see how little the code needed to change to
include those optimizing constraints.

------
jfasi
This post explain nothing.

Any article claiming to explain P vs NP without so much as mentioning
nondeterministic and deterministic Turing machines is meaningless.

~~~
j2kun
Not true. You can just use the characterization of NP in terms of certificates
and deterministic verifying machines, and still get everything (except maybe
the standard proof of the Karp-Lipton theorem).

~~~
diminish
Watch out where you stand. Sons of Turing are a large mafia, which will
immediately reduce every other computational construct into TMs and claim you
didn't really add up anything :)

~~~
j2kun
Tell that to the Quantum Brotherhood. Edit: you may find the head of a cat in
your bed, but only if you look and only with probability 1/2.

------
_greim_
> P problems are easy for computers to solve, and NP problems are easy for
> computers to check answers for, but extremely difficult for computers to
> solve. [...] All P problems are NP problems

Seems like a direct contradiction. Typo, or am I missing something?

~~~
14113
Sort of - we don't know if NP problems are hard for computers to solve, that's
really the whole question!

Technically, P is a subset of NP. Problems in NP have answers (called
certificates) which can be _verified_ , or checked, using an algorithm that
runs in polynomial time (that is asymptotically O(n^x), where X is a finite
integer). Problems that are in P are those that have a polynomial time
algorithm to _construct_ an answer.

Any problem that's in P is therefore in NP, as we can simply run the algorithm
for constructing the answer then compare it with the certificate to see if
they match.

P vs NP simply asks if _all_ problems in NP can be solved in polynomial time,
hence P=NP.

~~~
_greim_
Ahh. Thank you. This actually makes more sense than the article itself!

------
jmcgough
I've heard that if a polynomial-time solution was found for an NP-hard
problem, that would mean that all NP-hard problems can be solved in polynomial
time. Is this true, and why is that?

~~~
gphilip
No, this is not true. But the following is true: if a polynomial-time solution
was found for an NP-hard problem, that would mean that all problems _in the
class_ NP can be solved in polynomial time [1]. This would include all those
NP-hard problems which _also happen to be_ in the class NP.

NP-hard can be read as "as hard to solve as any problem in the class NP". So
if we can solve one of these hard problems in polynomial time, then -- by the
meaning of NP-hard -- we can solve all problems in the class NP in polynomial
time.

The reason why your statement is not true as it is, is that there are NP-hard
problems which are not inside the class NP. These problems are "much harder
than" any problem in the class NP and so, being able to solve all problems in
NP in polynomial time does not mean that these "harder than all of NP"
problems can also be solved in polynomial time. Check the Wikipedia entry on
NP-hard for an example of such a "harder-than NP, but also NP-hard" problem.
[https://en.wikipedia.org/wiki/NP-hard](https://en.wikipedia.org/wiki/NP-hard)

A problem which is both (i) NP-hard, and (ii) in NP is said to be _NP-
complete_. If a polynomial-time solution was found for an NP-hard problem,
that would mean that all NP-complete problems can be solved in polynomial time
(because they are all in NP).

[1] There is a fine point here turning on what "can be solved" means. If we
take "can be solved" to mean "there exists an algorithm", then this statement
is fine. Otherwise ... but that is an arcane point anyway.

~~~
jmcgough
Thanks for the explanation - I didn't understood the difference between NP-
hard and NP-complete when I asked this (the wiki article on NP-hard helped to
clarify!).

------
elwell
What are some of the ways 'solving' P vs. NP would affect society (or certain
specific computing problems)?

------
jordanlev
Why on earth does this web page not display its content when cookies are
disabled?

