Docsity

Solutions to Practice Problems Pumping Lemma, Exercises of Database Programming

Toggle sidebar
bg1
Solutions to Practice Problems
Pumping Lemma
1. L = { a b | k $ 0}
k k
see notes
2. L = {a | k is a prime number}
k
Proof by contradiction:
Let us assume L is regular. Clearly L is infinite (there are infinitely many prime
numbers). From the pumping lemma, there exists a number n such that any string
w of length greater than n has a “repeatable” substring generating more strings in
the language L. Let us consider the first prime number p $ n. For example, if n was
50 we could use p = 53. From the pumping lemma the string of length p has a
“repeatable” substring. We will assume that this substring is of length k $ 1. Hence:
a 0L and
p
a0L as well as
p + k
a0L, etc.
p+2k
It should be relatively clear that p + k, p + 2k, etc., cannot all be prime but let us add
k p times, then we must have:
a0L, of course a
p + pk p + pk = ap (k + 1)
so this would imply that (k + 1)p is prime, which it is not since it is divisible by both p
and k + 1.
Hence L is not regular.
3. L = {a b }
n n+1
Assume L is regular. From the pumping lemma there exists a p such that every w 0
L such that |w| $ p can be represented as x y z with |y| 0 and |xy| # p. Let us
choose a b . Its length is 2p + 1 $ p. Since the length of xy cannot exceed p, y
p p+1
must be of the form a for some k > 0. From the pumping lemma a b must also
k p-k p+1
be in L but it is not of the right form. Hence the language is not regular.
Note that the repeatable string needs to appear in the first n symbols to avoid the
following situation:
assume, for the sake of argument that n = 20 and you choose the string a b
10 11
which is of length larger than 20, but |xy| # 20 allows xy to extend past b, which
means that y could contain some b’s. In such case, removing y (or adding more y’s)
could lead to strings which still belong to L.
4. L = {a b }
n 2n
Assume L is regular. From the pumping lemma there exists a p such that every w 0
L such that |w| $ p can be represented as x y z with |y| 0 and |xy| # p. Let us
choose a b . Its length is 3p $ p. Since the length of xy cannot exceed p, y must
p 2p
be of the form a for some k > 0. From the pumping lemma a b must also be in L
k p-k 2p
pf3
pf4
pf5

Partial preview of the text

Download Solutions to Practice Problems Pumping Lemma and more Exercises Database Programming in PDF only on Docsity!

Solutions to Practice Problems

Pumping Lemma

  1. L = { a b | kk^ k $ 0} see notes
  2. L = {a | k is a prime number}k Proof by contradiction: Let us assume L is regular. Clearly L is infinite (there are infinitely many prime numbers). From the pumping lemma, there exists a number n such that any string w of length greater than n has a “repeatable” substring generating more strings in the language L. Let us consider the first prime number p $ n. For example, if n was 50 we could use p = 53. From the pumping lemma the string of length p has a “repeatable” substring. We will assume that this substring is of length k $ 1. Hence:

a p 0 L and a p + k 0 L as well as a p+2k 0 L, etc.

It should be relatively clear that p + k, p + 2k, etc., cannot all be prime but let us add k p times, then we must have:

a p + pk^0 L, of course ap + pk^ = ap (k + 1)

so this would imply that (k + 1)p is prime, which it is not since it is divisible by both p and k + 1.

Hence L is not regular.

  1. L = {a bn^ n+1} Assume L is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose a bp^ p+1. Its length is 2p + 1 $ p. Since the length of xy cannot exceed p, y must be of the form a for some k > 0. From the pumping lemma ak^ p-kb^ p+1must also be in L but it is not of the right form. Hence the language is not regular.

Note that the repeatable string needs to appear in the first n symbols to avoid the following situation:

