TDDD65 Problem Session 2

Linköpings Tekniska Högskola
Institutionen för Datavetenskap
Gustav Nordh
TDDD65 Problem Session 2
1. Show that the class of context-free languages is closed under union, concatenation, and *
(Kleene star).
2. Consider the language L = {aq | q is a prime number} and the following proposed
(incorrect) proof trying to show that L is not regular.
Assume that L is regular. Then the pumping lemma must hold and there exists a
constant p as stipulated by the pumping lemma. Consider the string s = aq where q is the
first prime number larger than p + 2. According to the pumping lemma s can be split into
xyz such that for each i ≥ 0, xy i z ∈ L, |y| > 0, and |xy| ≤ p. Choose x = ε, y = a, and
z = aq−1 . Now consider the string xy 2 z which according to the pumping lemma must be in
L. By our choice of xyz we have that xy 2 z = aq+1 which is not in L since q + 1 is an even
number larger than 2 (and thus not a prime). Hence our assumption that L is regular was
wrong and we conclude that L is not regular.
(a) Point out the error(s) in the proposed (incorrect) proof above.
(b) Correct the proposed proof and show that L is not regular.
3. For each of the languages described by the following regular expressions over Σ = {0, 1} give
a CFG (context-free grammar) generating the language.
(a) 0*1*
(b) 0(10)*1
(c) 0*+1*
(d) (000)*
(e) (0+1)*0(0+1)*1(0+1)*0(0+1)*
(f) ((11)*0)*
4. (a) Give a CFG G that generates the language
L = {ai bj ck | i = j or j = k where i, j, k ≥ 0}
(b) Show a left-most derivation of the string aabbcc.
(c) Is G ambiguous? (Try to justify your answer.)
5. A palindrome is a string that reads the same forward and backward, e.g., the string abba.
Describe a PDA recognizing the language of all palindromes over the alphabet {a, b}.
6. Show that the class of decidable languages is closed under complement.
7. Prove that the following languages are not regular.
(a) {0n 1m 0n | m, n ≥ 0}
(b) {0m 1n | m 6= n}
(c) {wtw | w, t ∈ {0, 1}∗ , w 6= ε, t 6= ε}