Professional Documents
Culture Documents
Exercise 5
Exercise 5
(e is epsilon)*
c) L = { aj bm ck | j + k = m }
S → L R
L→ aLb | e
R→ bRc |e
Exercise 2.
e, S / S a
1. e, R / R a
e, S / E b
e, R / L b
e, E / E a
e, L / L a
e, E / R b
e, L / E b
e, E / E e
e, e / $S e, $ / e
q0 q1 q2
a, a / e
b, b / e
q0
b
a
b
DFA q1
e, S / E S E
2. e, S / c
e, E / a
e, E / b
e, E / c
e, e / $S e, $ / e
q0 q1 q2
a, a / e
b, b / e
e, S / R L c, c / e
3. e, R / c R b
e, L / b R a
e, R / e , c/e
e, L / e
e, e / $S e, $ / e
q0 q1 q2
a, a / e
b, b / e
c, c / e
, c/e
4.
e, S / b S a
e, S / a S b
e, S / e
e, e / $S e, $ / e
q0 q1 q2
, c/e
a, a / e
b, b / e
Exercise 3.
, c/e
a) { an b m | 0 < m < n }
Context-free
S → aa R b
R→ aR | aRb | e
Assume L = { an bm | 0 < m < n }is regular. Thus, it is pumpable by the pumping
lemma and has the pumping length p. Suppose w = ap+1bp and we know that w is in
L and |w| = 2p+1 >= p. Suppose we divide up w into xyz such that: the length of xy
is at most p and xy contains only a's, but maybe not all of the a's, y will contain at
least one a and z will contain the remaining a's, and all of the b’s. If we pump down
the string xy^0, then it also should be in L by the pumping lemma. However, when
we pump down, we see that we get ap+1-ybp which contains more a’s than b’s or the
same number of a’s as b’s in the string. Thus, the string is not in L. Thus, L is not
pumpable and not regular.
c) { a2^n | 𝑛 ≥ 0 }
Not context-free.
Assume L = {a^𝑘 | 𝑘 = 2^𝑛 , 𝑛 ∈ 𝑁} is context-free. Thus, it is pumpable by the
pumping lemma and has the pumping length p. Suppose w = a^(2^p) and we know
that w is in L and |w| = 2^p >= p. Suppose we divide up w into uvxyz such that: the
length of vxy is at most p and where v and y are non-empty. If we pump up to the
string uv^2xy^2z , we will get a string with greater number of a’s. Therefore, the
length of this string should be >= 2^(p+1) so that it is in L. Suppose v and y contains
k number of a’s. Then, we have that:
2^p < 2^p + k <= 2^p + p
2^p + p < 2^(p+1)
Therefore, 2^p < 2^p + k < 2^(p+1), which means that the length is now between
two consecutive powers of 2. Thus, the string is not in L. Thus, L is not pumpable
and not context-free.
.
d) { 𝑤𝑤reverse𝑤 | 𝑤 ∈ {0,1} ∗ }
Not context-free.
Assume L = { 𝑤𝑤reverse𝑤 | 𝑤 ∈ {0,1} ∗ }is context-free. Thus, it is pumpable by the
pumping lemma and has the pumping length p. Suppose w = 01p001p001p0 and we
know that w is in L and |w| = 3p+3 >= p. Suppose we divide up w into uvxyz such
that: the length of vxy is at most p and v and y are non-empty. Thus, vxy can
contain at most two of the 0’s. If we pump down to the string uv0xy0z, then it also
should be in L by the pumping lemma. However, when we pump down, we see that
the resulting string will contain a smaller number of 0’s and we cannot divide this
string into three parts with same number of 1’s and 0’s. In the second case, we can
divide w into uvxyz such that v and y will contain only a’s and at least one a. If we
pump down this string, we can get the resulting strings 01(p-v)001(p-y)001p0 or
01p-v-y001p001p0 or 01p001p-v-y001p0. These strings cannot be in the language,
since they cannot be divided into three parts with same number of 1’s and 0’s. Thus,
L is not pumpable and not context-free.
e) language of palindromes over {a, b} that have the same number of a’s and b’s.
Not context-free
Assume this language is context-free. Thus, it is pumpable by the pumping lemma
and has the pumping length p. Suppose w = apb2pap and we know that w is in L and
|w| = 4p >= p. Suppose we divide up w into uvxyz such that: the length of vxy is at
most p and v and y are non-empty. Here, in the first case, vxy may contain only a’s.
If we pump down the string uv0xy0z, the resulting string will contain a smaller
number of a’s and the same number of b’s. Therefore, this string is not in L. In the
second case, vxy may contain some k number of a’s and some r number of b’s,
again v and y are non-empty and |vxy| <= p. If we pump down this string, then we
might get strings ap-kb2p-rap or apb2p-rap-k. We can see that these strings cannot be
palindromes, since number of a’s on the left-side is not equal to the a’s on the right-
side. Therefore, these strings are also not in the language. Finally, in the third case,
vxy may contain only b’s, but not all b’s. If we pump down this string, then we can
get the string apb2p-v-yap. Now the number of b’s is less than before, so we cannot
divide the string into two parts that will contain the same number of a’s and b’s, the
number of b’s will be less. Thus, this string is also not in L. Therefore, the language
is not pumpable and context-free.
Same operation can be applied to vyx with characters chosen from the right string.
Therefore, since none of the strings are not in the language, the language is not
pumpable and thus not context-free.