0% found this document useful (0 votes)
20 views4 pages

NPcomplete

The document discusses NP hard and NP complete problems. It defines the complexity classes P, NP, NP-hard and NP-complete. Some key problems like knapsack, traveling salesman and satisfiability are shown to be NP-complete. Reducibility is introduced to show the relationship between these complexity classes.
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)
20 views4 pages

NPcomplete

The document discusses NP hard and NP complete problems. It defines the complexity classes P, NP, NP-hard and NP-complete. Some key problems like knapsack, traveling salesman and satisfiability are shown to be NP-complete. Reducibility is introduced to show the relationship between these complexity classes.
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/ 4

UNIT-V

NP HARD AND NP-COMPLETE PROBLEMS.

Basic concepts:

NP Nondeterministic Polynomial time.

two groups.
Group-1
Problems with solution time bound by a polynomial of a small degree. They are also

algorithms. Ex: Ordered Search (O (log n)), Polynomial evaluation O(n)


Sorting O(n.log n)

Group-II
Problems with solution times not bound by polynomial (simply non polynomial ). These
are hard or intractable problems. None of the problems in this group has been solved by any
polynomial time algorithm. Ex: Traveling Sales Person O(n2 2n), Knapsack O(2n/2)

No one has been able to develop a polynomial time algorithm for any problem in the
group II. So, it is compulsory and finding algorithms whose computing times are greater
than polynomial very quickly because such vast amounts of time to execute that even
moderate size problems cannot be solved.

Theory of NP-Completeness:

Show that may of the problems with no polynomial time algorithms are computational time
algorithms are computationally related.

There are two classes of non-polynomial time problems

1. NP-Hard
2. NP-Complete

NP Complete Problem: A problem that is NP-Complete can solved in polynomial time if and
only if (iff) all other NP-Complete problems can also be solved in polynomial time.

NP-Hard: Problem can be solved in polynomial time then all NP-Complete problems can be
solved in polynomial time.

All NP-Complete problems are NP-Hard but some NP-Hard problems are not know to be NP-
Complete.

157
Nondeterministic Algorithms:

Algorithms with the property that the result of every operation is uniquely defined are termed
as deterministic algorithms. Such algorithms agree with the way programs are executed on a
computer.

Algorithms which contain operations whose outcomes are not uniquely defined but are limited
to specified set of possibilities. Such algorithms are called nondeterministic algorithms.

The machine executing such operations is allowed to choose any one of these outcomes
subject to a termination condition to be defined later.

To specify nondeterministic algorithms, there are 3 new functions.

Choice(S) arbitrarily chooses one of the elements of sets S

Failure () Signals an Unsuccessful completion

Success () Signals a successful completion.

Example for Non Deterministic algorithms:

Algorithm Search(x){
//Problem is to search an element x
//output J, such that A[J]=x; or J=0 if x is not in A
J:=Choice(1,n);
if( A[J]:=x) then
{
Write(J);
Success();
}
else{
write(0);
failure();
}
Whenever there is a set of choices that leads to a successful completion then one such set of
choices is always made and the algorithm terminates.
A Nondeterministic algorithm terminates unsuccessfully if and only if (iff) there exists no set
of choices leading to a successful signal.

Nondeterministic Knapsack algorithm


Algorithm DKP(p, w, n, m, r, x)
{

158
W:=0;
P:=0;
for i:=1 to n do{
x[i]:=choice(0, 1);
W:=W + x[i]*w[i];
P:=P + x[i]*p[i];
}
if( (W>m) or (P<r) ) then Failure();
else Success();
}
p given Profits w given Weights
n Number of elements (number of p or w) m Weight of bag limit
P Final Profit W Final weight

The Classes NP-Hard & NP-Complete:


For measuring the complexity of an algorithm, we use the input length as the parameter. For
example, An algorithm A is of polynomial complexity p() such that the computing time of A
is O(p(n)) for every input of size n.
Decision problem/ Decision algorithm: Any problem for which the answer is either zero or
one is decision problem. Any algorithm for a decision problem is termed a decision algorithm.
Optimization problem/ Optimization algorithm: Any problem that involves the
identification of an optimal (either minimum or maximum) value of a given cost function is
known as an optimization problem. An optimization algorithm is used to solve an optimization
problem.

P is the set of all decision problems solvable by deterministic algorithms in polynomial time.
NP is the set of all decision problems solvable by nondeterministic algorithms in polynomial
time.

Since deterministic algorithms are just a special case of nondeterministic, by this we


concluded that P NP

Commonly believed relationship between P & NP

In considering this problem, s.cook formulated the following question.

If there
that P=NP.
159
Cook answered this question with

Theorem: Satisfiability is in P if and only if (iff) P=NP

Notation of Reducibility

Let L1 and L2 be problems, Problem L1 reduces to L2 (written L1 2) iff there is a way to


solve L1 by a deterministic polynomial time algorithm using a deterministic algorithm that
solves L2 in polynomial time

This implies that, if we have a polynomial time algorithm for L2, Then we can solve L1 in
polynomial time.

L1 2 and L2 3 then L1 3

A problem L is NP-Hard if and only if (iff) satisfiability reduces to L ie.,

A problem L is NP-Complete if and only if (iff) L is NP-Hard and

Commonly believed relationship among P, NP, NP-Complete and NP-Hard

Most natural problems in NP are either in P or NP-complete.

Examples of NP-complete problems:


Packing problems: SET-PACKING, INDEPENDENT-SET.
Covering problems: SET-COVER, VERTEX-COVER.
Sequencing problems: HAMILTONIAN-CYCLE, TSP.
Partitioning problems: 3-COLOR, CLIQUE.
Constraint satisfaction problems: SAT, 3-SAT.
Numerical problems: SUBSET-SUM, PARTITION, KNAPSACK.

160

You might also like