Vous êtes sur la page 1sur 58

P, NP Classes

Deliverables Unsolvability Satisfiability Problem Classification Reductions

NP-Complete and NP-Hard


6/15/2012 Copyright @ gdeepak.com 2

Easy Vs. Hard


Euler Circuit vs. Hamiltonian Circuit

Shortest Path vs. Longest Path


Minimum Spanning Tree vs. Edge Cover vs. Min Cut vs. Max Cut 2-Dim Matching vs. 3-Dim Matching Dominating Set Vertex Cover

2-Colorability vs. Colourability


2-Satisfiability vs. Satisfiability
6/15/2012 Copyright @ gdeepak.com 3

Solvable and Unsolvable

We can categorize the problem space into two parts Solvable Problems

Unsolvable problems
6/15/2012 Copyright @ gdeepak.com 4

Halting Problem
Given a description of a program and a finite input, decide whether the program finishes running in a finite time or will run forever, given that input The halting problem is famous because it was one of the first problems proved undecidable, which means there is no computer program capable of correctly answering the question for all possible inputs.

Given an polynomial , Does it has an integer solution

6/15/2012

Copyright @ gdeepak.com

Diagonalization
In a small town of Sundargarh All those who dont know how to do make-up go to the only beauty parlor of Sunaina in the town and those who know how to do make-up do it themselves.
Set of all Finite State Machines that dont accept itself will go to a Finite state machine that runs them It is similar to the powerful idea of diagonalization

6/15/2012

Copyright @ gdeepak.com

Post Correspondence Problem


U1 U2 U3 U4 aba bbb aab bb V1 v2 v3 v4 a aaa abab babba Solution to this problem is the sequence 1, 4, 3, 1 because u1u4u3u1 = aba + bb + aab + aba = ababbaababa = a + babba + abab + a = v1v4v3v1 The problem is to find whether such a solution exists or not
6/15/2012 Copyright @ gdeepak.com 7

Moving towards solution


From not solvable we come to the concept of how well we can solve the problems logn- logarithmic time n- linear time nlogn near linear time n2 square time n3 cubic time n4 --- nk - higher polynomial or super polynomial
6/15/2012 Copyright @ gdeepak.com 8

P Class of Problems
All those algorithms that can be solved in polynomial time with worst case running time as O(nk). So these problems are regarded as tractable. K can not be a variable, but has to be fixed.
A problem that can be solved polynomially in one model can also be solved polynomially in other model.

6/15/2012

Copyright @ gdeepak.com

Minimum Spanning Tree Shortest Path Sorting Min-Max Max Flow Convex Hull

6/15/2012

Copyright @ gdeepak.com

10

Internal Structure of P
O(nk) K is fixed O(n3)

O(n2)
O(n) O(logn)

O(1)

6/15/2012

Copyright @ gdeepak.com

11

Big Picture
Unsolvable EXPSPACE

EXPTIME
PSPACE NP

6/15/2012

Copyright @ gdeepak.com

12

NP

Vertex Cover Graph Coloring Travelling Salesman Max-Cut in a graph Steiner Tree Subgraph isomorphism Dominating Set

6/15/2012

Copyright @ gdeepak.com

13

How many
There are thousands of known NP-complete problems Known till now. There are definitely thousands of others which have not been explored yet. More and more are coming into the net as the researchers prove the reduction of a problem into already known NP-Complete Problem.

6/15/2012

Copyright @ gdeepak.com

14

Determinism
If the result of every operation is uniquely defined then we call that algorithm as deterministic algorithm.
If we remove this notion and we say that the output of an operation is not unique but limited to a set of possibilities In theoretical computer science, a non-deterministic Turing machine (NTM) is a Turing machine (TM) in which state transitions are not uniquely defined.
6/15/2012 Copyright @ gdeepak.com 15

Non-deterministic Machines
These can do things in parallel as long as the resulting choices can be connected with or and any of them is true.
It can choose one of the possible choices at any point of time at the same time

6/15/2012

Copyright @ gdeepak.com

16

Non determinism
A Non deterministic algorithm for searching an element x in a given set of elements A[1..n] 1. j= choice(1,n) 2. if A[j]=x then write (j); Success 3. else write(0); Failure

6/15/2012

Copyright @ gdeepak.com

17

Non determinsitic sorting


