Docsity

CS3500 Homework Solutions: Regular Languages and Pumping Lemma, Assignments of Computer Science

Toggle sidebar
bg1
CS3500 HW2 Solutions
1.23 (5 points each)
a. Let Lbe the language and assume Lis regular. Let pbe the pumping length
and sbe the string 0p10p. Because sis a member of Land shas length more
than p, the pumping lemma guarantees that scan be split into three pieces,
s=xyz satisfying the three conditions of the pumping lemma. Because of con-
dition 3 (|xy| ≤ p), ycan only consist of 0s. Then the string xy2zwill not be
in Lsince the number of 0s before 1 will exceed the number of 0s after 1.
b. Let Lbe the language and assume it is regular. Then its complement
L={0n1n|n≥0}is also regular since the class of regular language is closed
under complement. But we know in class that Lis not regular and thus we have
a contradiction.
c. Let Lbe the language and assume it is regular. Then its complement Lis
also regular. Furthermore, the language L∩{0∗1∗}is also regular since the class
of regular language is closed under intersection. We know that L∩ {0∗1∗}=
{0n1n|n≥0}is not a regular language and this is a contradiction.
Note: The complement of Lis not the language in part b). Lshould be a
UNION of the strings NOT of the form {0∗1∗}and the language in part b).
d. Let Lbe the language and assume it is regular. Let pbe the pumping length
and sbe the string 0p10p. Following the same reasoning in part a), we can
show that either we pump up or pump down, the resulting string will not be a
palindrome.
2.4 (5 points each)
a.
S→A1A1A1A
A→A0|A1|
b.
S→0A0|1A1|0|1|
A→A0|A1|
c.
S→1A|0A
A→1S|0S|
d.
S→0S0|0S1|1S0|1S1|0
e.
S→SAR |RAR
A→1A|1
R→R0R1|R1R0|
f.
S→0S0|1S1|0|1|
1
pf3
pf4

Partial preview of the text

Download CS3500 Homework Solutions: Regular Languages and Pumping Lemma and more Assignments Computer Science in PDF only on Docsity!

CS3500 HW2 Solutions

1.23 (5 points each) a. Let L be the language and assume L is regular. Let p be the pumping length and s be the string 0p 10 p. Because s is a member of L and s has length more than p, the pumping lemma guarantees that s can be split into three pieces, s = xyz satisfying the three conditions of the pumping lemma. Because of con- dition 3 (|xy| ≤ p), y can only consist of 0s. Then the string xy^2 z will not be in L since the number of 0s before 1 will exceed the number of 0s after 1.

b. Let L be the language and assume it is regular. Then its complement L = { 0 n 1 n|n ≥ 0 } is also regular since the class of regular language is closed under complement. But we know in class that L is not regular and thus we have a contradiction.

c. Let L be the language and assume it is regular. Then its complement L is also regular. Furthermore, the language L∩{ 0 ∗ 1 ∗} is also regular since the class of regular language is closed under intersection. We know that L ∩ { 0 ∗ 1 ∗} = { 0 n 1 n|n ≥ 0 } is not a regular language and this is a contradiction. Note: The complement of L is not the language in part b). L should be a UNION of the strings NOT of the form { 0 ∗ 1 ∗} and the language in part b).

d. Let L be the language and assume it is regular. Let p be the pumping length and s be the string 0p 10 p. Following the same reasoning in part a), we can show that either we pump up or pump down, the resulting string will not be a palindrome.

2.4 (5 points each) a. S → A 1 A 1 A 1 A A → A 0 | A 1 |  b. S → 0 A 0 | 1 A 1 | 0 | 1 |  A → A 0 | A 1 |  c. S → 1 A | 0 A A → 1 S | 0 S |  d. S → 0 S 0 | 0 S 1 | 1 S 0 | 1 S 1 | 0 e. S → SAR | RAR A → 1 A | 1 R → R 0 R 1 | R 1 R 0 |  f. S → 0 S 0 | 1 S 1 | 0 | 1 | 

2.7 (5 points each) a. We’ll use Γ = {a, b, a}, where a represents a deficit of as. Read symbols from the input. If an a is read and there is a on the stack, pop a. If an a is read and there is not a on the stack, push a. If a b is read, repeat the following exactly twice: if a is on the stack, pop a; otherwise push a. If we run out of input when the stack is empty, accept. Otherwise reject.

d. There are two cases we should consider: i = j or i 6 = j. Case 1: Nondeterministically decide i 6 = j and do the following: a. Repeat: If there is no more input, reject. Otherwise, nondeterministically decide if this is string i. If not, read input through to the next # or end of input. If so, read input through to the next # or end of input but push every symbol read onto the stack, except the #, and break out of this loop. b. Repeat: If there is no more input, reject. Otherwise, nondeterministically decide if this is string j. If not, read input through to the next # or end of input. If so, read input through to the next # or end of input but compare each symbol with the symbol on the stack, popping as we go. If they match and the stack is empty and we’ve reached # or end of input, read the rest of the input and accept. Otherwise, reject. Case 2: Nondeterministically decide i = j and do the following: Repeat: If there is no more input, reject. Otherwise, nondeterministically decide if this is string i. a. If not, read input through to the # or end of input. b. If so, read input symbols and push them onto the stack. If # is read or end of input is reached, reject. Nondeterministically decide when we hit the middle of the string. Nondeterministically read a, b, or nothing. Now read the rest of the string (up to # or end) and compare to the stack, popping as we go. If they match and the stack is empty and we’ve read the whole string, accept. Otherwise reject.

2.17 a. (15 points) Let MC be a PDA accepting C and MR be a DFA accept- ing R. We construct a PDA M accepting C ∩ R in a manner similar to Theorem 1.12 in Sipser. Say MC = (QC , Σ, Γ, δC , qC , FC ) and MR = (QR, Σ, δR, qR, FR). Let M = (Q, Σ, Γ, δ, q 0 , F ) with the following: Q = QC × QR, q 0 = (qC , qR), F = {(r 1 , r 2 ) | r 1 ∈ FC and r 2 ∈ FR}. Define δ like this: Say for some r 1 ∈ QC , a ∈ Σ, and t ∈ Γ, δC (r 1 , a, t) = {(q 1 , t 1 ),... , (qn, tn)} for some n ≥ 0. Then we define δ((r 1 , r 2 ), a, t) = {((q 1 , δR(r 2 , a)), t 1 ),... , ((qn, δR(r 2 , a)), tn)}. Basically M simulates MC and MR together. MR doesn’t pay attention to M ’s stack, so M is a valid PDA with one stack, which it gets from MC. A string accepted by both MC and MR will end up in an accept state in each, and so it will follow

or y contains the # in s, pumping down will eliminate it, and the string will no longer be in the language because every string in the language contains at least one # symbol. This covers all possibilities, so we have a contradiction.