Professional Documents
Culture Documents
Relationship Between P and NP PDF
Relationship Between P and NP PDF
P & NP
Relationship between P and NP
Veningston. K
Computer Science and Engineering
Unit V - Outline
• 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
• 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”
• Example 2:
– Given a graph G
– TSP solution whose weight is at most 100
– The solution given is “ABCDA”
• 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
• 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
• 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
• 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”.