Presentation on theme: "NP and NP Complete. Definitions A problem is in the class P if there is a polynomial time solution to the problem A problem is in the class NP if there."— Presentation transcript:
Definitions A problem is in the class P if there is a polynomial time solution to the problem A problem is in the class NP if there is a non- deterministic polynomial time solution to the problem –Essentially, given a solution, can you determine if it works in polynomial time A problem is in the class NP-Hard if every problem in NP reduces to it –What does it mean for one problem to reduce to another? A problem is in the class NP-Complete if it is both NP and NP-Hard
Cook's Theorem SAT is NP-Complete –Clearly in NP SAT – Given a boolean expression, it is satisfiable if there exists an assignment of 0s and 1s to its variables such that the expression evaluates to 1 –(x|y)&(x|y) –(x|y)&(!x|y)&(!y)
Cook's Theorem SAT is NP-Complete –Clearly in NP SAT – Given a boolean expression, it is satisfiable if there exists an assignment of 0s and 1s to its variables such that the expression evaluates to 1 –(x|y)&(x|y) – x=T y=T or x=T y=F or x=F y=T –(x|y)&(!x|y)&(!y) – ???
Clique Given an undirected graph G=(V, E) and an integer k, determine whether G contains a clique of size >=k. –Clique – a subgraph such that all vertices are connected to all other vertices Clique is in NP – given a subset of >= k vertices, easy to determine if subset represents a clique
Reduce SAT to Clique Show how to create an instance of Clique to represent any SAT problem –if you can solve the Clique problem, you can solve SAT Given an expression in conjunctive normal form, create a column of vertices for each clause Connect each vertex to all other vertices that are not in same column and are not the complement
Example (Manber text) E=(x|y|!z)&(!x|!y|z)&(y|!z) x y !z !x !y z y !z Choose k as m (number of clauses) If clique of size k, it must contain one vertex from every column since vertices in a column do not connect Assign value of 1 to each variable represented by vertex in clique(x and !x not connected) – solution to SAT!
TSP Hamiltonian Cycle (HAM) –Find a simple cycle, in an undirected graph, that visits every vertex. TSP –Given a complete graph G=(V, E), with edge costs, and an integer K, is there a simple cycle that visits all vertices and has total cost <= K?
TSP NP – Given a simple cycle, in polynomial time can check if it contains all vertices and has cost <= K. Reduce HAM to TSP –solve HAM using a solution to TSP –create an instance of TSP to represent any HAM
TSP – NP-Complete Determine if Hamiltonian Cycle exists for G. Create complete graph G' that has same vertices as in G. Edge has weight 1 if it is in G and 2 otherwise. Solve TSP on G' with K = number of vertices. TSP tour that visits all vertices will contain each vertex 1 time and will use only edges of weight 1