Watch First Watch First: Pandnp Pandnp

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

P and NP

The most important question of them


all is not “Why is there something
instead of nothing?” but rather “Is P =
NP?”

CONTENTS
CONTENTS
Watch First • DeFnitions • Examples • Decision
Problems, Optimization Problems • The Big Deal
• NP-Complete Problems • Links

Watch First
P vs. NP and the Computational Comple…
Watch later Share

Definitions
Informally,

The class NP is the set of all


functions 𝑓 for which, given any 𝑥
and 𝑦 , you can check
check, in polynomial
time, whether or not 𝑓(𝑥, 𝑦) is true.

The class P is the set of all functions


𝑓 for which, given any 𝑥 , you can
Fnd, in polynomial time, a value 𝑦 for
Fnd
which 𝑓(𝑥, 𝑦) is true.

As always, when we say “polynomial time”


without qualiFcation, we mean polynomial
in the number of bits in which the problem
input is encoded.

Exercise
Exercise: Prove that all functions in P
are also in NP
NP.

Examples
The following problems are all in NP
NP.

SHORTEST PATH
Given weighted graph 𝐺 , nodes
𝑠 and 𝑡 in 𝐺 , and value 𝑘 , is
there a path 𝑝 from 𝑠 to 𝑡 such
that 𝑤𝑒𝑖𝑔ℎ𝑡(𝑝) ≤ 𝑘?
TRAVELING SALESPERSON
Given complete weighted graph
𝐺 and value 𝑘 , is there a
Hamilton cycle 𝑐 visiting every
node in 𝐺 such that
𝑤𝑒𝑖𝑔ℎ𝑡(𝑐) ≤ 𝑘 ?
MINIMUM SPANNING TREE
Given weighted graph 𝐺 and
value 𝑘 , is there a spanning
tree 𝑡 such that
𝑤𝑒𝑖𝑔ℎ𝑡(𝑡) ≤ 𝑘 ?
VERTEX COVER
Given graph 𝐺 and value 𝑘 , is
there a vertex cover 𝑠 for 𝐺
such that |𝑠| ≤ 𝑘 ?

These are in NP because we can check in


polynomial time

Whether 𝑝 is a path in 𝐺 with weight


≤𝑘
Whether 𝑝 is a cycle in 𝐺 visiting
every node and has weight ≤ 𝑘
Whether 𝑡 is a spanning tree of 𝐺
with weight ≤ 𝑘
Whether 𝑠 is a vertex cover of 𝐺 and
has ≤ 𝑘 nodes

Exercise
Exercise: Argue why these are all
polynomial-time checkable.

Exercise
Exercise: Two of the above problems
are currently known to be in P. Which
ones?

Decision
Problems,
Optimization
Problems
P and NP only contains decision
problems. But many decision problems
can be transformed in polynomial time to
and from a corresponding optimization
problem.

Decision Optimization
Name Given
Problem Problem

SHORTEST Weighted Is there a Find the path


