R-23 Adsnaa Unit-5 NP Hard and Complete
R-23 Adsnaa Unit-5 NP Hard and Complete
Basic Concepts:- There are two groups in which a problem can be classified. The first group
consists of the problem that can be solved in polynomial time. For example searching of an element
from the list O(log n), sorting of elements O(log n).
The second group consists of problems that can be solved in non – deterministic
polynomial time. For example – knapsack problem O(2n/2) and travelling salesperson problem
(O(n2 2n)).
Decision Problem:- Any problem for which answer is either YES or NO is called “Decision
Problem”. The algorithm for decision problem is called “Decision Algorithm”.
Optimization Problem:- Any problem that involves the identification of optimal cost (Minimum
(or) Maximum) is called optimization problem. The algorithm for optimization problem is called
optimization algorithm.
Definition of NP:- problem that can be solved in non – deterministic polynomial time.
Eg:- Travelling sales person, Graph coloring, knapsack problem, Hamiltonian circuit problem.
Computational
Complexity Problems
P- Class NP - Class
NP – Complete NP - Hard
If an NP – Hard problem can be solved in polynomial time then all NP – complete problem can
also be solved in polynomial time.
All NP – complete problems are NP – Hard but all NP – Hard problems cannot be NP – complete.
NP class problem are the decision problems that can be solved by non deterministic polynomial
algorithm.
The algorithm in which every operation is uniquely defined is called deterministic algorithm.
The algorithm in which every operation may not have unique result, rather there can be specified
set of possibilities for every operation. Such an algorithm is called non – deterministic algorithm.
Non – deterministic means that no particular rule is followed to make y\the guess.
Non – deterministic (Guessing) stage:- Generate a non- deterministic string that can be thought
of as a candidate solution.
Deterministic (verification) stage:- In this stage it takes as input the candidate solution and the
instance to the problem and returns Yes if the Candidate solution represents actual solution.
Example (1)
Consider the problem of searching for an element x in a given set of elements A[1:n], n ≥ 1. We
are required to determine an index j such that A[i] = x or j = 0 if x is not in A. A non deterministic
algorithm for this is –
J := choice (1,n);
If A[j] = x then {write (j); success ( );}
Write (0); failure ( );
Algorithm NSORT(A, n)
{
for i:= 1to n do B[i] := 0;
for i := 1 to n do
{
j := choice(1, n);
if B[j] ≠ 0 then failure ( );
B[j] := A[i];
}
for i :=1 to n-1 do
if B[i]> B[i+1] then failure ( );
write (B[1:n]);
success ( );
}
In the above algorithm initially the auxiliary array B[ ] is set to 0. Then each element one
by one from the input set is such into the auxiliary array B[ ]. At each time two elements of B[ ]
are compared with each other. This process places all the elements of the array in ascending order.
If the elements in the function B[ ] are not in order then failure function will be called else success
function will be called & contents of B[ ] will be displayed.
Example3:-
Maximum clique:- “The maximal sub graph of a graph is a clique”. The size of the clique is the
number of vertices in it. The max clique problem is an optimization problem that has to determine
the size of a largest clique is G(v, e)). The decision problem is to determine whether & has clique
of size of least K (for source given K).
Algorithm DCK(g, n, k)
{
s:=Ø;
for i:=1 to K do
{
t:=choice(1, n);
if t € s then failure( );
S:=S U {t}
}
for all pairs(i, j) such that I € s , j € s, and I ≠ j do
if(i, j) is not an edge of g then failure( );
success( );
}
The above algorithm considers two nodes in a graph and checks whether they form an edge.
Then another node which forms an edge with the first edge is found. This process repeats until a
maximal closed sub graph is formed. The nature of nodes in the resultant sub graph is the clique
of the graph.
P denotes the class of all deterministic polynomial language problems and NP-denotes the class of
all non deterministic polynomial language problems.
hence, P ≤ NP
P = NP
→The problems which are known to lie in P are often called as track able problems which lie
outside of P are after turned as intractable.
NP – problems
P – problems
→A NP – problem such that if it is in P, then NP = P. If aproblem has this same property then it is
called “NP – Head”
Cook’s Theorem:-
Proof:-
Let
C = x1 v x2 v x3 - - - - - v xk.
= ( 1 v 0 v 1 ) ˄ ( 0 v 1 v 1) ˄ ( 1 v 1 ) ˄ ( 0 v 1)
=1˄1˄1˄1=1
f=1
Proof:- Scientist Stephen Cook in 1971 stated that Boolean satisfiability (SAT)
problem is NP- complete.
The conjunction clauses for Boolean expression are given is following table.
(H(i+j)(k+1) ˄ Qq(k+1)˄Tij(k+1)
Moving to accept O (1)
Disjunction of all clauses Qf state
If B is satisfiable, then there is an accepting state is the algorithm.
Thus the proof shows that Boolean satisfiability problem can be solved in
polynomial time. Hence all problems in NP could be solved in polynomial time. And
Hence the complexity class NP could be equal to P.
*********