Algorithm Nsort For i=1 to n do B[i]=0; for i=1to n do { j= choice(1,n); if b[j]<>0 then failure();
B[j] = a[i] } for i= 1 to n-1 do if B[i] > B[i+1] then failure; success();

6/15/2012

Copyright @ gdeepak.com

18

Non-deterministic Polynomial (NP)


It is the set of all problems that can be solved in polynomial time with non-deterministic concept. However this concept only exists in theory. There are no implementations what so ever.

6/15/2012

Copyright @ gdeepak.com

19

Decision Problems
A decision problem is that problem which can have only two options as its solution space i.e. yes or no. Whether x is a prime number is also a decision problem that will have answer yes or no. For a Travelling salesperson problem the question that whether a tour of cost < k exists is a decision problem.

6/15/2012

Copyright @ gdeepak.com

20

Guess & verify


So for many problems it will be like guess & verify situation. We will guess a particular solution and then verify that whether this is the solution (yes) or not ( no) If this guessing and verifying can be done in polynomial time with the help of a non deterministic concept then we say that the problem is in NP

6/15/2012

Copyright @ gdeepak.com

21

Non Determinism
Non deterministic machine checks all of them at once Can be done hypothetically. Means we need exponential number of parallel processors to do the same task in a deterministic way in polynomial time. So Non deterministic machine will take 3n If you have a good guess, then it can be done in a polynomial time, otherwise total number of guesses are exponential.

6/15/2012

Copyright @ gdeepak.com

22

Satisfiability Problem
Satisfiability is the problem of determining if the variables of a given Boolean formula can be assigned in such a way as to make the formula evaluate to TRUE. Equally important is to determine whether no such assignments exist, which would imply that the function expressed by the formula is identically FALSE for all possible variable assignments. In this latter case, we would say that the function is unsatisfiable; otherwise it is satisfiable. To emphasize the binary nature of this problem, it is frequently referred to as Boolean or propositional satisfiability.
6/15/2012 Copyright @ gdeepak.com 23

Satisfiability Problem
if f(x1,x2,xn) = True xi = 0 or 1 we have to find x1,x2,x3xn such that f(b1,b2,b3bn)=1 where b1= 0 or 1,b2= 0 or 1.. bn = 0 or 1 2n different permutations, someone out of that can give answer as 1 (true) guess ?f(1,0,1,0,0,1 ..,1,0) = 1 verify ( evaluate the function) ability to guess and verify in polynomial time
Copyright @ gdeepak.com 24

6/15/2012

COOK theorem
The complexity class P is contained in NP but the vice versa has not been proved and proving whether p= NP remains the biggest research question. Cook Formulated a question that is there any single problem in NP such that if we showed it to be in P, then that would imply P=NP

6/15/2012

Copyright @ gdeepak.com

25

reducibility
Given an instance x of a problem A, use a polynomial time reduction algorithm to transform it to instance y of problem B. Run the polynomial time algorithm for B on instance y use the answer for y as the answer for x.

6/15/2012

Copyright @ gdeepak.com

26

NP
These can do things in parallel as long as the resulting answers can be connected with OR and any one of them is the answer. Or in other words it can choose one of the possible choices at any point of time at the same time.

6/15/2012

Copyright @ gdeepak.com

27

3-SAT
(x+ + z) (x+ y + ) (p++) . . . Mth clause
N different variables being used in m set of clauses

Whether there is a way to assign truth values to different variables so that whole formula is true Total number of such possible assignments for n variables 2n So Total time will be 3m.2n This was the first problem to be proved NP-Complete

6/15/2012

Copyright @ gdeepak.com

28

NP version
For every possible set of assignment to n-variables it will check the truth value of the assignment. Either this or this or or that The solutions can be checked with a combination of Ors and one of them may be true if it has an assignment otherwise all will be false. Theoretically can be done with 2n Parallel processors in polynomial deterministic time. Non deterministic machine will take 3m. Well, if you are a good boy or GOD-boy and you can guess the things magically, then you can guess in the first go and truth value can be determined in polynomial time. But, we are yet to find such a BOY.

6/15/2012

Copyright @ gdeepak.com

29

SAT
(x) (x+ + z) (x+ ) (p+++t) . . . Mth clause
N different variables being used in m set of clauses A clause can contain any number of variable which was fixed to 3 in 3-SAT Whether there is a way to assign truth values to different variables so that whole formula is true Total number of such possible assignments for n variables 2n

