NP –Hard and NP-Complete Problems
Basic Concepts
P, NP, NP-Hard and NP-Complete are classes that any problem would fall under or would
be classified as.
The computing times of algorithms fall into two groups.
Group1– consists of problems whose solutions are bounded by the polynomial of small
degree. Example – Binary search o(log n) , sorting o(n log n), matrix multiplication 0(n
2.81).
Group2 – contains problems whose best known algorithms are non polynomial. • Example
–Traveling salesperson problem 0(n22 n ), knapsack problem 0(2 n/2 ) etc.
P- Polynomial time solving . Problems which can be solved in polynomial time, which take
time like O(n), O(n2), O(n3).
It uses deterministic algorithm.
Eg: finding maximum element in an array or to check whether a string is palindrome or not.
so there are many problems which can be solved in polynomial time.
These problems are called tractable, while others are called intractable or
superpolynomial.
NP- Non deterministic Polynomial time solving. Problem which can't be solved in
polynomial time like TSP( travelling salesman problem) or An easy example of this is
subset sum: given a set of numbers, does there exist a subset whose sum is zero?.
but NP problems are checkable(verified) in polynomial time means that given a solution
of a problem , we can check that whether the solution is correct or not in polynomial time.
It uses the non deterministic algorithms
There are two classes of non polynomial time problems 1) NP- hard 2) NP-complete
P versus NP
Every decision problem that is solvable by a deterministic polynomial time algorithm is
also solvable by a polynomial time non-deterministic algorithm.
All problems in P can be solved with polynomial time algorithms, whereas all problems
in NP - P are intractable.
It is not known whether P = NP. However, many problems are known in NP with the
property that if they belong to P, then it can be proved that P = NP.
If P ≠ NP, there are problems in NP that are neither in P nor in NP-Complete.
The problem belongs to class P if it’s easy to find a solution for the problem. The problem
belongs to NP, if it’s easy to check a solution that may have been very tedious to find.
To define NP – hard and NP-Complete classes of problems. We need to know reducibility.
Reduction: Let L1 and L2 be problems. Problem L1 reduces to L2 if and only if there is a
way to solve L1 in a deterministic polynomial time using deterministic algorithm that
solves L2 in polynomial time.
Non-deterministic Algorithms
Deterministic algorithm, for a given particular input, the computer will always produce
the same output going through the same states. Can solve the problem in polynomial
time. Can determine the next step of execution.
Non-deterministic algorithm, for the same input, the compiler may produce different
output in different runs. In fact non-deterministic algorithms can’t solve the problem in
polynomial time and can’t determine what is the next step. The non-deterministic
algorithms can show different behaviors for the same input on different execution and
there is a degree of randomness to it.
To implement a non-deterministic algorithm, we have a couple of languages like Prolog
but these don’t have standard programming language operators and these operators are
not a part of any standard programming languages.
Some of the terms related to the non-deterministic algorithm are defined below:
choice(X) : chooses any value randomly from the set X.
failure() : denotes the unsuccessful solution.
success() : Solution is successful and current thread terminates.
Problem Statement : Search an element x on A[1:n] where n>=1, on successful search
return j if a[j] is equals to x otherwise return 0.
Non-deterministic Algorithm for this problem :
j= choice(a, n)
if(A[j]==x) then
write(j);
success();
write(0);
failure();
In Computer Science, many problems are solved where the objective is to maximize or
minimize some values, whereas in other problems we try to find whether there is a
solution or not. Hence, the problems can be categorized as follows −
Optimization Problem
Optimization problems are those for which the objective is to maximize or minimize some
values. For example,
Finding the minimum number of colors needed to color a given graph.
Finding the shortest path between two vertices in a graph.
Decision Problem
There are many problems for which the answer is a Yes or a No. These types of problems
are known as decision problems. For example,
Whether a given graph can be colored by only 4-colors.
Finding Hamiltonian cycle in a graph is not a decision problem, whereas checking a
graph is Hamiltonian or not is a decision problem.
NP-Hard and NP-Complete Classes
NP-Hard: L is NP-hard if for all L' ϵ NP, L' ≤p L. Thus if we can solve L in polynomial time,
we can solve all NP problems in polynomial time.
NP-Complete: L is NP-complete if
L ϵ NP and
L is NP-hard
If any NP-complete problem is solvable in polynomial time, then every NP-Complete
problem is also solvable in polynomial time. Conversely, if we can prove that any NP-
Complete problem cannot be solved in polynomial time, every NP-Complete problem
cannot be solvable in polynomial time.
Cook’s Theorem
Cooks Theorem implies that any NP problem is at most polynomially harder than SAT. This
means that if we find a way of solving SAT in polynomial time, we will then be in a position
to solve any NP problem in polynomial time. This would have huge practical repercussions,
since many frequently encountered problems which are so far believed to be intractable
are NP. This special property of SAT is called NP-completeness. A decision problem is NP-
complete if it has the property that any NP problem can be converted into it in polynomial
time. SAT was the first NP-complete problem to be recognized as such (the theory of NP-
completeness having come into existence with the proof of Cooks Theorem), but it is by no
means the only one. There are now literally thousands of problems, cropping up in many
different areas of computing, which have been proved to be NP-complete.
In order to prove that an NP problem is NP-complete, all that is needed is to show that SAT
can be converted into it in polynomial time. The reason for this is that the sequential
composition of two polynomial-time algorithms is itself a polynomial-time algorithm, since
the sum of two polynomials is itself a polynomial.
Suppose SAT can be converted to problem D in polynomial time. Now take any NP problem
D0. We know we can convert it into SAT in polynomial time, and we know we can convert
SAT into D in polynomial time. The result of these two conversions is a polynomial-time
conversion of D0 into D. since D0 was an arbitrary NP problem, it follows that D is NP-
complete