NP Completeness

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

NP- Completeness

Is every problem is easy to solve?


If a problem can be solved in polynomial time,
then we consider it faster (converge faster)
To know about the difficulty of a program, we
will discuss about NP-Completeness
Problems :
– Decidable (algo exists)
– Un-decidable (no algo exists)
Decidable Problems


Tractable
– If there exists at least one polynomial bound
algorithm (nk)
– Run fast

Intractable
– If the problem is not tractable then it is intractable
– Run slow
Intractable


Difficult to solve

For large value or range of input it will take a lot
time to solve

Example: travelling salesman problem
So what we do?


We dont look for exact answers
– Example: in travelling salesman problem we are not
interested in finding shortest route but we want to
find out the route between two nodes.
– This approach is called as heuristic ( or
approximation) that is we are looking for some
solution which may be not a optimal solution or
exact solution.
– Approximation soliutions run faster.
Un-decidable Problems


No algorithm exists

Example: halting problem of turing machine
Some examples


Shortest path problem is tractable
– What is think about longest path problem?

Eulers tour : every edge is repeated exactly
once
– It is tractable

Hamiltonion cycle: every vertex is repeated
exactly once
– Intractable
– Sub problem of travelling salesman problem
Optimization Problems


Optimzation problems :
– TSP
– 0/1 Knapsack
– LCS

In all the problems above we are looking for
optimal solution
How to know whether problem is easy or hard
to solve?
– We go for some subproblem and work on it
– If is his hard to solve then bigger problem is also
hard to solve
– Example: in TSP one subproblem may be “ is there
any shortest path covering all vextex of lengh
atmost k?”
Decision Problems

For a given poblem if you look for some


subproblem. The given subproblem can be
answered or not.
These subproblems are called as decision
problems.
if decision prolem is hard then given problem is
hard.

Is there any shortest path covering all the
vertices of length atmost k

Is there any solution whose orofit is atleast k

Is there any subsequence whose length is
atleast k

If optimiztion problem is easy then decision
problem is easy

If decision problem is hard then optimization
problem is hard

So for optimization problem our focus is to look
for decision problems
Verification Algorithm


Given some input

And a decision problem

And a answer

- verify whether answer is right?


Why Verification Algorithm?


Suppose somesome has solved optimization
problem

Someone has given you a answer

- so for given decision problem you will look for


verification problem, if it is hard, then decision
problem is hard compare to optimization
problem
OP -- DP – Solution

if OP is solved in (nk) then check for verification


algorithm for given DP, if it takes (nk) then you
can say OP is solved in (nk)
P & NP


P is a set of all DP for which there exists a
polynomial time algorithm to solve

NP is a set of all DP for which there exists a
polynomial time verfication algorithm

If you solve the problem in polyomial time then
you can verify the problem in polynomial time

So every P class problem there will be
verfication algorithm which runs in a polynomial
time.
So
every problem in P will also be in NP
So the millions dollar question is :

P = NP

There are many problems which are in NP but
not in P like TSP, 0/1 Knapsack.

So if someone solve these in polynomial time
then these belong to P.

So as of now (NP-P) is intractable.

Since 1971, no one able to give polynomial time
solution to (NP-P) problems nor any proof that
these can not be solved in polynomial time.

We can not solve all the (NP – P) problems in
polynomial time.

We can come up with some problem which is
harder than (NP – P) problems.

If we solve that problem in polynomial time then
all other (NP – P) problem can be solved in
polynomial time.
Reducability
Reducability

A problem ‘A’ is said to be polynomial time


reducible to a problem ‘B’ if

Every instance x of ‘A’ can be transformed to
some instance y of ‘B’ in polynomial time.

Answer to ‘x’ is yes if and only if answer to ‘y’ is
Yes.
Example


Given n boolean variables with value
x1,x2,x3...xn, does at least one variable have the
value “True’.’
– (T,F,T,F)
● Given n integers i1,i2,i3.....in is
max(i1,i2,i3.....in > 0)
– (20,0,3,-2)
Example Continued..

Covert problem ‘A’ (T,F,T,F) to some intance of


problem ‘B’ (1,0,1,0)
here reduction is polynomial time and problem
‘B’ can be solved in polynomial time, so
problem ‘A’ can be solved in polynomial time

You might also like