The language
L = {anbnbn | n >= 0}
is not context-free.
This can be proved by using the Pumping Lemma.
Given an arbitrary n, take
u =
anbnanbnanbn
in L. Let us call "blocks" the six parts of only a's or only b's
of which u is composed.
Consider five strings v,w,x,y,z
such that u = vwxyz, |wxy|<=n and |wy|>0.
Assume |w|>0. We have the following cases:
- w contains a's and/or b's from the first two blocks.
Then y may contain a's from the first block, and/or
b's from the second block, but nothing else. Hence for k=0
vwkxykz = vxz cannot belong to L
because the first half of vxz ends with b's, and the second half too.
- w contains some a's from the third block. Then
for k=0
vwkxykz = vxz cannot belong to L
because it contains less than n a's in the third
block and n b's in the sixt block.
- w contains some b's from the fourth block.
Similar to Case 2: we conclude that vxz contains
less than n b's in the fourth
block and n a's in the first block.
- w contains a's and/or b's from the last two blocks.
Similar to Case 1: we conclude that the first half of xvy
starts with a's, and the second half too.
The case in which |y|>0 is analogous.
Exercise 2
One solution is represented by the following table for the transition function.
Columns are the symbols of the tape, rows are the states, and the three symbols
in each box represent the result of the transition. Empty positions correspond
to undefined results. D stands for "Delta" (i.e. blank). h is the halting state
\symbol
state\ a b c d A B X D
\_______________________________________________________________
| | | | | | | | |
0 | | | | | | | | D 1 R |
|_______|_______|_______|_______|_______|_______|_______|_______|
| | | | | | | | |
1 | A 2 R | B 4 R | | | | | X 1 R | D h S |
|_______|_______|_______|_______|_______|_______|_______|_______|
| | | | | | | | |
2 | a 2 R | b 2 R | X 3 L | | | | X 2 R | |
|_______|_______|_______|_______|_______|_______|_______|_______|
| | | | | | | | |
3 | a 3 L | b 3 L | | | A 1 R | | X 3 L | |
|_______|_______|_______|_______|_______|_______|_______|_______|
| | | | | | | | |
4 | | b 4 R | | X 5 L | | | X 4 R | |
|_______|_______|_______|_______|_______|_______|_______|_______|
| | | | | | | | |
5 | | b 5 L | | | | B 1 R | X 5 L | |
|_______|_______|_______|_______|_______|_______|_______|_______|