0% found this document useful (0 votes)
95 views

NP Hard and NP Complete Problems

This document discusses NP-hard and NP-complete problems. It defines problems that can be solved in polynomial time by deterministic algorithms as being in P, and problems that can be solved in polynomial time by non-deterministic algorithms as being in NP. NP-hard problems are at least as hard as the hardest problems in NP, and NP-complete problems are NP-hard problems that are also in NP - meaning they are the hardest problems in NP. Determining if P=NP or P≠NP is a major unsolved problem in computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

NP Hard and NP Complete Problems

This document discusses NP-hard and NP-complete problems. It defines problems that can be solved in polynomial time by deterministic algorithms as being in P, and problems that can be solved in polynomial time by non-deterministic algorithms as being in NP. NP-hard problems are at least as hard as the hardest problems in NP, and NP-complete problems are NP-hard problems that are also in NP - meaning they are the hardest problems in NP. Determining if P=NP or P≠NP is a major unsolved problem in computer science.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Np hard and Np complete problems

• In this topic we are concerned with the


distinction b.w problems that can be solved by
a polynomial time algo. And problems for
which no polynomial time algo is known.
• The problems categoies into two groups.
• 1. the first group whose solution are bounded
by polynomials of small degree.
• Ex: 0(n), 0(logn) , o(nlogn) etc.
Cont..
• 2,. Second group: problems whose best-
known algos. Are non-polynomial.
• Ex: tsp complexity ??
• Knapscak complexity ??
• No one has solved these problem in
polynomial time yet now.
Cont..
• This is very important because algos whose
time are greater than polynomial time very
quickly require such vast amounts of time to
execute that even moderate – size problems
cannot be solved.
• The theory of NP-completeness which we
going to discuss does not provide a method pf
obtaining poly. Time algos. For problems in
the second group.
• Nor does it say that algos. Of this complexity
do not exist.
• Instead, what we do is show that many
problems for which there are no known poly.
Time algos are computationally related.
Np-hard Np-complete
• A problem that is np-complete has the property
that it can be solved in poly. Time iff if all other
np-complete problems can also be solved in poly.
Time.
• If an np-hard problem can be solved in poly. Time
, then all np-complete problems can be solved in
ploy.
• All np-complete problems are np- hard, but some
np-hard problems are not known to be np-
complete.
Non-deterministic algorithms
• Deterministic: The algorithm in which every operation is
uniquely defined is called deterministic algorithm.
• Non-Deterministic: The algorithm in which the operations
are not uniquely defined but are limited to specific set of
possibilities for every operation, such an algorithm is
called non-deterministic algorithm.
• The non-deterministic algorithms use the following
functions:
• 1. Choice: Arbitrarily chooses one of the element from
given set s.
• 2. Failure: Indicates an unsuccessful completion
• 3. Success: Indicates a successful completion
• X: = choice(1,n)could result in x being assigned
any one of the integer in the range[1,n].
• Failure() and success() signals are used to
define a computation of the algo.
• Whenever there is a set of choices that leads
to a successful completion, then one such set
of choices is always made and the algo.
Terminates successfully.
• A non-detrministic algo . Terminates
unsuccessfully iff if there exists no set of
choices leading to a success signal.
• The time for choice, success, failure are 0(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[j]=x or j=0 if x is not in A.
Non –deterministic algo.
• Algorithm Search(A,x)
• {
j=Choice(1,n);
if(A(j)=x) then
{
Write(j);
Success();
}
else
{
Write(0);
Failure();
}
}
• The number 0 can be output iff if there is no j
such that A[j]= x.
• Non-deterministic time is 0(1).
• While deterministic search time is ???
sorting
• Let A[i] , 1<=i<=n, be an unsorted array of
positive integers. The non-deterministic algo.
Nsotrt(A, n). Sorts the numbers into non-
decreasing order and then outputs them in
this order.
• An B[1:n] array is used .
• Algorithm nd_sort(A,n)
{
//”a” is array to be sorted and “b” is array for auxiliary storage
for i = 1 to n do do B[i]=0;
For i=1 to n do
{
j = Choice(1,n);
if B[j] ≠ 0 then Failure();
B[j] = a[i] //create the array “b” by selecting “n” elements
}
for i = 1 to n -1 do// verify number
{
if(B[i] > B[i+1]) then failure();
write(B[1:n]);
success();
}
• Complexity 0(n)
• Deterministic -0(nlon)
• A deterministic intretation of a non-
determinstic algo , in theory each time a
choice is to be made, the algorithm makes
several copies of itself.
• One copy is made for each of the possible
choices.
• Thus, many copies are executing at the same
time.
• The first copy to reach a successful completion
terminates all other computations.
• If a copy reaches a failure completion , then
only that copy of the algorithm terminates.
• Non-deterministic has the ability to select a
“correct” element from the set of allowable
choices (if such an element exists) every time
a choice is to be made.
• A correct element is defined relative to a
shortest sequence of choices that leads to a
successful termination.
• In case there is no sequence of choices
leading to a successful termination, we
assume that the algo. Terminates in one unit
of time with output “ unsuccessful
termination.
• Any problem for which the answer is either 0
or 1 is called decision problem. An algo. For a
decision problem is termed a decision
algorithm. Any problem that involves the
identification of an optimal( max or min) value
of a given cost function is known as
optimization problem.
• it is possible to construct the non-detrministic
algo. For such problem.
• Decision problem: The solution to the
problem is "yes" or "no". Most optimization
problems can be phrased as decision
problems (still have the same time
complexity).
Example : Assume we have a decision
algorithm X for 0/1 Knapsack problem with
capacity M, i.e. Algorithm X returns “Yes” or
“No” to the question “is there a solution with
profit  P subject to knapsack capacity  M?”
Non deterministic knapsack
Algo DKP(p, w, n, m, r, x)
{
W=0; P=0;
for i=0 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(); // check whether the profit is at least r.
else success();
}
• It assigns 0/1 values to x[i] for all i, 1<=i<=n.
• A successful termination is possible iff the
answer to the decision problem is yes.
• The tome--- 0(n).
• If q is the input length using a binary
representation , the time is 0(q).
• Ex; a positive integer khas alength of
floor(logk+1) bits when in binary.
The classes of Np-hard and Np-
complete
• Def: If p is the set of all decision problems
solvable by deterministic algo. In poly time .
Np is the set of all decision problems solvable
by non-deterministic algo in poly time.
• Since deterministic algo. Are just a special case
of non-deterministic ones, we conclude that p
is subset of np.
• Unsolved problem in cs is whether p=np or p
not equal to np
• Is it possible that all the problems in np , there
exist poly time deterministic algos that have
remained undiscovered?
Commonly relationship b/w p and np
when p not equal tp Np
• Cook: satisfiability is in P iff P=NP.
Relationship b/w P ,np ,NP-HARD AND
NP-complete

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