You are on page 1of 48

Unit 5 NP Completeness

AISHWARYA
Introduction

 Computers and Intractability: A Guide to the Theory of NP-Completeness “ by


Michael Garey and David S. Johnson; Freeman, New York, 1979.
 Scott Aaronson, a complexity researcher at MIT, explains his intuition about P
vs. NP:
 "If P were equal to NP, then the world would be a profoundly different
place than we usually assume it to be. There would be no special value in
"creative leaps", no fundamental gap between solving a problem and
recognizing the solution once it's found. Everyone who could appreciate a
symphony would be Mozart; Everyone who could follow a set-by-step
argument would be Gauss
P and NP

 (Polynomial Time): The class of decision problems for which a solution can be
verified quickly (in polynomial time) once it is provided.
 NP (Nondeterministic Polynomial Time): The class of decision problems for
which a solution can be guessed and checked quickly (in polynomial time) using
a nondeterministic Turing machine. In NP, finding the solution may not be
quick, but verifying it is.
Solvable vs Unsolvable Problems
Problem taxonomy

 Tractable problem: Have good algorithms with polynomial time complexity


(irrespective of the degree)
 Tractable Problem: A problem that is solvable by a polynomial-time
algorithm.
 Intractable problem: Have algorithms with super polynomial time
complexity(exponential or factorial time complexity) ex: or
 Intractable Problem: A problem that cannot be solved by a polynomial-time
algorithm.
 Un-decidable Problem: Do not have algorithms of any known complexity
(polynomial or super-polynomial).
Decidable vs Undecidable Problem

 A problem is said to be Decidable if we can always construct a


corresponding algorithm that can answer the problem correctly.
 A problem is decidable if there exists an algorithm that, given any input, will
correctly determine whether the answer is "yes" or "no.
 There is a systematic and effective procedure to find the solution to the problem
for any input.
 Sorting a list of numbers, finding the shortest path in a graph, or determining if
a number is prime are decidable problems because algorithms exist to solve
them for any given input.
Undecidable Problems

 A problem is undecidable if there is no algorithm that can always provide an


answer (either "yes" or "no") for every possible input.
 For undecidable problems, there is no systematic and effective procedure that
guarantees finding a solution for all cases.
 Undecidable problem is the Halting Problem, proposed by Alan Turing
Intractable Problem

 Intractable problems are problems for which there exist no efficient algorithms
to solve them.
 Most intractable problems have an algorithm – the same algorithm – that
provides a solution, and that algorithm is the brute-force search.
 This algorithm, however, does not provide an efficient solution and is, therefore,
not feasible for computation with anything more than the smallest input.
 Example : TSP, GRAPH COLORING
Tractable Problem

 problems is "polynomial time solvable" or simply "easy" problems.


 problem is considered tractable if there exists an algorithm whose worst-case
running time is polynomial in the size of the input.
 Tractable problems have algorithms that can find a solution in a reasonable
amount of time for inputs of practical size.
 Tractable problems include sorting a list of numbers, finding the shortest path
in a graph using Dijkstra's algorithm, and determining whether a number is
prime
P Problem

 Problem for which there is a polynomial time algorithm are called tractable.
 A problem is assigned to the P represent the class of problems which can be
solved by a deterministic Polynomial algorithm.
P Problem

 A language L (a set of strings) is in P if there exists a polynomial-time


deterministic Turing machine M such that, for every input string x:
 If x is in L, then M accepts x in polynomial time.
 If x is not in L, then M rejects x in polynomial time.
 Examples of problems in P include:
 Sorting: Given a list of numbers, can they be rearranged in non-decreasing
order?
 Searching: Given a sorted list of numbers, is a particular number present in
the list?
 Shortest Path: What is the shortest path between two nodes in a graph?
NP Problem

 A problem is assigned to the NP (nondeterministic polynomial time) class if it is solvable


in polynomial time by a nondeterministic Turing machine.
 A problem is assigned to the NP represents the class of decision problem which can be
solved by a non-deterministic polynomial algorithm.
 A P-problem (whose solution time is bounded by a polynomial) is always also NP.
 If a problem is known to be NP, and a solution to the problem is somehow known, then
demonstrating the correctness of the solution can always be reduced to a single P
(polynomial time) verification.
 If P and NP are not equivalent, then the solution of NP-problems requires (in the worst
case) an exhaustive search.
NP class

 Class NP is the class of decision problems that that can be solved by


nondeterministic polynomial algorithms. This class of problems is called
nondeterministic polynomial.
 The class P is a sub-class of NP (since any problem that can be solved in
polynomial time can also be verified in polynomial-time, if only by solving the
problem and comparing solutions).
 But NP also contains many problems that can be verified in polynomial-time but
for which there is no known polynomial-time solution.
Deterministic

 In a deterministic algorithm, the execution is entirely predictable and follows a


single, well-defined sequence of steps for any given input.
 Deterministic algorithms are commonly used in various applications, and they
are easy to analyze and understand.
 Example: A simple deterministic algorithm for finding the maximum element in
an array could involve iterating through the array and keeping track of the
maximum value encountered.
Non- Deterministic

 In a nondeterministic algorithm, there is an element of randomness or


uncertainty during execution.
 The same input may lead to different possible outcomes on different runs of the
algorithm.
 Nondeterministic algorithms are often used in situations where there are
multiple possible solutions, and the algorithm explores different paths
simultaneously or probabilistically.
 Example: The Monte Carlo algorithm for estimating the value of π is a
nondeterministic algorithm. It uses random sampling to approximate the value
and can produce different results in different runs.
How to solve

 Write non deterministic algorithm instead of deterministic algorithm


 Solve one problem and show similarity in all other
Non Deterministic algo search : writing ND
for exponiential problem

Algorithm Nsearch(A,n,key)
{
j=choice();
if(key=A[j])
{ write(j); success();}
Write(0);
Failure();
}
 P is Deterministic Polynomial time taking algorithm
 NP is Non Deterministic Polynomial Time Taking Algorithm
 Deterministic is subset of Non Deterministic Algorithm
Satisfiability Problem: Base Problem
Reducibility
Randomization

You might also like