You are on page 1of 1

Solving 2SAT

A 2SAT instan e is an instan e of Satis ability in whi h ea h lause ontains


two literals. We present a polynomial time algorithm whi h redu es a 2SAT
instan e to the problem of nding the strong omponents of a digraph ( see
page 1082 of Cormen for a de nition).
If the 2SAT instan e I is over variables x1 ; ::; xn then the graph GI we
onsider has vertex set fx1 ; ::; xn ; x1 ; :::; xn g. Ea h lause A or B orresponds
to two edges of GI , one from A to B ,the other from B to A. Thus if I has m
lauses there are exa tly 2m edges in GI .
Note that if AB is an edge then in any satisfying truth assignment for whi h
A is true, B must also be true (sin e the lause orresponding to the edge must
be satis ed). It follows by indu tion that if there is a (dire ted) path P from
A to B then in any satisfying truth assignment if A is true then so is B . Now,
we annot set both xi and xi to true, in a satisfying truth assignment. Thus, if
there is a dire ted path from xi to xi , xi must be false in any satisfying truth
assignment. Similarily, if there is a dire ted path from xi to xi then xi must be
true in any satisfying truth assignment. Thus, if for some i, xi and xi are in
the same strong omponent then there is no satisfying truth assignment.
We now show that if there is no su h i, then there is a satisfying truth
assignment. To begin, we note that if AB is an edge of GI then so is BA.
Applying this fa t to all the edges of a path, we see that there is a path from
A to B in GI pre isely if there is a path from B to A in GI . Symmetri ally,
there is a path from B to A in GI pre isely if there is a path from A to B in
GI . Thus, A and B are in the same strong omponent of GI , pre isely if A and
B are.
So, assuming there is no strong omponent ontaining both a variable and
its negation, we an pair the strong omponents as U; U su h that the literals
appearing in U are pre isely the negations of the literals appearing in U .
We take a topologi al sort of the a y li al omponent graph of G (see Figure
22.9 of Cormen), and set the variables in U to be true if U appears after U in
this order and false otherwise. To show this assigment is satisfying it is enough
to show that there is no edge AB with A true and B false (sin e the edges
orresponding to an unsatis ed lause have this form). Assume the ontrary
and let U be the rst omponent of the strong omponent graph whi h ontains
an endpoint of su h an edge. Let vw be an edge with v true, w false and one
of v or w in U . Note that one of v or w is not in U , be ause all of the literals
in U re eived the same truth value. By our hoi e of U , the vertex in the edge
whi h is not in U is in a omponent appearing after U in the topologi al sort
and hen e v 2 U . Sin e v is true, this means that U appears before U in our
topologi al sort. But wu is also an edge from a true vertex to a false vertex.
This edge ontains a vertex of U , ontradi ting our hoi e of U .
So, to solve 2SAT, we need only nd the strong omponents of a digraph.
In the next lass, we present a linear time algorithm for this problem.
1

You might also like