Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complexity ©D.Moshkovits 1 2-Satisfiability NOTE: These slides were created by Muli Safra, from OPICS/sat/)

Similar presentations


Presentation on theme: "Complexity ©D.Moshkovits 1 2-Satisfiability NOTE: These slides were created by Muli Safra, from OPICS/sat/)"— Presentation transcript:

1 Complexity ©D.Moshkovits 1 2-Satisfiability NOTE: These slides were created by Muli Safra, from http://cs.umd.edu/~gasarch/T OPICS/sat/)

2 Complexity ©D.Moshkovits 2 2SAT Instance: A 2-CNF formula  Problem: To decide if  is satisfiable (  x  y)  (  y  z)  (x  z)  (z  y) Example: a 2CNF formula

3 Complexity ©D.Moshkovits 3 2SAT is in P Theorem: 2SAT is polynomial-time decidable. Proof: We’ll show how to solve this problem efficiently using path searches in graphs… PAP 184-185

4 Complexity ©D.Moshkovits 4 Searching in Graphs Theorem: Given a graph G=(V,E) and two vertices s,t  V, finding if there is a path from s to t in G is polynomial- time decidable. Proof: Use some search algorithm (DFS/BFS).

5 Complexity ©D.Moshkovits 5 Directed Graph Construction Vertex for each variable and a negation of a variable Directed Edge ( ,  ) iff there exists a clause equivalent to (  )

6 Complexity ©D.Moshkovits 6 Graph Construction: Example xx y x zz z (  x  y)  (  y  z)  (x  z)  (z  y) yy

7 Complexity ©D.Moshkovits 7 Observation Claim: If the graph contains a path from  to , it also contains a path from  to . Proof: If there’s an edge ( ,  ), then there’s also an edge ( ,  ).

8 Complexity ©D.Moshkovits 8 Correctness Claim: a 2-CNF formula  is unsatisfiable iff there exists a variable x, such that: 1.there is a path from x to  x in the graph 2.there is a path from  x to x in the graph

9 Complexity ©D.Moshkovits 9 Correctness (1) Suppose there are paths x..  x and  x..x for some variable x, but there’s also a satisfying assignment . If  (x)=T (similarly for  (x)=F): TF xx x...   TF (  ) is false!

10 Complexity ©D.Moshkovits 10 Correctness (2) Suppose there are no such paths. Construct an assignment as follows: xx y x zz z yy x 1. pick an unassigned literal , with no path from  to , and assign it T y z 2. assign T to all reachable vertices 3. assign F to their negations xx yy zz 4. Repeat until all vertices are assigned

11 Complexity ©D.Moshkovits 11 Correctness (2) Claim: The algorithm is well defined. Proof: If there were a path from x to both y and  y, then there would have been a path from x to  y and from  y to  x.

12 Complexity ©D.Moshkovits 12 Correctness A formula is satisfiable iff there are no paths of the form x..  x and  x..x.

13 Complexity ©D.Moshkovits 13 2SAT is in P We get the following efficient algorithm for 2SAT: –For each variable x find if there is a path from x to  x and vice-versa. –Reject if any of these tests succeeded. –Accept otherwise  2SAT  P.

14 Complexity ©D.Moshkovits 14 Summary We’ve seen that checking if a given CNF formula is satisfiable is solvable in polynomial-time, if every clause contains up to 2 literals. (In other words, 2-SAT is in P.) However, if each clause can contain 3 or more literals, then the problem is NP- hard!. (In other words, 3-SAT is NP-hard.) 


Download ppt "Complexity ©D.Moshkovits 1 2-Satisfiability NOTE: These slides were created by Muli Safra, from OPICS/sat/)"

Similar presentations


Ads by Google