Day-38 30april2021 UNIT-5 NP Complete Class

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

BE IV SEMESTER (CSE Batch “B”)

CS-1842 Analysis and Design of Algorithm


Unit-4 Topic:- NP P

Dr. Sunil Joshi


Polynomial Time Algorithm
 For any particular Algorithms if their worst-
case running time is O(nk), for some constant k
and input size n then this algorithm will be
Polynomial Time algorithm.
 The complexity of Polynomial time algorithm is
called Polynomial Time Complexity.
 The problem whose solution time are bounded
by Polynomial of some degree like ordered
searching which is O(logn) , Polynomial
evaluation which is O(n), Sorting which is O(n2)
are type of Polynomial time algorithm.
Non Polynomial Time Algorithm
 Non-Polynomial Time algorithm
(Exponential) are those, whose best-known
algorithm are non-polynomial or for which
no polynomial time algorithm is known.
 The complexity of non-polynomial time
algorithm are called non-polynomial time
complexity.
 Example:- Travelling Salesman Problem
O(n22n), Knapsack algorithm O(2n/2)
Polynomial vs.Non Polynomial
Polynomial vs.Non Polynomial
Complexity Class
 Complexity Class can be defined as a set of
languages, membership in which, is determined
by a complexity measure, such as running time ,
on an algorithm that determine whether a given
string x belong to language L.
 The actual definition of a complexity class is
some what more technical using this language
theoretic framework.
 We can provide an alternative definition of the
complexity class P
 P= { L<={0,1}: there exist an algorithm A that
decide L in polynomial time}
Decision Problem
 Many of the Problem described occur
naturally as optimization problems ( they are
called combinatorial optimization problems
), but they can also be formulated as decision
problem.
 The classes P and NP are classes of decision
problems.
 Basically, a decision problem is a question
that has two possible answers yes and no. the
question is about some input.
Decision Problem
 A problem instance is the combination of the
problem and a specific input.
 Usually the statement of a decision problem has
two parts.
 The instance description part defines the
information expected in the input
 The question part states the actual yes-or-no
question the question contains variables defined
in the instance description.
 A decision problem’s output is either yes or no
according to the correct answer to the question, as
applied to a given input.
The class P
 An algorithm is said to be polynomially
bounded if its worst case complexity is bounded
by a polynomial function of the input size(i.e. if
there is a polynomial p such that for each input
of size n the algorithm terminates after at most
p(n) steps).
 A problem is said to be polynomially bounded if
there is a polynomially bounded algorithm for it
 P is the class of decision problems (
combinatorial optimization problem) that are
polynomial bounded.
The class NP
 A nondeterministic algorithm has two phases
and an output step
 The nondeterministic “guessing” phase
 The deterministic “verifying” phase
 If the verifying phase return true, the
algorithm output is yes otherwise there is no
output.
The class NP
 A nondeterministic algorithm is said to be
polynomially bounded if there is a fixed
polynomial P such that for each input of size
n for which the answer is yes, there is some
execution of the algorithm that produces a
yes output in at most P(n) steps.
The class NP
 NP is the class of decision problems for which
there is a polynomially bounded non-
deterministic algorithm( the names NP comes
from “Nondeterministic Polynomially
bounded” )
 Example:- Graph coloring, Hamiltonian
cycle , job scheduling with penalties,
travelling salesman problem, knapsack
problem.
P⊆NP
P vs NP
 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 non-deterministic algorithms in
polynomial time.
 Since deterministic algorithms are just a
special case of nondeterministic ones , we
conclude that P⊆NP
P vs NP

NP
P
P vs NP
NP Complete
 A Problem L is NP-Complete if and only if L
is NP- Hard and LεNP
 A Problem L is NP hard if and only if
satisfiability reduces to L .
Reduction
 Let L1 and L2 be problems.
 Problem L1 reduces to L2 if and only if there
is a way to solve L1 by a deterministic
polynomial time algorithm using a
deterministic algorithm that solves L2 in
polynomial time.
Reduction
SAT
Note
 NP is the class of decision problems that can be
solved by non-deterministic polynomial algorithms.
 Problems that cannot be solved in polynomial time
are known as intractable.
 the time complexity of Horner's rule in polynomial
evaluation is O(n)
 If a problem Z is in NP Class. Then If Z is NP-hard,
then it is NP-complete.
 Raju and Sonu have been asked to show that a
certain problem W is NP-complete. Raju shows a
polynomial time reduction from the 3-SAT problem
to W, and Sonu shows a polynomial time reduction
from W to 3-SAT then W is NP-complete
?
drsuniljoshi.cse@satiengg.in
Thank You

You might also like