6/15/2012

Copyright @ gdeepak.com

30

General SAT
SAT 3-SAT

Claim is that if you can solve 3-SAT you can solve any version. Any three variable clause will remain as it is (x+ + z) (x+ + z) (x+ ) (x+ +c) (x+ + ) (p+++t) (p++) ( ++t)
(p+ ++t + u+v) (p++1) (1 ++L2)(2 +t+L3)(3 +u+v)
6/15/2012 Copyright @ gdeepak.com 31

Solving 2-SAT
(x1 + x2) (x2 + x3) (x1 + x2) (x3 + x4) (x3 + x5) (x4 + x5) (x3 + x4). Number of variables n = 5 and number of clauses m = 7. (In general, m n.) Start by making x1 TRUE. This makes the clause (x1 + x2) TRUE; accordingly, this clause may be removed. Under this assignment, x2 must be TRUE (i.e., x2 must be FALSE) in order to satisfy the clause (x1 + x2). Making x2 FALSE satisfies the clause (x2 + x3) as well, leaving only the shorter formula and so on (x3 + x4) (x3 + x5) (x4 + x5) (x3 + x4)
6/15/2012 Copyright @ gdeepak.com 32

3-colorability SAT
Can you color a Graph in with 3 colors or Not. Let us say that 3 colors to be used are Red, Yellow and Green.
A B

For every node the logical relation has to be (AR + AG + AY ) Similar Relation will be formed for every node with 3 clauses
6/15/2012 Copyright @ gdeepak.com 33

3-colorability
6 logical relations has to be created using above rule AR AG G AY BR BG G BY Total 3n+6e clauses will be there in the corresponding 3-SAT relation where n is the number of nodes and e is the number of edges
Copyright @ gdeepak.com 34

6/15/2012

Reductions
SAT 3-SAT Means SAT is at least as hard as 3-SAT or if I can solve 3-SAT then I can solve SAT also. 2-colorability SAT (Useless Reduction) Theoretically it means that if I can solve SAT, I can also solve 2-colorability but that is already solved and is very easy using the bipartite graph. So we never reduce an easy problem to an hard problem. So we try to solve a problem for many days, if it cannot be solved in a polynomial time then we try to reduce it to some NP-complete problem and the iterating like this between the two stages.
6/15/2012 Copyright @ gdeepak.com 35

2-SAT Strongly Connected Components

We have the following 2-SAT relation (x+u) ( + y) ( +)

x
y u

We want to convert in a graph and want to say whether it is strongly connected or not. For the above formula to have a true assignment, one or more variable in each formula has to be true. If x is false then u has to be true and has to be false and so on.
6/15/2012 Copyright @ gdeepak.com 36

Strongly Connected Components


Each strongly connected components can be collapsed into one. If all the complements are in different connected components then 2-SAT has a true assignment.
M is NP-Complete if NP M and if M Q then Q is NPComplete. However if Q M that may not give us anything.

6/15/2012

Copyright @ gdeepak.com

37

Facts
There are many in NP which are not NP-Complete (All inside P are in NP). Are there any outside P which are NP but not NPcomplete. There are many problems for which neither there exists polynomial time solution and neither we are able to find any reduction to a NP-Complete Problem Factoring is exponential in size of number of digits and we dont know any polynomial time algorithm to it but we dont know reduction to any NP-Problem.
6/15/2012 Copyright @ gdeepak.com 38

XY then YX
Independent Set problem: largest set of nodes which are not connected to each other. Segment intersection: To find the number of lines that dont intersect with any other line. We claim that maximum number of lines that dont intersect with each other is same as maximum independent set.

c d

e
b d

b a
6/15/2012 Copyright @ gdeepak.com

39

All reductions are not easy


If we want to reduce independent set to segment intersection, it will be an exponential reduction.

6/15/2012

Copyright @ gdeepak.com

40

How to do reduction
Experience Feature extraction Familiarity with both the problems Boolean Algebra

6/15/2012

Copyright @ gdeepak.com

41

3-SAT Vertex Cover