PATH graph 𝐺 , path 𝑝 from from 𝑠 to 𝑡
nodes 𝑠 𝑠 to 𝑡 with with the
and 𝑡 weight ≤ 𝑘 smallest
(for some weight
𝑘 )?
TRAVELING Complete Is there a Find the
SALESPERSON weighted Hamilton Hamilton
graph 𝐺 Cycle of 𝐺 Cycle in 𝐺
with weight with the
≤ 𝑘 (for smallest
some 𝑘 )? weight
MINIMUM Weighted Is there a Find the
SPANNING graph 𝐺 spanning spanning tree
TREE tree in 𝐺 of 𝐺 with the
with weight smallest
≤ 𝑘 (for weight
some 𝑘 )?
VERTEX COVER Graph 𝐺 Is there a Find the
subset 𝑠 of smallest
the nodes in subset 𝑠 of
𝐺 , of size 𝑘 the nodes in
or less (for 𝐺 such that
some 𝑘 ), every edge in
such that 𝐺 has at least
every edge in one endpoint
𝐺 has at in 𝑠 .
least one
endpoint in
𝑠?
SATISFIABILITY A boolean Is there an —
formula assignment
containing of boolean
0 or more values to
variables variables
that makes
the formula
true?
CLIQUE Simple Is there a Find the
graph 𝐺 subset 𝑠 of largest subset
the nodes in 𝑠 of nodes in
𝐺 such that 𝐺 such that
all possible all possible
edges edges of 𝑠
between are present.
them are
present?
KNAPSACK A set 𝑆 of Is there a set Find the
items 𝑠𝑖 of numbers of
with nonnegative each item to
weights integers choose that
𝑤𝑖 and {𝑛1 . . . 𝑛|𝑆| } maximizes
values 𝑣𝑖 , such that ...? the total value
and without
capcity 𝐶 exceeding C
SUBSET SUM Set 𝑆 of Is there a —
numbers non-empty
and value subset
𝑘 𝑠 ⊆ 𝑆 such
that
∑𝑖 𝑠𝑖 = 𝑘?
INTEGER An integer Is there a —
FACTORIZATION 𝑁 ≠ 0 bag of
integers 𝑏
not including
1 or 𝑁 such
that
∏𝑖 𝑏 𝑖 = 𝑁 ?
GRAPH Graph 𝐺 Is there an Find the
COLORING assignment smallest
of ≤ 𝑘 number of
colors to colors such
nodes in 𝐺 that no two
such that no adjacent
two adjacent vertices are
nodes have the same
the same color
color?
MAX FLOW / Directed Is there a ...? Find the ...
MIN CUT weighted
graph 𝐺 ,
nodes 𝑠
and 𝑡
MIN FLOW / Directed Is there a ...? Find the ...
MAX CUT weighted
graph 𝐺 ,
nodes 𝑠
and 𝑡
HAMILTON Graph 𝐺 Is there a —
CYCLE cycle
containing
every node in
𝐺?
EULERIAN TOUR Graph 𝐺 Is there a —
tour
containing
every edge in
𝐺?
MATCHING Graph 𝐺 Is there a Find the
subset 𝑠 of largest set of
the nodes in edges in 𝐺
𝐺 , of size 𝑘 with no
or larger (for common
some 𝑘 ), vertices.
such that no
two edges in
𝑠 share a
vertex?
DOMINATING Graph 𝐺 Is there a Find the
SET subset 𝑠 of smallest
the nodes in subset of
𝐺 , of size 𝑘 nodes in 𝐺 to
or less (for which all
some 𝑘 ), to other nodes
which every are adjacent.
other node in
𝐺 is
adjacent?
GRAPH Undirected, Are there 𝑛 Find the
PARTITIONING weighted graphs...? smallest such
graph 𝐺 𝑛

The Big Deal


Here are some facts:

NP consists of thousands of useful


problems that need to be solved
every day.

Some of these are in P .

For the rest, the fastest known


algorithms run in exponential time.

Although no one has found


polynomial-time algorithms for these
problems, no one has proven that
no such algorithms exist for them
either!

In fact, it is quite possible that all


problems in NP are solvable
(decidable) in polynomial time: no
one knows whether P = NP or P ≠
NP
NP.

Most computer scientists think they


are not equal: if they are equal, it
would mean it is as easy to Fnd
solutions as it is to check them.

The INTEGER FACTORIZATION


problem that makes RSA secure,
would be probably insecure if P =
NP
NP.

The Clay Mathematics Institute will


award a one-million dollar prize to
anyone that answers the P=NP
question.

Some quotes

The P vs. NP problem has been called


"one of the most important problems
in contemporary mathematics and
theoretical computer science" .... That
is an understatement. Not only is P vs.
NP the deFning question of our Feld;
it's one of the deepest questions ever
asked for which we'd know how to
recognize an answer. ....If you doubt
this, read the Clay Math Institute's list
of million-dollar prize problems ...
notice how P vs. NP stands out, not
merely as the only problem of the
seven relevant practically ... Does the
ability to recognize an answer ...entail
the ability to Fnd an answer? We are
after not projective algebraic varieties
or zeros of the Riemann zeta function,
but the nature of mathematical
thought itself.

— Scott Aaronson

