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

Design and Analysis of Algorithms (18CSE107)

Reducibility
Polynomial time Reduction Algorithms

Veningston. K
Computer Science and Engineering
Unit V - Outline

• Network flow problem


– Ford Fulkerson Algorithm for Maximum Flow Problem

• NP–Hard and NP–Complete Problems


– Terminologies
– Examples
– Complexity Class - P, NP, NP-Complete, NP-Hard
– Is P=NP?

– Reducibility
•Design and Analysis of Algorithms
•2
(18CSE107)
Open questions

• P != NP?  we should show that, there is at least one problem outside P for
which “no one could ever produce a polynomial time algorithm”.

• P == NP?  if all the problems lying outside P could be solved in polynomial


time, then all these problems will move to P.
How to solve NP Problems?

• To win Turing Award, we may have to prove P==NP


or P != NP.
– Till now, no one proved it

• We solve many real life problems using


Approximation.
– Close approximation
Polynomial time Reduction Algorithm

• Problems in P can be quickly solved or easily solved.


• Problems in NP can be quickly verified or easily
verified.
– We do not know whether it could be solved easily or not.
– How many such problems in NP?

Millions of Problems
Scenario

• Chess grandmaster
Why Reducibility?

• It is impossible to solve all these problems, because


there are millions of problems.
• Take a single problem which is harder than all these
problems
– If we could solve that problem in polynomial time, then
we could solve all these problems in polynomial time
– In order to do that, we need a notion of Reducibility
Reducibility

• Reducibility means a problem can be reduced to


other problem.
• Let’s see how to reduce all these problems to one
problem.

Millions of Problems
Reducibility - Definition

• A problem ‘A’ is said to be polynomial time reducible


to a problem ‘B’ if,
– Every instance α of ‘A’ can be transformed to some
instance β of ‘B’ in polynomial time

– Answer to α is ‘YES’ if and only if answer to β is ‘YES’

NOTE: We are talking about Decision Problems only


Polynomial time Reduction

• What is the importance of this polynomial time


conversion?
– We talk about the conversion which will take only
polynomial time (O(nk)).
• In case, if we have a polynomial time algorithm to
solve ‘B’ i.e. O(nl)
– Now we have to solve the problem ‘A’
– But we have converted it to problem ‘B’ in polynomial
time.
How to solve problem ‘A’?

• Convert it to some problem ‘B’ which takes O(nk)


• Solve ‘B’ in O(nl)

α β
O(nk)
‘A’ ‘B’
O(nl)
O(nk) + O(nl)
If we have such a conversion,

• We can say 2 statements


– If ‘B’ is easy, then we can say that ‘A’ is also easy

– If ‘B’ is in P, then ‘A’ is also in P

• NOTE:
– We are doing everything not to say that a problem is easy. ✘
– We are doing everything to say that a problem in hard (or)
difficult
How can we say that a problem is hard?

• Let us assume that a problem which is already


proven not to be in P.
– If it is proved that no one could solve the problem ‘A’ in
polynomial time, then this problem ‘A’ is not in P class.

• Then, we can find out that ‘B’ can also be not in P.


– Hence, ‘B’ is hard.
Proof

• If ‘A’ is not in P, which means ‘A’ is hard, then


definitely ‘B’ is not in P

O(nk)
‘A’ ‘B’
‘A’ is not in P
Problem Conversion?

• We shall try to convert a problem in polynomial


time and show the problem is easier.

• The 2 problems are:


– ‘A’: Given ‘n’ Boolean variables with values x1,x2,…, xn, does
at least one variable have the value TRUE.

– ‘B’: Given ‘n’ integers i1,i2,…, in, is max(i1,i2,…, in) > 0


How Polynomial reduction actually works?
• Given problems are,
– ‘A’: Given ‘n’ Boolean variables with values x1,x2,…, xn, does
at least one variable have the value TRUE.
– ‘B’: Given ‘n’ integers i1,i2,…, in, is max(i1,i2,…, in) > 0
• ‘A’:
– If n = 4, the problem instance is (T, F, F, T)
– Does at least one variable has ‘True’? YES
• ‘B’:
– If n = 4, the problem instance is (-30, -1, 0, 2)
• Integer could be +ve or -ve or zero
– Is there at least one ‘positive integer’ in that? YES
• At least one value which is > 0
How Reduction works?

• The problems ‘A’ and ‘B’ are decision problems.


• Problem ‘B’:
– Can we solve this problem in polynomial time? YES
– Algorithm:
• Check 1st value, if it is > 0, say ‘YES’
• Otherwise, go to the next element.
• By the end, if we are not able to find any +ve integer, then say ‘NO’
– Takes O(n) time.
– We have a polynomial time algorithm for solving problem
‘B’.
How Reduction works?

• The problems ‘A’ and ‘B’ are decision problems.


• Problem ‘A’:
– Convert it to problem ‘B’
– How to convert ‘A’ to ‘B’?
• Take the problem instance of ‘A’ i.e. (T, F, F, T)
• Scan the entire instance and if there is T, convert it to 1, if there is
F, convert it to 0.
• (T, F, F, T)  (1, 0, 0, 1)
– Now, the answer to problem ‘A’ is ‘YES’, if and only if the
answer to ‘B’ is ‘YES’
• Because, there is at least one number which is > 0  (1, 0, 0, 1)
– This conversion is polynomial time conversion
Proof

O(n)
‘A’ ‘B’
O(n)

• Time taken to solve ‘A’ is O(n) + O(n)


• This is trivial problem
• This is how reduction algorithm works.
If Reduction take exponential time?
O(2n)
‘A’ ‘B’
O(n)

• Time taken to solve ‘A’ is O(2n) + O(n)


• This is not polynomial time reducibility.

• NOTE:
– If ‘B’ easy, then ‘A’ is easy i.e. if ‘B’ is in P, ‘A’ is in P
– If ‘A’ is not in P, ‘B’ is not in P i.e. if ‘A’ is hard, ‘B’ is harder
– Conversion works only for Decision problems
– Conversion should take place in polynomial time

You might also like