TDDD65 Example Exam 1

advertisement
2012-09-28
Linköpings Tekniska Högskola
Institutionen för Datavetenskap
Gustav Nordh
TDDD65 Example Exam 1
Outline of the proposed solutions for selected problems.
1.
(3 p)
(a) Everything that can be computed can be computed by a Turing machine.
(1)
(b) No solution given.
(2)
2.
(6 p)
(a) (0 + 1)∗ (00 + 11)
(2)
(b)
(2)
q
0, 1
1
1
p
r
0
0
s
0
(c)
0
{p, s}
{p, r, s}
0
1
1
{p}
1
0
1
0
{p, q}
1
1
{p, q, r}
(2)
3.
(5 p)
(a) S → S1 | S2
S1 → AB
S2 → aS2 d | aCd
C → bCc | bc
A → aAb | ab
B → cBd | cd
(4)
(b) The string abcd has two different left-most derivations:
S ⇒ S1 ⇒ AB ⇒ abB ⇒ abcd
S ⇒ S2 ⇒ aCd ⇒ abcd
and hence the grammar is ambiguous.
(1)
4. Assume that L is regular and consider the string s = 0p 1p ∈ L, where p is the pump length
given by the pumping lemma. The pumping lemma says that there is a partition of s into
xyz such that |xy| ≤ p, |y| > 0, and xy i z ∈ L for all i ≥ 0. In any such partition of s we must
have that y is a nonempty string of 0’s (since s starts with p 0’s, |xy| ≤ p, and |y| > 0. Hence,
taking i = 2 we see that #0(xy 2 z) > #1(xy 2 z) and thus xy 2 z ∈
/ L. We have a contradiction
with the pumping lemma and L is not regular.
(4 p)
5. The fact that A is the union of two regular languages implies that A is regular, and hence
decidable. The reduction F ≤m A implies that F is decidable (since it is mapping reducible
to a decidable language).
(3 p)
Since B is not Turing recognizable and B ≤m D, we know that D is not Turing recognizable
(and hence not decidable).
The reductions E ≤m C and A ≤m E does not tell us anything about the decidability of E
(although the reduction E ≤m C tells us that E is Turing recognizable).
In summary: we can conclude that D is undecidable and that F is decidable, but we cannot
conclude whether or not E is decidable.
6.
(5 p)
(a) MONOTONE-SAT is in NP since the correctness of solutions can be verified in polynomial time by checking that each clause is satisfied by the solution.
(1)
(b) Given a 3SAT instance ϕ with variables x1 , . . . , xn and clauses C1 , . . . , Cm we reduce
it to a MONOTONE-SAT instance ϕ′ with variables x1 , . . . , xn , y1 , . . . , ym and clauses
′
C1′ , . . . , Cm
, D1 , . . . , D2n .
(4)
The D clauses are D2i = (xi ∨ yi ), D2i−1 = (xi ∨ yi ) (1 ≤ i ≤ n). This forces xi
and yi to take different values in any solution (i.e., we cannot have a solution where
xi = 0 and yi = 0, or xi = 1 and yi = 1). The C ′ clauses corresponds to the C clauses
in the 3SAT instance. Given a clause Cj , the clause Cj′ is constructed by replacing
each negative literal xi in Cj by yi and keeping all positive literals. So, for example, if
Cj = (x1 ∨ x2 ∨ x4 ), then Cj′ = (y1 ∨ y2 ∨ x4 ).
It is clear that ϕ′ is a MONOTONE-SAT instance. Moreover, ϕ is satisfiable by an
assignment α if and only if ϕ′ is satisfiable by a an assignment α′ , where α′ (xi ) = α(xi )
and α′ (yi ) = α(xi ). Hence, the reduction described above is a mapping reduction from
3SAT to MONOTONE-SAT.
The reduction can clearly be carried out in polynomial time and we conclude that
MONOTONE-SAT is NP-complete.
2
7. TRIANGLE: There are n(n − 1)(n − 2)/6 distinct sets of 3 vertices. If we assume that
the graph is represented in such a way that the existence of an edge can be checked
in constant time, then checking whether 3 vertices form a triangle can be done in time
O(1) + O(1) + O(1) = O(1). So the algorithm runs in polynomial time, more precisely, in
time n(n − 1)(n − 2)/6(O(1) + O(1) + O(1)) = O(n3 ).
3COL: There are 3n possible assignments of 3 colors to the n vertices in the graph.
Checking whether an assignment of colors is a proper 3 coloring can definitely be done
in time O(n2 ). So the running time of the algorithm is O(3n n2 ) (or O(3n ) if we ignore
polynomial factors) which is exponential.
3
(4 p)
Download