Lecture 15
Lecture 15
Lecture No. 15
1
NP Completeness
Until now we have been designing algorithms for
specific problems.
We have seen running times O(logn), O(n), O(nlogn), O(n2),
O(n3), .
We often think about problems we can solve in polynomial
time O(nk) as being easy/practically solvable/tractable
We have seen a lot of these
Similarly we think about problems we need exponential
time like O(2n) to solve as being hard/practically
unsolvable/intractable
We have seen a few of these.
NP Completeness
Showing that a problem has an efficient
algorithm is relatively easy.
“All’ that is needed is to demonstrate an
algorithm.
Proving that no efficient algorithm exists for a
particular problem is difficult.
How can we prove the non-existence of
something?
NP Completeness
Goal:
To study interesting class of problems (called NP
Complete)
whose status is unknown.
i.e., no polynomial time algorithm has yet been
discovered, nor has anyone yet been able to prove that
no polynomial time algorithm can exist for any one of
them.
One of the deepest research problem in theoretical
computer science.
NP Complete
• The problem of finding an efficient solution to an NP-
Complete problem is known as P ≠ NP?.
• There is currently a US$1,000,000 award offered by the
Clay Institute (http://www.claymath.org/) for its
solution
• In the remainder of this module we will introduce the
notation, terminology and tools needed to discuss NP-
Complete problems and to prove that problems are
NP-complete.
Proving that a problem is NP-Complete does not prove
that the problem is hard.
It does indicate that the problem is very likely to be hard.
NP Complete
Why so difficult?
Several NP-Complete Problems are very similar to problems
that we know already how to solve in polynomial time.
For example:
• Shortest simple path vs. Longest simple path
• Fractional Knapsack vs. 0-1 Knapsack
• Euler Tour vs Hamiltonian Cycle
• 2-CNF Satisfiability vs. 3-CNF Satisfiability
In Boolean logic, a formula is in conjunctive normal
form (CNF) if it is a conjunction of one or more
clauses, where a clause is a disjunction of literals;
otherwise put, it is a product of sums or an AND of
ORs
Class P
Informal discussion
The class P consists of those problems that are solvable
in polynomial time.
More specifically, they are problems that can be solved
in time O(nk) for some constant k, where n is the size of
the input to the problem.
Most of the problems we have examined are in class P
Class NP
Consider Hamiltonian cycle problem
Given a directed graph G = (V, E) a ‘certificate’ is a
sequence v = (v1 ,v2 ,v3 ,…..v|V|) of |V| vertices.
We can easily check/verify in polynomial time if v is an
Hamiltonian cycle or not.
Consider the problem of 3-CNF Satisfiability
A certificate here is an assignment of values to the
variables.
We can easily check/verify in polynomial time
whether the assignment satisfies the boolean formula.
Class NP
The class NP consists of those problems that are
verifiable in polynomial time.
Already observed that Hamiltonian Cycle Problem &
3-CNF Satisfiability problem are in class NP.
Note
If a problem is in P then we can solve it in polynomial
time & so given a certificate it is verifiable in
polynomial time
Therefore P NP
The open question is whether P ⊂ NP?
Class NP-Complete
A problem is in the class NPC (referred as NP-Complete) if
1. It is in NP
2. Is as ‘hard’ as any problem in NP
Note
Most computer scientists believe that NP-complete
problems are intractable.
Because, if any NP-complete problem can be solved in
polynomial time then every problem in NP has a
polynomial time algorithm.
- We will prove this later
NPC
Technique to show that the problem is NP-complete:
Different than what we have been doing:
We are not trying to prove the existence of polynomial
time algorithm
Instead we are trying to show that no efficient or
polynomial time algorithm is likely to exist.
Three key ideas needed to show problem is NPC
1. Decision problem vs. Optimization problem
2. Reductions
3. First NP-complete problem
Decision problem vs. Optimization problem
Decision problem vs. Optimization problem
Many problems of interest are Optimization problems
Decision SPP
Instance: A weighted graph G, two nodes s and t of G,
and a bound b
Question: is there a simple path from s to t of length at
most b?
Decision problem vs. Optimization problem
Observe, if one can solve an optimization problem (in
polynomial time), then one can answer the decision
version (in polynomial time)
Example: If we know how to solve MST we can solve DST
which asks if there is an Spanning Tree with weight at
most k.
How?
First solve the MST problem and then check if the MST
has cost k.
If it does, answer Yes.
If it doesn’t, answer No
Decision problem vs. Optimization problem