• Please give details of your calculation. A direct answer without explanation is not counted.
• Your answers must be in English.
• Please carefully read problem statements.
• During the exam you are not allowed to borrow others’ class notes.
• Try to work on easier questions first.
Problem 1 (20 pts)
We say w1 is w2’s subsequence if we can obtain w1 by removing some symbols in w2. For example, ad is a subsequence of abcdc by removing the second, the third, and the fifth symbols.
As a result, is a subsequence of any string. Is
A = {hC, wi | C is a CFG which can generate at least one subsequence of wk for some k}
Turing decidable?
If you use any lemma which is not taught in the class, even if it is in the textbook, you need to prove it. This problem can be solved without using any lemma which is not taught.
Answer
Yes, this language is decidable. Assuming w = w1w2· · ·wn, where wi ∈ Σ, ∀i = 1 . . . n, we denote S ≡ {subsequences of wk for some k} and T ≡ {w1, w2, · · · , wn}∗. Now we show S = T . Trivially, S ⊂ T . Besides, for any string w0 ∈ T , w0 is a subsequence of w|w0| because we can obtain w0 by removing all symbols excepts (w0)i in the i-th w of w|w0|. Therefore, T ⊂ S. The following Turning Machine decides language A by check if C can accept any string in T .
1. Mark all terminals in {w1, w2, . . . , wn}.
2. Repeat until no new variables get marked:
• Mark any variable V where C has a rule V → U1U2· · ·Uk and each symbol U1, . . . , Uk has already been marked.
3. If the start variable is not marked, reject; otherwise, accept.
1
Problem 2 (20 pts)
Assume
f1(n) = O(2n) and f2(n) = O(3n).
Is
f1(n) + f2(n) = O(3n)?
You need to formally prove your answer. You get 0 point if only answering yes/no.
Answer
Yes. Since f1(n) = O(2n) and f2(n) = O(3n), there exists positive numbers c1, c2, n1, n2, such that
f1(n) ≤ c12n, ∀n > n1, and (1)
f2(n) ≤ c23n, ∀n > n2. (2)
Take n0 = max(n1, n2) and c = c1+ c2, then for all n > n0,
f1(n) + f2(n) < c12n+ c23n≤ (c1+ c2)3n. So we have f1(n) + f2(n) = O(3n).
Common mistakes
1. You cannot give c1, n1, c2, n2 in (1) and (2).
2. You cannot say what f1(n) and f2(n) are. For example, you cannot say that f1(n) = 2n.
Problem 3 (30 pts)
Assume
f1(n) = O(2n) and f2(n) = o(3n).
Is
f1(n) + f2(n) = o(3n)?
You need to formally prove your answer. You get 0 point if only answering yes/no.
2
Answer
Yes. Since f1(n) = O(2n), there exists c1, n1 such that f1(n) ≤ c12n, ∀n > n1. Then
n→∞lim
f1(n) + f2(n) 3n
≤ lim
n→∞
c12n+ f2(n) 3n
= 0 + 0 = 0.
Therefore, f1(n) + f2(n) = o(3n).
Problem 4 (20 pts)
Prove whether the following two statements are true or false (a) If A and B are countable, then A ∪ B is also countable
(b) All irrational numbers are not countable. (hint: use the first part of this question)
Answer
(a) Assuming A = {a1, a2, a3, . . . } and B = {b1, b2, b3, . . . }, then A ∪ B = {a1, b1, a2, b2, . . . } is also countable. And because A ∩ B may not be empty set, we have to skip the elements that have been counted before.
(b) We prove by contradiction. If irrational numbers are countable. Then the union of irra- tional numbers and rational numbers is also a countable set because rational numbers are countable. However, the union is real number, so it is a contradiction.
Common Mistakes
If you world like to use diagonalization method, you must be able to argue that the obtained number is irrational. Note that a rational number may have infinitely many digits.
Problem 5 (5 pts or -10 pts)
In Chapter Seven (or in the lecture last week) we mentioned one of the greatest unsolved computer science problem. What is it?
If you correctly answer this question, you get 5 points. Otherwise, you get −10.
3
Answer
NP = P or NP 6= P.
Problem 6 (5 or 25 pts)
(a) (5 pts) Calculate 48, 023 × 89, 363
(b) (Bonus 20 pts) Find 512, 973, 211 = p × q, where p, q > 1 and p, q ∈ N.
Answer
(a) 48, 023 × 89, 363 = 4, 291, 479, 349.
(b) 512, 973, 211 = 9, 133 × 56, 167.
4