0% found this document useful (0 votes)
11 views7 pages

R-23 Adsnaa Unit-5 NP Hard and Complete

The document discusses NP-Hard and NP-Complete problems, categorizing them into problems solvable in polynomial time (P) and those solvable in non-deterministic polynomial time (NP). It defines decision and optimization problems, explains the characteristics of NP-Complete and NP-Hard classes, and introduces Cook's Theorem, stating that the Boolean satisfiability (SAT) problem is NP-Complete. The document also provides examples of non-deterministic algorithms and their complexities.

Uploaded by

Hemanth Atla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

R-23 Adsnaa Unit-5 NP Hard and Complete

The document discusses NP-Hard and NP-Complete problems, categorizing them into problems solvable in polynomial time (P) and those solvable in non-deterministic polynomial time (NP). It defines decision and optimization problems, explains the characteristics of NP-Complete and NP-Hard classes, and introduces Cook's Theorem, stating that the Boolean satisfiability (SAT) problem is NP-Complete. The document also provides examples of non-deterministic algorithms and their complexities.

Uploaded by

Hemanth Atla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Unit 5

NP – HARD AND NP – Complete Problems

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 P:- Problem that can be solved in polynomial time.

Eg:- Searching, sorting, All pairs shortest path.

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

A problem D is called NP – Complete if –

(i) If belongs to class NP.


(ii) Every problem in NP can also be solved in polynomial time.

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.

Non – Deterministic 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.

The non – deterministic algorithm is a two stage algorithm

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.

Non – deterministic algorithm uses 3 functions.

Choose( ):- Arbitrary chooses one oe the elements os set S.

Failure( ):- indicates unsuccessful completion.

Success( ):- indicates a successful completion.

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 ( );

Therefore, time complexity of a non- deterministic algorithm is O(1).

Therefore, time complexity of above is O(1).


Example (2) Sorting of elements

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.

NP – HARD & NP – COMPLETE CLASSES:

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

→The question is whether or not

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.

→ The relationship between P and NP is shown as follows.

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”

→NP – complete class is the intersection of the NP and NP – Hard classes.


Fig : Relationship between P, NP, NP – complete & NP – Hard.

→Normally, decision problem are NP-complete lent optimization problem are


NP-Hard.

→Two problem P & Q are said to be polynomial equivalent if and if p α Q and Q


α p.

Cook’s Theorem:-

Statement:-Boolean satisfiability (SAT) problem is NP complete.

Proof:-

The Satisfiability problem:

Let

1) A variable is a member of {x1, x2, .....}


2) A hiteral can be either a variable xi or it can be a complement xi
3) A clause is a disjunction of literals.

C = x1 v x2 v x3 - - - - - v xk.

4) A Boolean formula is a conjunction of clauses.


C1 ˄ C2 ˄ - - - - - - Cm
Thus for a satisfiability(SAT) problem (or) A Boolean formula f.

Is there truth assignment to the variables of f that makes f true?

For e.g.:- Consider a Boolean formula ( x1 v x2 v x3 ) ˄ ( x1 v x2 v x3 ) ˄ ( x1 v x2 )


˄ ( x1 v x2) .

The assignment to variable of f is x1=1, x2=0, x3=0. Then,


f = (x1 v x2 v x3) ˄ (x1 v x2 v x3) ˄ (x1 v x2) ˄ (x1 v x2)

= ( 1 v 0 v 1 ) ˄ ( 0 v 1 v 1) ˄ ( 1 v 1 ) ˄ ( 0 v 1)

=1˄1˄1˄1=1

f=1

Thus f is true for x1 = 1, x2 = 0, x3 = 0. Then this formula is satisfiable.

Proof:- Scientist Stephen Cook in 1971 stated that Boolean satisfiability (SAT)
problem is NP- complete.

The Boolean satisfiability is in NP. This is because a non- deterministic algorithm


can guess an assignment of truth values of variable. This algorithm can also
determine the value of expression for corresponding assignment and can accept if
entire expression is true.

The algorithm is composed of

1) Input tape where input tape is divided in to finite number of cells.


2) The read/write head which reads each symbol from tape.
3) Each cell contains only one symbol at a time.
4) Computation is performed in number of states.
5) The algorithm terminates when it reaches to accept state.

The conjunction clauses for Boolean expression are given is following table.

Clauses Meaning Time


O (p(n))
Tij O Cell i of input tape contains Symbol j.
Qs O Initial state O(1)
Ho O Initial position of tape head O(1)
Tijk=Tij(k+1) 2 Hik Tape remains unchanged unless written O(p(n2))
Qqk→┐Qqk One state at a time O(p(n))
O(p(n2))
Hik →┐Hik One read/write head position at a time
Tijk→┐Tijk One symbol per tape cell at a time O(p(n2))
Note that H denotes head, Q denotes states and T denotes tape. The disjunction
clauses for this algorithm can be written as

Clause Meaning Time


Possible O (p(n2))
(Hik ˄ Qqk ˄ Tijk)→ transition

(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.

*********

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy