Professional Documents
Culture Documents
Formal Languages and Automata Homework 4
Formal Languages and Automata Homework 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 :
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:
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.
A NSWER :