Download presentation
Presentation is loading. Please wait.
Published byGeorgia Patrick Modified over 8 years ago
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 xx y x zz z ( x y) ( y z) (x z) (z y) yy
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 xx x... TF ( ) is false!
10
Complexity ©D.Moshkovits 10 Correctness (2) Suppose there are no such paths. Construct an assignment as follows: xx y x zz z yy 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 xx yy zz 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.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.