Let us take a Boolean expression (x+ +) (+ y + z) It is satisfiable for x=T and y=T and z=F If k is the vertex cover, n is the number of variables and m is the number of clauses then k=n+2m So if k is the vertex cover as per the above formula then 3-SAT is satisfiable If formula is satisfiable then k=n+2m
6/15/2012 Copyright @ gdeepak.com 42

3-SAT Vertex Cover


On top we have no of variables and below no of clauses
x y z

6/15/2012

Copyright @ gdeepak.com

43

3-SAT Vertex Cover


Dotted is the vertex cover.
x y z

6/15/2012

Copyright @ gdeepak.com

44

3-SAT Vertex Cover


Because at least one vertex of the triangle was connected to the true assignment on the top. x=T, y=T, z=T is not an assignment (x+ +) (+ y + z) (+ +)

6/15/2012

Copyright @ gdeepak.com

45

3-SAT Vertex Cover


It does not satisfies our equation.
x y z

6/15/2012

Copyright @ gdeepak.com

46

NP- Complete
It needs to be in NP This problem is at least as hard as every other problem in NP

6/15/2012

Copyright @ gdeepak.com

47

Hamiltonian Circuit Problem


ABCDEFG are the nodes Guess: BDEFGCAB I can check whether these are connected in this manner in polynomial time, if all the edges exist I say , yes and if any edge is missing, I will say No and then make another guess. There are n! guesses No body knows any better algorithm

6/15/2012

Copyright @ gdeepak.com

48

Clique Problem
Given a graph and a number k. In this graph can you find k or more nodes which are all connected to each other. Or find the max clique of a graph If n is 3 or 4 then it is a polynomial algorithm, otherwise k can go to n.

6/15/2012

Copyright @ gdeepak.com

49

3D matching
M F Martian 100 100 100 We can have n3 combinations of preferences
Guess 100 triples

Take your guess, for ever triple check if it is there in the preferences then n*n3 How many guesses : exponential

6/15/2012

Copyright @ gdeepak.com

50

Reduction
Sorting Convex Hull Sorting reduces to convex Hull 8 3 17 Reduction 8,64 3,9 17, Solve convex hull Solution to convex hull after again converting back will be solution to your sorting Reduction should be easy, not the bottom neck of your algorithm and the weakest link of your chain Reductions in the case of NP-complete problems should be polynomial time reductions
6/15/2012 Copyright @ gdeepak.com 51

NP complete
If Problem is NP-hard and problem belongs to NP then it is NP-complete. Problems are designated "NP-complete" if their solutions can be quickly checked for correctness, and if the same solving algorithm used can solve all other NP problems. They are the most difficult problems in NP in the sense that a deterministic, polynomial-time solution to any NP-complete problem would provide a solution to every other problem in NP
6/15/2012 Copyright @ gdeepak.com 52

NP-Hard
Y is NP-Complete 1) Y belongs to NP 2) For any X belonging to NP X can be reduced in polynomial time to Y If we remove the first condition then it is NP-Hard Optimization version of the TSP where you say that find the optimal schedule instead of saying whether a Tour of less than K exists. All problems in Complexity classes above NP-Complete are sometime also called NP-hard because they are more harder then any hard problem in NP.
6/15/2012 Copyright @ gdeepak.com 53

Conclusion
So we are able to correlate one problem which is NP hard with the another problem which is also NP hard and so we can say that if one of them can be solved in polynomial time then another can also be solved in polynomial time. Similarly it can be proved for all problems in NP. But the problem is that we dont have any polynomial solution for any of the problems in NP included both discussed. And also there is almost no hope. Only thing we can say here is that it has not been proved that P=NP and neither it has been proved that P<> NP so that can give us a little hope to work on and on.
6/15/2012 Copyright @ gdeepak.com 54

Questions, Comments and Suggestions

6/15/2012

Copyright @ gdeepak.com

55

Question 1
Hamiltonian path problem for undirected graphs is in P A) True B) False

6/15/2012

Copyright @ gdeepak.com

56

Question 2
What would prove that X is NP-hard? (A) Showing a polynomial-time reduction from 3-Sat to X (B) Showing a polynomial-time reduction from X to 3-Sat (C) Either of the above (D) None of the above

6/15/2012

Copyright @ gdeepak.com

57

Question 3
3-SAT is A) P B) NP C) NP Complete D) NP Hard

6/15/2012

Copyright @ gdeepak.com

58

Vous aimerez peut-être aussi