Professional Documents
Culture Documents
alog a
) which is strictly
better than exponential time.
3 Certicates and the Class NP
As hard as they are there is something nice and easy about all the examples above, in-
cluding the TSP, Clique, SAT, cSAT, factoring, GI, Hamilton cycle, and knapsack problems.
In all of them, the solution to the search version is short (polynomial size) and it is easy
(in polynomial time) to verify that the solution is correct. Said dierently, when the answer
to the decision problem is Yes on a input x, there exists a short proof or succinct certicate
(poly-size) of this fact. If we had magic powers to guess this certicate, we could verify it in
polynomial time. Often this certicate is simply the solution to the search problem version
of the decision problem. When it is clear from the context, we will interchangeably refer to
it as the certicate or the solution.
Lets exemplify this notion of a certicate with a few examples and then dene it formally.
TSP: In the case of the traveling salesman problem, on input (G. 1) with n vertices the
certicate is a a tour
1
. ...
a
in the graph whose total cost is less than or equal to K. To
verify the certicate, one checks that (1)
1
=
a
(2) for all i = 1...:, there is a
)
= i (3)
i1
ucipt(
i
.
i+1
) < 1. All this can be done in time O(V+E).
SAT: For example, a certicate that a formula o with n variables and m clauses is in SAT is
a truth assignment to the variables which makes it true. For n variables, this certicate is
of size n, and it takes O(nm) time to verify it by evaluating the formula on this assignment.
HAM: For example, in the case of Hamilton cycle, the certicate (or solution) would be a
closed path that visits each node once, and to verify it one need to check that (1) all vertices
5
are visited (2) no vertex is visited more than once. and (3) rst and last vertices are the
same.
Factoring: In the case of case of factoring on the certicate would be a divisor which is
smaller than the bound. Namely, for input pair (`, 1), the certicate is divisor d of `
such that 2 d 1 and d divides `. To verify it we must check that (1) d divides ` and
(2)1 < d < `
These certicates have the following properties:
Every yes input to the problem has at least one certicate (possibly many), and each
no input has none.
They are succinct In each case the certicate is bounded in size by a xed polynomial
in the length of the input. i.e the truth assignment is of length : which is linear in the
size of the formula.
They are easily veriable. In each case there is a polynomial algorithm which takes
as inputs the input of the problem and the alleged certicate, and checks whether the
certicate is a valid one for this input. In the case of Hamilton cycle whether the given
closed path indeed visits every node once. And so on.
We call the class of decision problems which have such certicates NP.
2
.
NP: class of decision problems for which there exists a verication algorithm \
and
constant c 0 such that for r an input of ( where : = log r.)
1. \
(r. ) = 1:nc
Remarks:
Remark 1: NP DOES NOT MEAN not polynomial time !!!
EXP: decision problems whose solution takes exponential time
P: decision problems whose solution takes polynomial time
NP: decision problems with ecient verication algorithms
Remark 2:
Not all problems have short and easy veriable certicates. Consider, for example, the
problem non-SAT problem: Given a formula o, how would you prove quickly (even if you
were a magician) that it is true that there is no truth assignment that makes the formula
2
NP stands for nondeterministic polynomial, meaning that all problems in it can be solved in polynomial time by a
nondeterministic computer that starts by guessing the right certicate, and then checking it.
6
true. Or the graph-Non-Isomorphism: How would you prove that there is NO mapping
between all the vertices of the rst graph to those of the second graph which respects the
edge relationship. You could obviously enumerate all of them but that would not take
polynomial time but exponential time. Note that the above problems have exponential size
certicates and solutions. For example for non-satisability, if you cycle through al the
possible solutions to a formula and if none satisfy it, then you know its not satisable. Even
worse, some problems can not be solved at all in principle (they are called undecidable). So,
its not a matter of ineciency but of impossibility. An example of such a problem is the
halting-problem. Given a program 1 and an input r, decide if 1(r) will terminate. For
proof, take 6.045.
How about non-compositeness? Or Primality : is there a short proof that a number is
prime (rather then being composite)? It turns out that yes, but its non-trivial, and was
shown by Pratt in the late seventies.
Primality testing is naturally dened as a decision problem.
Primes: on input p output Yes if p is prime and no otherwise.
Theorem Primes are in NP
This follows from the existence of a certicate of the fact that 2
j
= j 1 which naturally
is only true for primes. What is used is the fact that 2
j
is cyclic. Namely, has a generator :
an element of order p-1. In other words, 2
j
= {p
i
mod j : i = 1. .... j 1} The certicate is:
(p, proof that p is order j 1).
Further reading: What is a short proof of g being order p-1.
4 P vs. NP problem
Notice that P is a subset of NP. Why? Intuitively, because checking the validity of a solution
is easier than coming up with a solution. For example, it is easier to get jokes than to be a
comedian.
Formally, if a problem is in P, there exists a polynomial time algorithm A that solves P.
Dene \
(r) = (r). Obviously, the output is true if and only if (r) = 1 c:. So, here
the execution of A is the certicate. (The recent result that primality is in P, thus yields
another proof that PRIMES problem is in NP).
A big question is whether 1 = `1 ???
Intellectually speaking, the P=NP? problem is very appealing. It asks whether it is as easy
to come up with a solution as it is to check that the solution is correct If this was the case
it would mean that if we show that a problem is in NP (which is generally simple to do
compared to designing ecient algorithms to nd solutions) it is also in P. Assuming the
7
proof would be constructive, this would provide an easy recipe to solve thousands of problems
currently intractable. On the other hand it would mean that modern cryptography which
is based on the fact that P is dierent than NP is impossible. This question of P vs. NP is
truly the million dollar question of computer science
3
After four decades of research, and
thousands, everyone seems to believe that P = NP, but no one has proven it.
What we can do is identify some problems in NP which seem to be harder (or at least as
hard) than all the rest, in the sense that if we could solve one of these special problems in
polynomial time then we could solve every problem in NP in polynomial time. We call these
the NP-complete problems. To answer the question P=NP? you could concentrate all your
eorts in answering whether an NP-complete problem has a polynomial time algorithm.
The rst problem shown NP-complete by Steve Cook in 1974 is cSAT.
Cooks Theorem: Every problem in NP can be reduced in polynomial time to circuit
SAT.
What does it mean to be reduced in polynomial time? Informally, we say that A is polynomial
time reducible to B that you can turn in polynomial time a instance of A to an instance of
B. It follows that a polynomial time algorithm for B, can be used it to obtain a polynomial
time algorithm for A.
Lets talk about reductions more formally.
Reductions between Problems
Formally, let and 1 be two decision. A poly-time reduction from to 1 is a polynomial-
time algorithm 1 which transforms inputs of to equivalent inputs of 1. That is, given an
input r to problem . 1 will produce an input 1(r) to problem 1, such that r is a yes
input of if and only if 1(r) is a yes input of 1. Notation: <
j
1 (A is reducible to
B).
4
Obviously a reduction from to 1 together with a polynomial time algorithm for 1, gives
a polynomial algorithm for . For any input r of of size :, the reduction 1 takes time
j(:) -a polynomial to produce an equivalent input 1(r) of 1. If we now submit this input
1(r) which is at most j(:) in length to the assumed algorithm for 1, running in time (:)
on inputs of size :, where is another polynomial, then we get the right answer of r, within
a total number of steps at most j(:) +(j(:)) also a polynomial.
Showing NP-completeness of a problem B by reducing all NP problems to B, is dierent
than the way we have used reductions before. Earlier in the course we used reductions to
3
See http://www.claymath.org/prizeproblems.
4
Actually the above way to dene a poly-time reduction is a special case called Karp-reduction. A more general type of
reduction with the same underlying meaning is called cook-reduction. In a cook-reduction from A to B: there exists a pair of
polynomial time algorithms R and D such that on input x to problem A, R(x) computes a sequence y1...ym inputs to problem
B, and D(x,B(y1)...B(ym))=A(x). In this class we will use the term polynomial-time reduction to mean a Karp-reduction.
8
establish that problems are easy (e.g., from matching to max-ow). In this part of the class
we shall use reductions (in a more sophisticated and counterintuitive context), in order to
prove that certain problems are hard. If we reduce A to B, we are establishing that, give or
take a polynomial, A is no harder than B. If we know 1 is easy, this establishes that is
easy. If we know is hard, this establishes 1 is hard.
Going back to Cooks theorem, since all problems in NP can be reduced to cSAT, this means
that all of them are no harder than cSAT.
9