Problem 2.6(d) [4 pts] S X T#X X#T T#X#T X axa bxb #T# # T at bt #T ε Problem 2.12 [3pts] Original CFG: R XRX S S atb bta T XTX X ε X a b q start ε, ε $ ε, R X ε, ε R ε, ε X ε, R S ε, T X ε, T ε ε, X a ε, X b a, a ε b, b ε ε, ε R ε, $ ε q loop ε, S b ε, ε T ε, ε a ε, S a ε, ε T ε, ε b ε, T X ε, ε T ε, ε X qq accept start
Problem 2.13 [4 pts] (a) There are 2 cases: Case 1: The string contains exactly two # symbols. In this case, the string produced can have any number of zeros with the two # symbols. Case 2: The string contains exactly one # symbol. The string produced will have twice the amount of 0 s to the right of the # as to the left of the #. (b) Prove L(G) is not regular. We assume L(G) is a regular language, so there exists a pumping length p. We choose the string s to be 0 p #0 2p, which is in L(G) and the length of the string is 3p + 1 p. Thus, s can be divided into 3 pieces xyz satisfying the 3 conditions of the pumping lemma. Because xy p, then xy only contains 0 s to the left of the #. Since y > 0, it is safe to claim that y = 0 k, k > 0. xy 2 z = 0 p+k #0 2p which is not in the language L(G) since 2(p + k) > 2p. This contradicts the assumption that L(G) is a regular language. Therefore, we conclude that L(G) is not a regular language. Problem 2.14 [3 pts] Initial. A BAB B ε ε Step 1. Add new start symbol A BAB B ε ε Step 2. Remove ε rules Remove B ε A BAB BA AB A B ε Remove A ε A BAB BA AB A B BB Step 3. Remove unit rule Remove A A ε A BAB BA AB B BB Remove A B S 0 BAB BA AB 00 BB ε A BAB BA AB 00 BB
Step 4. Convert rules to proper form Replace terminal 0 with variable U S 0 BAB BA AB UU BB ε A BAB BA AB UU BB B UU U 0 Shorten length 3 rules. S 0 BAB replaced with S 0 BA 1 and A 1 AB And A BAB replaced with A BA 2 and A 2 AB S 0 BA 1 BA AB UU BB ε A BA 2 BA AB UU BB B UU U 0 A 1 AB A 2 AB Problem 2.25 [4 pts] Note: Either method is acceptable. Proof: Method 1: Construct a PDA that accepts the suffixes of A. Because A is context-free, there must be a PDA accepting A, call it M1. Then, do the following: (1) Make a copy of M1, and call it M2. M2 has exactly the same states, stack, and transitions as M1. Together M1 and M2 form the whole PDA M. (2) Change the input part of transitions in M2 from what it was to ε, while keeping the stack the same. (i.e. if the original transition was a, b ε, we change it to ε, b ε. (3) For each state in M2, add a transition ε, ε ε to the corresponding state in M1. (4) Let the start of M2 be the start state of PDA M. M will construct the stack appropriately and ignore the input. At some point of time, M nondeterministically transitions from the state in M2 to the corresponding state in M1, then starts to take the first character of the suffix as the input, and makes transition in M1 from then on. Therefore, all the suffixes of the string belonging to A will be accepted by M. Problem 2.30(a,d) [4 pts each] Proof of part (a). Assume A is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = 0 p 1 p 0 p 1 p, where p A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma. Since vxy p and vy > 0, vxy may not contain two sets of 0 or 1 symbols.
Case 1: v and y only contain one symbol, i.e. vxy = 0 l, vxy = 1 l, where 0 < l p. If vxy = 0 l, then for i = 2, uv 2 xy 2 z = 0 p+l 1 p 0 p 1 p A or uv 2 xy 2 z = 0 p 1 p 0 p+l 1 p A. Therefore, vxy 0 l. Similarly, we can prove vxy 1 l. Case 2: v and y contain two symbols, i.e. vxy = 0 l 1 r or vxy = 1 r 0 l, where 0 < l + r p. If vxy = 0 l 1 r, then for i = 2, uv 2 xy 2 z = 0 p+l 1 p+r 0 p 1 p A or uv 2 xy 2 z = 0 p 1 p 0 p+l 1 p+r A. So, vxy 0 l 1 r. Similarly, vxy 1 r 0 l. Case 3: v or y contains both 0 and 1, i.e. v = 0 l 1 r and y = 1 k ; or v = 1 r 0 l and y = 0 k, where 0 < l + r p. If v = 0 l 1 r, then for i = 0, uv 0 xy 0 z = 0 p l 1 p r k 0 p 1 p A or uv 0 xy 0 z = 0 p 1 p 0 p l 1 p r k A. Similarly, v 1 r 0 l. In all possible cases, there is a violation of the pumping lemma. Thus, the original assumption of A being context-free is incorrect. Therefore, A is not a context-free language. Proof of part (d). Assume A is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = a p b p #a p b p, where s A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma. Case 1: vxy is in either a p b p part of s. In this case, consider uv i xy i z for i = 0 or i > 0, the number of a s and b s will be unbalanced on both sides of s separated by the #, violating the pumping lemma. Case 2: vxy contains the # part of s. Subcase a: x contains the #. In this case, consider uv i xy i z for i = 0 or i > 0, v consists of b s and y contains only a s. However the number of a s and b s will be unequal on either side of s separated by the #, violating the pumping lemma. Subcase b: v or y contains the #. Suppose v contains the #. In this case, consider uv 0 xy 0 z this resulting string does not contain a # so s A. Similarly, when y contains the #. In all possible cases, there is a violation of the pumping lemma. Thus, the original assumption of A being context-free is incorrect. Therefore, A is not a context-free language. Problem 2.31 [4 pts] Assume B is a context-free language. So it must satisfy the pumping lemma for CFLs. Let p be the pumping length. Consider the string s = 0 p 1 2p 0 p, where p A and s > p. According to the pumping lemma, s may be divided into 5 pieces, s = uvxyz, and the division satisfies the three constraints of the pumping lemma.
Case 1: vxy contains only 1 s. In this case, consider uv 2 xy 2 z B, since it will no longer have the same number of 0s and 1s. Case 2: vxy contains at least one 0. Consider uv 2 xy 2 z B, because it will no longer be a palindrome since xvy can only symbols from the starting 0s or the final 0s, but not both. Hence, after pumping s will no longer have the same number of 0s before and after the 1s. In both possible cases, the pumping lemma is violated. Therefore, the original assumption of B being a context-free language is contradicted. Therefore, B is not a CFL.