P and NP

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Lecture 21

P and NP Problems
Time complexity

2
Introduction

Decision Optimisation
Problems Problems

3
Decision Problem
• In computability theory, a decision problem is a problem that can be posed as a 
yes-no question of the input values.
• Ex: “Given two numbers x and y, does x evenly divide y?".
• The answer is either 'yes' or 'no' depending upon the values of x and y.

4
Optimisation Problems
• An optimization problem is the problem of finding the best solution from all feasible
solutions.
• find a solution in the feasible region which has the minimum (or maximum) value of
the objective function.

5
P and NP Problems
• P is set of decision problems that can be solved in polynomial time by a
deterministic computer: which means that at any time during the computation, the
next computation step is uniquely determined.
•  These problems can be solved in time O(nk) in worst-case, where k is constant.
• These problems are called tractable, while others are called intractable or
superpolynomial.

6
Intractable Problems
• As the Problem size grow large, we are unable to solve them in reasonable time
• What constitutes reasonable time?
• Standard working definition: polynomial time
• On an input of size n the worst-case running time is O(nk) for some constant k
• Polynomial time: O(n2), O(n3), O(1), O(n lg n)
• Not in polynomial time: O(2n), O(nn), O(n!)

7
Examples: P Problems

8
NP Problems
• NP (nondeterministic polynomial time) is the set of problems that can be solved in
polynomial time by a nondeterministic computer.
• Non-deterministic machine basically tries all alternatives in parallel, with the time
complexity being equal to the longest path (always polynomial length) in the
potentially exponentially wide search tree.
• Thus, the class NP are those problems that can be tested/verified in polynomial
time.
• Deterministic implementations of non-deterministic machines require checking all
possible solutions leading to exponential time complexity

9
Nondeterminism
• In a non-deterministic algorithm, there are one or more possibilities for being the next
computation step, and the algorithm chooses one of them.
• Think of a non-deterministic computer as a computer that magically “guesses” a solution,
then has to verify that it is correct
• If a solution exists, computer always guesses it.
• One way to imagine it: a parallel computer that can freely spawn an infinite number of
processes
• Have one processor work on each possible solution
• All processors attempt to verify that their solution works
• If a processor finds it has a working solution
• So: NP = problems verifiable in polynomial time

10
Example: NP
• HAMILTON-PATH:
Given an undirected graph G = (V, E), does there exist a simple path P that visits every
node?
• Even though we don’t have a fast polynomial time algorithm to determine whether a graph
contains a HAMPATH or not.
• If such a path is discovered somehow (maybe with exponential time brute force searching)
we could easily-work it out whether the path is HAMPATH or not, in polynomial time.
• Here the certificate will be a Hamiltonian path from s to t itself in G if exists. So HAMPATH
is in NP.

11
Example 2: NP
• TSP is NP-Complete, first we have to prove that TSP belongs to NP.
• In TSP, we find a tour and check that the tour contains each vertex once.
• Then the total cost of the edges of the tour is calculated.
• Finally, we check if the cost is minimum. This can be completed in polynomial time.
• Thus TSP belongs to NP.

12
A Glimpse
So far:

• P = problems that can be solved in polynomial time


• NP = problems for which a solution can be verified in polynomial time
• Unknown whether P = NP (most suspect not)

13
• P  NP, because every problem in P has a solution in NP

14
Reduction
• Let L1 and L2 be two decision problems.
• Suppose algorithm A2 solves L2. That is, if y is an input for L2 then algorithm A2 will
answer Yes or No depending upon whether y belongs to L2 or not.
• The idea is to find a transformation from L1 to L2 so that the algorithm A2 can be
part of an algorithm A1 to solve L1.

15
NP Hard and NP Completeness
• Problems for which there is no polynomial time complexity, are computationally
related.
• There are two classes of such problems:
• NP HARD
• NP COMPLETE

16
NP Complete
• These are the hardest problems in NP. Such a problem is NP-hard and in NP.
• A problem is in the class NPC if it is in NP and is as hard as any problem in NP.
• If a polynomial time algorithm exists for any of these problems, all problems in NP
would be polynomial time solvable. These problems are called NP-complete.

17
NP Completeness

The problem that is NP complete has the property that it can be solved in polynomial
time if and only if all the other NP complete problems can be solved in polynomial
time.

18
Examples: NPC
• Satisfiability Problem
• Clique Problem
• Graph Coloring

19
NP Hard Problems
• At least as hard as the hardest problems in NP. Such problems need not be in NP; indeed,
they may not even be decision problems.

• The following problems are NP-Hard


• The circuit-satisfiability problem
• Set Cover
• Vertex Cover
• Travelling Salesman Problem
20
NP Hard and NP Complete
• NP-hard-- Now suppose we found that A is reducible to B, then it means that B is
at least as hard as A.
• NP-Complete -- The group of problems which are both in NP and NP-hard are
known as NP-Complete problem.

21
22

You might also like