You are on page 1of 20

Design and Analysis of Algorithms (18CSE107)

P & NP
Relationship between P and NP

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)
P vs. NP (Revisited)

• P
– If the problem is solvable in polynomial time, it is P
• NP
– If the problem is decidable and if we do not have any
polynomial time algorithm till now, then these problems
are NP
– We do not know anything about NP
• We do not whether they could be solved in polynomial time or
they cannot be solved in polynomial time
• Future will decide (No one knows)
Decision Problems

• We use only decision problems in NP-Completeness


theory.
• Every optimization problem can be actually
reframed into a decision problem
• Decision problem is easy compared to optimization
problem
– Easy means there is O(nk) algorithm
Decision Problems

• If the optimization problem is easy, then the


decision problem is turn out to be easy.
– It is trivial
• If the decision problem is hard or intractable, then
definitely optimization problem will be intractable.
– Because, decision problem is simpler compared to
optimization problem
Verification Algorithms

• Example 1:
– Given a graph G, the question is “Is this Hamiltonian Cycle?”
– It is said to be Hamiltonian cycle, if all the vertices are visited exactly
once and come back to starting vertex.
1 2
• Assume that a graph is given as input and the question is
given (which is a decision problem) & Assume that solution is
also given, 3
– We should verify using this solution, whether this question can be
answered with “YES” or “NO”

Solution path: ABCDA

ABCDA is Hamiltonian Cycle or Not?


Verification Algorithms
• Verification algorithm verifies whether an answer is
right or wrong.
• In the earlier example:
– Definitely, ABCDA is containing all the vertices
– And all the vertices are exactly once.
– Therefore, it is a candidate to be a Hamiltonian Cycle
• How to verify?
– Is it possible to visit them in this order at all?
• There should be path from A to B, B to C, C to D and D to A
– Check if all the vertices are present in the graph
– Check if the edges mentioned in the solution are present
in the graph.
Verification Algorithms

• Example 2:
– Given a graph G
– TSP solution whose weight is at most 100
– The solution given is “ABCDA”
• What is the algorithm for verification?
– Check if all the vertices are covered or not  Yes
– Check if all the edges existing in the graph or not  Yes
– Add up all the edge weights and check if total edge weight
is at most 100.
• The total edge weight is 97 which is < 100  Yes
Verification Algorithms – Formal definition

• Verification algorithm is that given a solution, we


should be able to verify whether the solution is right
or wrong.

• Verification algorithm runs in polynomial time.


P & NP

• P
– Set of all decision problem for which there is an
algorithm which solve the problem in polynomial time
• NP
– NP is not P  this statement is wrong


• The set of all problems for which there is no polynomial time
algorithm is NP.
– The set of all decision problems for which there is a
polynomial time verification algorithm is NP
Facts about NP

• No one has ever expanded NP as Non-Polynomial ✘


• We really do not know anything about NP problems.

• What we only know is,


– There are set of all decision problems whose solution can
be verified in polynomial time.
Relationship between P and NP

• If we are able to solve the decision problem in


polynomial time, then it belongs to P class
• Example 1:
– Given a graph G
– Let the decision problem by “Is there a Minimum cost
Spanning Tree whose weight is at most 10?”
• Can we solve this problem in Polynomial time?  YES
– We have algorithms for this optimization problem
• Prim’s algorithm
• Kruskal’s algorithm
Is there a solution which is having a MST whose weight is at most 10?
P Class

• Example 2:
– Given a Fractional knapsack problem,
– “Is there any solution whose profit is at least 10?”
– Do we have a polynomial time algorithm?  YES
• We solved it using Greedy method
• Time complexity is O(nlogn)
• NOTE:
– All the problems which we have seen before dynamic
programming, greedy and divide and conquer are going to
take polynomial time
NP Class
• NP are the set of all problems for which there is a
verification algorithm
– To verify the solution in polynomial time.
• If we are able to solve a problem in polynomial time,
we will be able to verify the solution in polynomial
time.
– Finding solution is a big thing
– Verifying solution is a simple thing
• Therefore, every problem in P will also be in NP.
Along with them, there would be extra problems in
NP.
Examples - NP

• TSP
– We failed to find out any polynomial time solution
– However, given a solution, we can verify it in polynomial
time.
– Therefore, TSP falls in NP. But not in P
• 0/1 Knapsack
– We are not able to find out the polynomial time algorithm
– Given a solution, we can verify it.
– Therefore, this problem also falls in NP
P vs. NP

• Relationship between P and NP


– If a problem is in P, definitely it is in NP
– If it could be solved, then it could be verified in polynomial
time.
• In future, if someone solves it in polynomial time,
then this problem will go into P class
– TSP, 0/1 Knapsack
P vs. NP

• Relationship between P and NP


– NP – P are intractable.
– The problems which are not in P and in NP

Problems solvable in Problems verifiable in


polynomial time. polynomial time.
P Problems NP Problems
NP

• We do not know anything about NP – P


– w.d.n.k whether these problems could be solved in
polynomial time or these problems can never be solved in
polynomial time.
• Since 1971, till this date,
– This problem is open “will anyone be ever able to propose
a solution for these kind of problems (Ex: TSP), which is
not in P”
NP

• Many researchers believe that P is present inside NP


– P is a proper subset of NP
• Since 1970’s, researchers are continuously fail to
prove that we could find a polynomial time algorithm
for these problems.
– We started believing that “there is no proof exist”
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.

You might also like