(Class - 10) - NP Completeness
(Class - 10) - NP Completeness
Tractability
Some problems are intractable: as they grow large, we are unable to solve them in reasonable time.
Here, reasonable time means polynomial time.
On an input of size n the worst-case running time is O(nk) for some constant k.
Polynomial time: O(n2), O(n3), O(1), O(n lg n)
Not in polynomial time: O(2n), O(nn), O(n!)
Polynomial-Time Algorithms
Every algorithm we’ve studied so far provides polynomial-time solution to some problem. But not all
problems are solvable in polynomial time. Turing’s “Halting Problem” is not solvable by any computer, no
matter how much time is given. Most problems that do not yield polynomial-time algorithms are either
optimization or decision problems.
(The Halting Problem is this: given a Turing machine and an input to the Turing machine, does the Turing
machine finish computing in a finite number of steps (a finite amount of time)? In order to solve the
problem, an answer, either yes or no, must be given in a finite amount of time regardless of the machine
or input in question. Clearly some machines never finish. For example, we can write a Turing machine
that counts upwards starting from one.)
Optimization/Decision Problems
An optimization problem is one which asks, “What is the optimal solution to problem X?”
An optimization problem tries to find an optimal solution.
Examples:
1) 0-1 Knapsack
2) Fractional Knapsack
3) Minimum Spanning Tree
A decision problem is one which asks, “Is there a solution to problem X with property Y?”
A decision problem tries to answer a yes/no question.
Examples:
1) Does a graph G have a MST (Minimum Spanning Tree) of weight ≤ W?
Some problems are decidable, but intractable: as they grow large, we are unable to solve them in
reasonable time.
Page 1 of 3
[Class - 10] – NP Completeness
The Class P
P is the class of decision problems that have polynomial-time deterministic algorithms.
That is, they are solvable in O(p(n)), where p(n) is a polynomial on n. A deterministic algorithm is
(essentially) one that always computes the correct answer.
The class NP
NP is the class of decision problems that are solvable in polynomial time on a nondeterministic machine
(or with a non-deterministic algorithm). Thus NP can also be thought of as the class of problems whose
solutions can be verified in polynomial time. Note that NP stands for “Nondeterministic Polynomial
Time”.
Given a Boolean expression on n variables, can we assign values such that the expression is TRUE?
This problem seems simple enough, but no known deterministic polynomial time algorithm exists. But it
is very easy to verify in polynomial time.
CNF Satisfiability
P And NP Summary
P = set of problems that can be solved in polynomial time.
NP = set of problems for which a solution can be verified in polynomial time.
Clearly P is a proper subset of NP
An open question: Does P = NP?
NP-complete problems
Reduction:
A problem P can be reduced to another problem Q if any instance of P can be rephrased to an instance of
Q, the solution to which provides a solution to the instance of P.
Intuitively it can be said that if P reduces in polynomial time to Q, P is “no harder to solve” than Q.
Example:
1) Cook’s theorem is NP-complete
2) CNF-sat is NP-complete
Page 3 of 3