assume, for the sake of argument that n = 20 and you choose the string a 10 b^11 which is of length larger than 20, but |xy| # 20 allows xy to extend past b, which means that y could contain some b’s. In such case, removing y (or adding more y’s) could lead to strings which still belong to L.

  1. L = {a bn^ 2n} Assume L is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose a bp^ 2p. Its length is 3p $ p. Since the length of xy cannot exceed p, y must be of the form a for some k > 0. From the pumping lemma ak^ p-kb^ 2pmust also be in L

but it is not of the right form. Hence the language is not regular.

  1. TRAILING-COUNT as any string s followed by a number of a’s equal to the length of s. Assume L is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose b a. Its length is 2pp^ p $ p. Since the length of xy cannot exceed p, y must be of the form b for some k > 0. From the pumping lemma bk^ p-k^ a pmust also be in L but it is not of the right form. Hence the language is not regular.
  2. EVENPALINDROME = { all words in PALINDROME that have even length} Same as #2 above, choose a bba .n^ n
  3. ODDPALINDROME = { all words in PALINDROME that have odd length} Same as #2 above, choose a ba .n^ n
  4. DOUBLESQUARE = { a bn^ nwhere n is a square } Assume DOUBLESQUARE is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose a pp^ b pp. Its length is 2p^2 $ p. Since the length of xy cannot exceed p, y must be of the form a for some k > 0. Let us add y p times. From thek pumping lemma a pp+pkb^ pp^ = a p(p + k)b^ p*pmust also be in L but it is not of the right form. Hence the language is not regular.
  5. L = { w | w 0 {a, b}*, w = w }R Proof by contradiction: Assume L is regular. Then the pumping lemma applies.

From the pumping lemma there exists an n such that every w 0 L longer than n can be represented as x y z with |y| Ö 0 and |x y| # n.

Let us choose the palindrome a ba .n^ n

Again notice that we were clever enough to choose a string which: a. has a center mark which is not a (otherwise when we remove or add y we would be left with an acceptable string) b. has a first portion on length n which is all a’s (so that when we remove or add y it will create an imbalance).

Its length is 2n + 1 $ n. Since the length of xy cannot exceed n, y must be of the form a for some k > 0. From the pumping lemma ak^ n-k^ b a nmust also be in L but it is not a palindrome.

Hence L is not regular.

  1. L = { w 0 {a, b}* | w has an equal number of a’s and b’s} Let us show this by contradiction: assume L is regular. We know that the language generated by ab is regular. We also know that the intersection of two regular languages is regular. Let M = (a bn^ n| n $ 0} = L(ab) 1 L. Therefore if L

us choose a bap^ p+1. Its length is 2p+2 $ p. Since the length of xy cannot exceed p, y must be of the form a m^ for some m > 0. From the pumping lemma a p-mba^ p+ must also be in L but it is not of the right form. Hence the language is not regular.

  1. L = {va k+1| v 0 {a, b}*, |v| = k} Assume L is regular. From the pumping lemma there exists an n such that every w 0 L such that |w| $ n can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose b an^ n+1. Its length is 2n+1 $ n. Since the length of xy cannot exceed n, y must be of the form b for some k > 0. From the pumping lemma if we add twok y to the original string b n+2ka^ n+1must also be in L but that string is of length 2n+2k+1 and v would have to be b n+kto fit the pattern the rest of the string would then be b ak^ k+1which is not of the right form. Hence the language is not regular.
  2. L = {va 2k| v 0 {a, b}*, |v| = k} Assume L is regular. From the pumping lemma there exists a n such that every w 0 L such that |w| $ n can be represented as x y z with |y| Ö 0 and |xy| # n. Let us choose b an^ 2n. Its length is 3n $ n. Since the length of xy cannot exceed n, y must be of the form b for some k > 0. From the pumping lemma bk^ n+k^ a nmust also be in L but it is not of the right form since the number of a’s exceeds the number of b’s and we cannot move any b’s on the a side (Note that you must add not subtract, otherwise the string would be OK by shifting a’s to the b side). Hence the language is not regular.
  3. L = {ww | w 0 {a, b}*} Assume L is regular. From the pumping lemma there exists an n such that every w 0 L such that |w| $ n can be represented as x y z with |y| Ö 0 and |xy| # n. Let us choose a b a b. Its length is 4nn^ n^ n^ n $ n. Since the length of xy cannot exceed n, y must be of the form a for some k > 0. From the pumping lemma ak^ n+kb a b^ n^ n^ n must also be in L but it is not of the right form since the middle of the string would be in the middle of the b which prevents a match with the beginning of the string. Hence the language is not regular.
  4. L = { a n!| n $ 0} Proof by contradiction: Let us assume L is regular. From the pumping lemma, there exists a number p such that any string w of length greater than p has a “repeatable” substring generating more strings in the language L. Let us consider a p!(unless p < 3 in which case we chose a ). From the pumping lemma the string w has a3! “repeatable” substring. We will assume that this substring is of length k $ 1. From the pumping lemma a p!-kmust also be in L. For this to be true there must be j such that j! = m! - k But this is not possible since when p > 2 and k # m we have m! - k > (m - 1)! Hence L is not regular.
  5. L = { a b | nn^ l Ö l} Proof by contradiction: Let us assume L is regular. From the pumping lemma, there exists a number p

