In the 2SAT problem, you are given a set of clauses, where each clause is the disjunction (OR) of
two literals (a literal is a Boolean variable or the negation of a Boolean variable). You are looking
for a way to assign a value true or false to each of the variables so that all clauses are
satisfied — that is, there is at least one true literal in each clause. For example, here’s an instance of 2SAT:
(x1∨¯x2)∧(¯x1∨¯x3)∧(x1∨x2)∧(¯x3∨x4)∧(¯x1∨x4).
This instance has a satisfying assignment: set x1, x2, x3, and x4 to true, false, false, and
true, respectively.
Are there other satisfying truth assignments of this 2SAT formula? If so, find them all.
Give an instance of 2SAT with four variables, and with no satisfying assignment.
The purpose of this problem is to lead you to a way of solving 2SAT efficiently by reducing it to
the problem of finding the strongly connected components of a directed graph. Given an instance
I of 2SAT with n variables and m clauses, construct a directed graph GI=(V,E) as follows.
GI has 2n nodes, one for each variable and its negation.
GI has 2m edges: for each clause (α∨β) of I (where α,β are literals), GI has an edge from
the negation of α to β, and one from the negation of β to α.
Note that the clause (α∨β) is equivalent to either of the implications ¯α⇒β or
¯β⇒α. In this
sense, GI records all implications in I.
Carry out this construction for the instance of 2SAT given above, and for the instance you
constructed in 2.
Show that if GI has a strongly connected component containing both x and ¯x for some
variable x, then I has no satisfying assignment.
Now show the converse of 4: namely, that if none of GI’s strongly connected components
contain both a literal and its negation, then the instance I must be satisfiable. (Hint:
Assign values to the variables as follows: repeatedly pick a sink strongly connected component
of GI. Assign value true to all literals in the sink, assign false to their negations, and
delete all of these. Show that this ends up discovering a satisfying assignment.)
Conclude that there is a linear-time algorithm for solving 2SAT.
Given: A positive integer k≤20 and k 2SAT formulas represented as follows. The first line gives the number of variables
n≤103 and the number of clauses m≤104, each of the following m lines gives a clause of length 2 by specifying
two different
literals: e.g., a clause (x3∨¯x5) is given by 3 -5.
Return: For each formula, output 0 if it cannot be satisfied or 1 followed by a satisfying assignment otherwise.