Question text is in black, solutions in blue.
Q1: 10 points Q2: 10 points Q3: 10 points Q4: 10 points Q5: 35+10 points Q6: 20 points (note the exam paper said "30" here) Q7: 30 points Total: 125+10 points
Several questions refer to the following PDA called P. P has state set {q0, q, f}, start state q0, final state set {f}, input alphabet {a, b}, and stack alphabet {$, c}. It has six transitions: (q0, ε, ε; q, $), (q, a, ε; q, c), (q, b, ε; q, c), (q, a, c; q, ε), (q, b, c; q, ε), and (q, ε, $; f, ε). (Remember that a transition (p, a, b; q, c) means that the machine may go from state p to state q reading a from the input, popping b, and then pushing c.)
The grammar G is given by the rule set S --> SS | aSa | aSb | bSa | bSb | ε. It was defined on the test paper but was left off of this page until I discovered the error in February 2011. (DAMB)
FALSE. Every string in P(D) has even length. Because of the $ symbol, P can only accept with an empty stack. Every move from state q either reads and pops or reads and pushes, in each case exactly one letter. The number of pushes must equal the number of pops to get an empty stack, and so the number of reads is twice this number, which is even.
TRUE. There are several ways to accept an arbitrary even-length string with P. If the length of w is 2k, you could read the first k letters pushing a c each time, then read the last k letters popping a c each time. Or you could push while reading every odd-numbered letter and pop while reading every even-numbered letter.
FALSE. This statement is somewhat similar to the Regular Language Pumping Lemma but actually says something different and quite ridiculous. The RLPL says that every pumped string xyiz is in L, but this says that every string in L is a pumped string. If you read the statement clearly, it is easy to find a counterexample. Let L be Σ*, with Σ = {a,b}, and let w be the string ak. However the strings x, y,and z are chosen, all the pumped strings will be in the language a* and thus b, for example, could not be a pumped string although it is in L.
TRUE. The answers to Questions 1 and 2 imply that L(P) is exactly the set of even-length strings, so we just need to prove (not just assert) that L(G) is this same set. Every string produced by G must have even length because every step in a derivation that produces terminals produces exactly two terminals. Conversely, every even-length string can be generated with G -- here is a proof by induction on k where 2k is the length of the string. If k = 0 we use S --> ε. Assume we can generate any string of length 2k from S, and consider any string of length 2k+2 -- write this string as xyu where x and y are letters and u is a string of length k2. For any x and y, S --> xSy is a rule. So we can derive xyu by the sequence S --> SS --> xSyS --> xyS --> xyu, using the IH to go from S to u.
There are several derivations, the easiest of which is probably
S --> aSb --> aaSab --> aabSbab --> aabbab. The parse tree has S at the
root with children a, S, and B. The child S has children a, S, and a. The
granchild S has children b, S, and b, and the great-grandchild S has an only
child ε. The leaves, read left to right, form the string aabbab.
Another derivation, matching my argument for Question 4, would be
S --> SS --> aSaS --> aaS --> aaSS --> aabSbS --> aabbS --> aabbaSb --> aabbab.
From S, apply the rule S --> aSb n times to get anSan. Then apply the rule S --> bSa n times and the rule S --> ε once to get the desired string.
It is not a CFL. (I was happy that most of you recognized that although
Question 5b shows this language to be a subset of the CFL L(G), this has
nothing to do with its own CFL-ness.) To show this language is not CFL we
use the CFL Pumping Lemma. If it were a CFL it would obey the CFLPL for some
pumping length p. Let w be the string
apbpapbp. Since |w| ≥ p, the
CFLPL says that w can be written as uvxyz with |vxy| ≤ p, |vy| > 0, and
such that for all i, ivixyiz is in L(G). We will show
that this is impossible. Since either v or y is nonempty, changing i from 1 to
2 adds some a's or b's to the string. Since |vxy| ≤ p, however, this can
add a's or b's to at most two of the four blocks of common letters that make up
w. Thus uvvxyyz cannot be in L(G), as even if it is in the language
a*b*a*b* the lengths of the four
blocks cannot be all equal.
A few of you misused the CFLPL (or the RLPL) by naming the strings u, v, x,
y, and z yourself. You just get to name w -- then you must show that any
division of w into five strings, meeting the conditions of the CFLPL, must
lead to at least pumped string that is not in L(G).
Both the TDP and BUP have three states, q0, q, and f, with start
state q0 and only final state f. The TDP has rules
(q0, ε S$; q. ε),
(q, a, a; q, ε),
(q, b, b; q, ε),
(q, ε S; q, ε),
(q, ε S; q, SS),
(q, ε S; q, aSa),
(q, ε S; q, aSb),
(q, ε S; q, bSa),
(q, ε S; q, bSb), and
(q, ε S; f, ε).
The BUP has rules
(q0, ε $; q. ε),
(q, a, ε; q, a),
(q, b, ε; q, b),
(q, ε ε; q, S),
(q, ε SS; q, S),
(q, ε aSa; q, S),
(q, ε bSa; q, S),
(q, ε aSb; q, S),
(q, ε bSb; q, S), and
(q, ε S$; f, ε).
It is regular -- we showed in Question 4 that it is exactly the set of even-length strings, which has the regular expression ((a ∪ b)(a ∪ b))* or a two-state DFA where the initial state is the only final state and every letter takes every state to the other state.
It is not. Many of you said that L(G') is the set of even-length palindromes,
since this is what you generate if you use the rules S --> aSa and S --> bSb
any number of times followed by S --> ε. But since S --> SS is still
a rule, L(G') is actually the star of the set of even-length palindromes.
Since L(G) includes (aa ∪ bb)* as a subset, it is difficult to
construct a Pumping Lemma proof that it is not regular -- pumping an
even-length string of a's to a longer even-length string of a's keeps you in
L(G').
My proof is as follows -- I claim that if i > j, the strings
x = (ab)i and y = (ab)j are not L(G') equivalent.
Let z = (ba)j. It is easy to see that yz is in L(G') because it is
an even-length palindrome -- I claim that xz is not in L(G'). If it were in
L(G'), I could divide it into substrings, each of which is an even-length
palindrome. A nonempty even-length palindrome must have aa or bb as its
central two characters, so the only even-length palindromes in xz must center
on the only double-letter in it, a bb. So any division into nonempty substrings
can contain at most one even-length palindrome and thus cannot consist entirely
of even-length palindromes.
Students of group theory may recognize this language as the set of words in
the generators a and b that equal the identity element of the group given by
the relations a2 = 1 and b2 = 1. Or not.
Let N3 consist of all the states and transitions of N1 and N2, plus a new start state and ε-transitions from the new start state to the start states of N1 and N2. The final states of N3 are the final states of N1 and N2. A word can be accepted by N3 if and only if it can be accepted by either N1 or N2 or both, since the paths in N3 from the new start state to a final state correspond either to paths in N1 or in N2.
In lecture we presented the "product construction" for DFA's, taking two DFA's
D1 and D2 and making a new DFA whose states are pairs
(q1, q2) where qi is a state of D1.
The transition function δ of the product machine is defined by the rule
δ((q1, q2), a) =
(δ1(q1, a), δ2(q2, a)).
The final states of the product machine are those states where both
components of the pair are final for their respective machines. The language
of this machine is L(D1) ∩ L(D2But here we have NFA's, so we must either convert to NFA's or argue that we
can adapt the construction. Given N1 and N2 with k states
each, we can construct D1 and D2, with 2k
states each, using the subset construction to ensure that
L(D1) = L(N1) and
L(D2) = L(N2). Then we can use the product construction
to get a DFA (which of course is also an NFA) with the desired language and
22k states.
To adapt the product construction to NFA's, we need to say what we are going
to do with ε-moves. If we add an ε-move from each state to
itself, and follow Sipser in defining δ(q,a) for an NFA to be the
set of states r such that there is a transition from q to r on letter a
(where a could also be ε), we can define the set
δ((q1, q2), a) to be the direct product of the sets
&delta1;(q1, a) and δ2(q2, a).
Then it is possible for our product NFA to read w and go from
(q01, q02) to (r1, r2) if an only
if it is possible to go from q01 to r1 reading w
and it is possible to go from q02 to r2 reading w.
Thus if we make the final state set of our product machine the direct product
F1 × F2, the language of our product machine is
L(N1) ∩ L(N2) as desired. I gave only partial credit
for answers that applied the product construction directly to NFA's without
these details.
Applying the GNFA construction, we can kill state 2, creating the new transitions (1,bb,3) and (1,bb,4), which merge with existing transitions to become (1, a ∪ bb, 3) and (1, a ∪ bb, 4). Then we can kill state 3, creating a single merged transition (1, a ∪ bb ∪ (a ∪ bb)b, 4). The final regular expression can also be written "a ∪ ab ∪ bb ∪ bbb (typo corrected 25 Feb)" or "(a ∪ bb)(ε ∪ b)", where we understand "ε" to be an abbreviation for "∅*". Since the original NFA has no loops and none are created during the construction, we don't generate any new stars in the regular expression.
The start state is {1}. We can compute δ({1}, a) = {3,4},
δ({1}, b) = {2}, δ({3,4}, a) = ∅ δ({3,4}, b) = {4},
δ({2}, a) = ∅, δ({2}, b) = {3,4}, and
δ({4}, a) = &delta({4}, b) = δ(∅, a) = δ(∅, b) =
∅. Once every state we have reached has both its transitions to other
states we have reached, we can stop, in this case with a five-state DFA.
Renaming {1} = 1, {2} = 2, {3,4} = 3, {4} = 4, and ∅ = 5, we have start
state 1 and final state set {3,4}.
Several of you constructed the following valid DFA by creating a states
for every prefix of a string in L(M), so that the seven states can be called
ε (the start state), a, b, ab, bb, bbb, and "death". Here the final
state set is {a, ab, bb, bbb}, and the transition from state named
w on letter x goes to the state named wx if there is one and to "death" if there
is not. This is a natural construction of a DFA for any finite language.
My five-state DFA from the first paragraph of my answer to Question 7b is
minimal. If we apply the minimization construction to it, we begin with classes
N = {1,2,5} and F = {3,4}. The behavior of state 1 with respect to this
partition is (F,N), the behavior of state 2 is (N,F), and the behavior of state
5 is (N,N). (Here "behavior of (F,N)" means the state goes to a state in F on
an a and to a state in N on a b.) Thus the three states of N must go into
three separate classes in the next partition. Similarly, the behavior of
state 3 is (N,F) and the behavior of state 4 is (N,N), so these two states
must also go into separate classes in the next partition. Our second partition
has five classes with one state each, proving that the original DFA was minimal.
If we apply the minimization construction to the second DFA in my answer
to Question 7b, we find the partition {{ε}, {a,bb}, {b}, {ab,bbb},
{death}} to be stable and so get a five-state minimal DFA isomorphic to that
above.
If we want to prove my first DFA to be minimal without the construction,
we can note that among the non-final states, 1 and 2 are separated by a,
1 and 5 are separated by a, and 2 and 5 are separated by b. Among the final
states, 3 and 4 are separated by b. So no states can be merged and the DFA
is minimal.
Last modified 13 February 2011