Instance: - Problem:: A Formula To Decide If Is Satisfiable
Instance: - Problem:: A Formula To Decide If Is Satisfiable
(¬x∨y)∧(¬y∨z)∧(x∨¬z)∧(z∨y)
(¬x∨y)∧(¬y∨z)∧(x∨¬z)∧(z∨y)
Complexity 1
©D.Moshkovits
PAP 184-185
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…
Complexity 2
©D.Moshkovits
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).
Complexity 3
©D.Moshkovits
Graph Construction
• Vertex for each variable and a
negation of a variable
• Edge (α,β) iff there exists a clause
equivalent to (¬α∨β)
Complexity 4
©D.Moshkovits
Graph Construction: Example
(¬x∨y)∧(¬y∨z)∧(x∨¬z)∧(z∨y)
(¬x∨y)∧(¬y∨z)∧(x∨¬z)∧(z∨y)
¬x
y
x
¬y
¬z
z
Complexity 5
©D.Moshkovits
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 (¬β,¬α).
Complexity 6
©D.Moshkovits
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
Complexity 7
©D.Moshkovits
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):
(¬α∨β) is false!
x α . . .β ¬x
T T F F
Complexity 8
©D.Moshkovits
Correctness (2)
• Suppose there are no such paths.
• Construct an assignment as follows:
¬x 2. assign T to
1. pick an all reachable
unassigned y vertices
vertex and x
assign it T 3. assign F to
their negations
¬y
¬z 4. Repeat until all
z vertices are assigned
Complexity 9
©D.Moshkovits
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.
Complexity 10
©D.Moshkovits
Correctness
A formula is unsatisfiable iff there are
no paths of the form x..¬x and ¬x..x.
Complexity 11
©D.Moshkovits
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.
Complexity 12
©D.Moshkovits