Tutorial 4
Tutorial 4
E →E+T |T
T →T ×F |F
F → (E) | a
• a • a+a
• a+a+a • ((a))
Exercise 2 We admit the following result: ”The class of context-free language is not closed under
intersection”. Use DeMorgan’s law to show that the class of context-free languages is not closed
under complementation.
De Morgan’s Laws:
De Morgan’s Laws describe the relationship between set union (∪), set intersection (∩), and
set complement. They can be stated as follows:
R → XRX | S
S → aT b | bT a
T → XT X|X|ε
X→a|b
Exercise 4 Give context-free grammars that generate the following languages. In all parts, the
alphabet Σ is {0, 1}.
1
a. {w | w contains at least three 1 s }
g. The set of strings over the alphabet | {a, b} with more a’s than b’s
j. {x1 #x2 # · · · #xk | k ≥ 1, each xi ∈ {a, b}∗ , and for some i and j, xi = xR
j
Exercise 5 • Give informal descriptions and state diagrams of pushdown automata for the
languages in Exercise 4 (a-f ).
• Give informal English descriptions of PDAs for the languages in Exercise 4(g-j)
A = ai bj ck | i = j or j = k where i, j, k ≥ 0 .
Exercise 7 Give an informal description of a pushdown automaton that recognizes the language
A in Exercise 6
Exercise 10 Convert the following CFG into an equivalent CFG in Chomsky normal form.
A → BAB|B|ε
B → 00 | ε
Exercise 11 Give a counter-example to show that the following construction fails to prove that
the class of context-free languages is closed under star. Let A be a CFL generated by the CFG
G = (V, Σ, R, S). Add the new rule S → SS and call the resulting grammar G′ . This grammar is
supposed to generate A∗ .
2
Exercise 12 Show that the class of context-free languages is closed under the regular operations,
union, concatenation, and star.
Exercise 13 Use the results of Exercise 12 to give another proof that every regular language is
context free, by showing how to convert a regular expression directly to an equivalent context-free
grammar.
Exercise 14 We admits the following result: ”The language {an bn cn | n ≥ 0} is not context-free”.
a. Let C be a context-free language and R be a regular language. Prove that the language C ∩ R
is context free.
b. Let A = {w | w ∈ {a, b, c}∗ and w contains equal numbers of a’s, b’s, and c’s }. Use part
(a) to show that A is not a CFL.
S → aS b| bY |Y a
Y → bY |aY |ε
Give a simple description of L(G) in English. Use that description to give a CFG for L(G), the
complement of L(G).
Exercise 16 Let A/B = {w | wx ∈ A for some x ∈ B}. Show that if A is context free and B is
regular, then A/B is context free.
Exercise 17 • Let Σ = {a, b}. Give a CFG generating the language of strings with twice as
many a’s as b’s. Prove that your grammar is correct.
• Let C = {x#y | x, y ∈ {0, 1}∗ and x ̸= y}. Show that C is a context-free language.