Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CSC 455/CS 555, Assignment 4

Answers

The main focus of the complexity part is problems that are likely not to have feasible algorithms (N P -
complete problems). Nonetheless, the core of the N P -completeness is actually based on feasible algorithms
(aka Turing machines running in deterministic polynomial time), for indeed they are the basis of polyno-
mial reductions. This assignment gives you the opportunity to play with algorithms.

1. Explain why a clause with two literals ( x ∨ y) is logically equivalent with two implications, namely
x → y and y → x.

A NSWER :

We have x → y = x ∨ y = x ∨ y (given that a → b = a ∨ b and by the elimination of double negation).


Similarly y → x = y ∨ x = y ∨ x = x ∨ y.
It follows that any instance of 2-SAT can be written in implicative normal form that is, as a conjunction
of simple implications (of form a → b).

2. Given an instance F of 2-SAT we construct the following directed graph: The vertices of the graph are
exactly all the literals from F, and there exists an edge ( a, b) iff a → b can be inferred from F based on
the equivalence established in Question 1. Show that such a graph can be constructed in polynomial
time starting from F.

A NSWER :

Let | F | denote the length of F (i.e., the number of symbols in F). Clearly there are less than | F | distinct
literals l1 , l2 , . . . , ln in F. The following algorithm will construct the desired graph, which will be
denoted by G ( F ) henceforth:
(a) Convert F to its implicative normal form F ′ using the equivalence from Question 1.
This step takes O(2| F |) = O(| F |) steps (since there are two y → x formulae for each clause in
F and there are less than | F | such clauses). Moreover we have | F ′ | ≤ O(2| F |) = O(| F |) (same
argument).
(b) Start with an empty graph G ( F ).
(c) For each pair (l, l ′ ) ∈ {l1 , l2 , . . . , ln }2 add the edge (l, l ′ ) to G ( F ) iff l → l ′ is a clause in F ′ .
There are O(| F |2 ) pairs (l, l ′ ) and O(2| F |) implications x → y in F ′ (to check against (l, l ′ )), so
this step requires O(| F |3 ) steps.
The algorithm follows the definition so it is obviously correct. It takes O(| F |) + O(| F |3 ) = O(| F |3 )
time and so is polynomial time, as desired.

1
3. Show that a 2-SAT instance F is unsatisfiable iff there exists a variable x such that there exists a path
from x to x and also a path from x to x in the associated graph as constructed in Question 2.

A NSWER :

Note first that → is transitive and the existence of a path ( a1 , a2 , . . . , ak ) in G ( F ) means that the
following implication chain can be inferred from F: a1 → a2 → · · · → ak . Therefore:

( a1 , a2 , . . . , ak ) is a path in G ( F ) iff a1 → ak according to F (1)

If : Let F be some unsatisfiable formula, and assume that there is no path from x to x for any literal x
such that there exists a path from x to x in G ( F ). Then the truth assignment that makes x false (and so
x true) will satisfy x → x (by Relation (1)). We now repeat such a truth assignment for all paths from
x to x. This assignment will not make any implication in F false, for indeed we assumed that no path
from x to x exists. Now take all the other paths, and assign truth values that make the corresponding
implications true. Such an interpretation makes F true, since there are no cycles that contain both x
and x. F is therefore satisfiable, a contradiction.
Only if : The path from x to x in G ( F ) means that x → x in F by Relation (1). Similarly we have x → x
in F so overall ( x → x) ∧ ( x → x). This formula is unsatisfiable, and therefore so is F, as desired.
Indeed, ( x → x) ∧ ( x → x) = ( x ∨ x) ∧ ( x ∨ x) = x ∧ x = False.

4. Based on your findings from Question 3 show that 2-SAT ∈ P .

A NSWER :

The following algorithm will solve 2-SAT in polynomial time:


(a) Set satisfiable to True.
(b) Construct the graph G ( F ) corresponding to the given formula F as in Question 2.
This step takes O(| F |3 ) time (see Question 2).
(c) For each literal l from F:
• Determine whether there is a path from l to l and from l to l. If this is the case then set
satisfiable to False.
Each of these two reachability problems can be solved using some state-space search algo-
rithm (such as backtracking) in time linear in the number of nodes in G ( F ). On the other
hand, the number of nodes in G ( F ) is O(2| F |) = O(| F |) and so this step takes O(| F |) time.
The whole loop takes O(| F |) × O(| F |) = O(| F |2 ) time.
(d) Report that F is satisfiable iff satisfiable = True.
That the algorithm solves 2-SAT follows immediately from Question 3. The time complexity is
O(| F |3 ) + O(| F |2 ) = O(| F |3 ) and so polynomial. Therefore 2-SAT ∈ P .

You might also like