Solutions to Exam 2
Exam 2 (Thursday, November 14, 2024)
Exam 2 (Thursday, November 14, 2024)
- Write a CFG for the language L = { wan | w is a word in {a,b}* and n = length(w) }
S -> aSa S -> bSa S -> ε
- Construct an nPDA for L = { anbm | n ≤ m ≤ 3n }
S -> aSb S -> aSbb S -> aSbbb S -> ε
- Construct a CFG and a dPDA for the language
L = { ambnap | n = 3m + 4p, m ≥ 1, n ≥ 1, p ≥ 1 |
S -> XY X -> aXbbb X -> abbb Y -> bbbbYa Y -> bbbba
We assume there are an infinite number of $ symbols at the bottom of the stack! i.e. once you pop a $ you will see another $ under it (-: - Precisely state the Pumping Lemma for context-free languages.
For all context-free languages L,
There exists a constant N such that
For all w in L with |w| ≥ N,
There exists u, v, x, y, and z such that w = uvxyz, |vxy| ≤ N and |vy| ≥ 1, and
For all i ≥0, uvixyiz is in L.
- Consider the CFG for EQUAL:
S -> aB S -> bA A -> aS A -> bAA A -> a B -> bS B -> aBB B -> b
- Show the parse tree for w = abaabb.
Pick the top two repeating B's in a path from root to leaf, and separate w into 5 parts
u, v, x, y, and z as the Pumping Lemma suggests. Show the dotted lines which separate
w into five parts.
- Modify the parse tree of part a by replacing the lower B's sub-tree with
the upper B's subtree. This will result in v and y repeating twice. Show the dotted lines
which separate the leaves into the seven parts: u,v,v,x,y,y,z.
- Show the parse tree for w = abaabb.
Pick the top two repeating B's in a path from root to leaf, and separate w into 5 parts
u, v, x, y, and z as the Pumping Lemma suggests. Show the dotted lines which separate
w into five parts.
- Are the following languages over the alphabet {a,b} context-free? Explain.
- L(a(a+b)*) ∩ ODDPALINDROME
Yes, because intersection of a regular language and a context-free language is context-free.
- { w | w is not in EVENEVEN }
Yes, because regular languages are closed under complementation, and every regular language is context-free.
- EQUAL ∪ EVENEVEN
Yes, because EQUAL is context-free, EVENEVEN is regular and therefore context-free, and context-free languages are closed under union.
- EQUAL ∩ {anbnan | n ≥ 1 }
Yes, because this language is empty and every empty language is regular and therefore context-free.
Note: ODDPALINDROME is the set of palindromes with odd length, EVENEVEN is the set of words with even number of a's and even number of b's, and EQUAL is the set of words with equal number of a;s and b's.
- L(a(a+b)*) ∩ ODDPALINDROME