such that any string w of length greater than p has a “repeatable” substring generating more strings in the language L. Let us consider n = p! and l = (p+1)! From the pumping lemma the resulting string is of length larger than p and has a “repeatable” substring. We will assume that this substring is of length k $ 1. From the pumping lemma we can add y i-1 times for a total of i ys. If we can find an i such that the resulting number of a’s is the same as the number of b’s we have won. This means we must find i such that: m! + (i - 1)*k = (m + 1)! or (i - 1) k = (m + 1) m! - m! = m * m! or i = (m * m!) / k + 1

but since k < m we know that k must divide m! and that (m * m!) / k must be an integer. This proves that we can choose i to obtain the above equality. Hence L is not regular.

  1. L = {a b a | k > n + l}n^ l^ k Assume L is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose a bap^ p+2. Its length is 2p+3 $ p. Since the length of xy cannot exceed p, y must be of the form a m^ for some m > 0. From the pumping lemma a p+2m^ bap+ must also be in L but it is not of the right form since p+2m+1 > p+2. Hence the language is not regular.
  2. L = {a b c | kn^ l^ k Ö n + l} Assume L is regular. From the pumping lemma there exists a p such that every w 0 L such that |w| $ p can be represented as x y z with |y| Ö 0 and |xy| # p. Let us choose a b ap!^ p!^ (p+1)!. Its length is 2p!+(p+1)! $ p. Since the length of xy cannot exceed p, y must be of the form a mfor some m > 0. From the pumping lemma any string of the form xy z must always be in L. If we can show that it is alwaysi. possible to choose i in such a way that we will have k = n + l for one such string we will have shown a contradiction. Indeed we can have p!+(i-1)m + p! = (p+1)! if we have i = 1 + ((p+1)! - 2 p!)/ m Is that possible? only if m divides ((p+1)! -2 p! ((p + 1)! - 2 * (p)! = (p + 1 - 2) p! and since m # p m is guaranteed to divide p!.

Hence i exists and the language is not regular.

  1. L = {a b a | n = l or ln^ l^ k Ö k} Proof by contradiction: Let us assume L is regular. From the pumping lemma, there exists a number p such that any string w of length greater than p has a “repeatable” substring generating more strings in the language L. Let us consider w = a b a .p^ p^ p From the pumping lemma the string w, of length larger than p has a “repeatable” substring. We will assume that this substring is of length m $ 1. From the pumping lemma we can remove y and the resulting string should be in L. However, if we remove y we get a p - mb a. But this string is not in L since p-m^ p^ p Ö p and p = p. Hence L is not regular.