If P=NP is proved by exhibiting a truly


feasible algorithm for an NP-complete
problem ..., the practical
consequences would be stunning.
First, ... many of the optimization
problems important to industry could
be solved. Second, mathematics
would be transformed, because
computers could Fnd a formal proof of
any theorem which has a proof of
reasonable length.

— Stephen Cook

In 1976 when I was a graduate student


in Germany, I bumped into a new
professor who had been a particularly
bright student .... He had been given a
full professorship ... pretty much right
after receiving his Doctorate. He told
me straight out that he was going to
solve the P=NP problem. He exuded
conFdence in his abilities and fairly
gloated over the fact that he had a leg
up on his American counterparts,
because, as a German professor, he
could pretty much dictate his own
schedule. That is, he could go into his
room, lock his door, and focus on The
Problem.

Many years later I asked about this


person, and I got answers indicating
that no one really knew anything about
him. He was still a professor as far as
anyone could tell, but he had turned
into a recluse and a virtual hermit,
which seemed to bale everyone.

— Rocky Ross

If P=NP, then the world would be a


profoundly different place than we
usually assume it to be. There would
be no special value in "creative leaps,"
no fundamental gap between solving a
problem and recognizing the solution
once it's found. Everyone who could
appreciate a symphony would be
Mozart; everyone who could follow a
step-by-step argument would be
Gauss; everyone who could recognize
a good investment strategy would be
Warren Buffett. It's possible to put the
point in Darwinian terms: if this is the
sort of universe we inhabited, why
wouldn't we already have evolved to
take advantage of it?

— Scott Aaronson.

Think you can win the prize? You probably


won't want to approach the challenge with
natural proofs.

NP-Complete
Problems
A decision problem is NP-Complete
(alternatively, in the set NPC
NPC), if (1) it is in
NP
NP, and (2) a polynomial-time solution for
it would imply a polynomial-time solution
for every problem in NP .

TODO

Reductions
TODO

Coping with NP-


Completeness
If you have an NP-Complete or NP-Hard
problem you can

Write an implementation using


intelligent backtracking. This will
solve the problem exactly but there
will be inputs for which the run time
is still longer than your lifetime.

Write something that looks for


special input cases and solves them
specially, e.g. for SUBSET SUM
having all positive inputs and a
relatively small value of 𝑘 , there
exists a pretty fast dynamic
programming solution.

Write an implementation using


randomization or heuristics, that runs
quickly but fails to give a correct
answer a certain small percentage of
the time. (Ideally the implementation
would announce that it wasn't sure of
its answer.)

For optimization problems, write


something that runs quickly and
gives an answer that is not optimal,
but not too far from optimal (an
approximation algorithm).

Polynomial-Time
Friends
Sometimes there are special cases of NP-
Complete problems that can be solved in
polynomial time. And sometimes an NP-
complete problem is a close cousin to one
in P.

Special Cases or
NP-Complete
Variants in P

SAT • All clauses have at


most two literals
(2SAT)
• All clauses are Horn
clauses (HORN SAT)
HAMILTON • The problem is
CYCLE deFned for edges
(EULER TOUR), not
vertices
• The number of...
3- • 2-DIMENSIONAL
DIMENSIONAL MATCHING
MATCHING
GRAPH k- •k=1
COLORING •k=2
• You know that the
graph is planar
LONGEST PATH • You want the
SHORTEST PATH
instead
(LARGEST) • The graph is a tree
INDEPENDENT
SET
(SMALLEST)
VERTEX COVER
INTEGER • LINEAR
LINEAR PROGRAMMING
PROGRAMMING

Links
The P versus NP Page
A Nice Explanation of the P vs. NP
Problem from MIT News
The Complexity Zoo
Wikipedia's List of NP Complete
Problems
NP-Completeness on xkcd: TSP,
Restaurant Orders.
David Johnson's NP-Completeness
Columns
Slides from a presentation by Uriel
Feige.
Blog posts and papers by Scott
Aaronson:
Ten Reasons to Believe P ≠ NP
Is P=NP Independent of ZFC?
NP-Complete Problems and
Physical Reality

You might also like