ct2 Sol
ct2 Sol
Class test 2
[ Write your answers in the question paper itself. Be brief and precise. Answer all questions. ]
1. (a) Design a PDA with only one state to accept the following language: (8)
Solution Let α ∈ L1 contain m a’s. The number of b’s in α would be m + n for some n > 0. The PDA matches m
a’s against m b’s, and ignores the remaining n b’s. However, m, n are not known a priori, so the machines
guesses them non-deterministically. This means that it makes a non-deterministic decision whether some b is
to be matched against an a or it would be ignored. Since the PDA has only one state, it would accept by empty
stack. We will let S denote the bottom marker for the stack. When the entire string is read from the input,
the bottom marker should be exposed. It is then popped out, and the machine accepts. We use two other stack
symbols A and B to indicate the excess of a’s and b’s (respectively) read so far. The PDA has the following
transitions:
Solution The above transitions can be mechanically converted to the following productions. Here, S is the start symbol.
S → aAS | bBS | bS | ǫ
A → aAA | b | bA
B → a | bBB | aB
— Page 1 of 2 —
2. Design a total Turing machine to accept the following language:
Briefly describe the working of the machine (how the head moves and rewrites tape cells). You may use the
example cbcabbcac for illustration. (8)
Solution The Turing machine M that we are going to design makes a to-and-fro motion along the tape, and erases
matching a’s with b’s and c’s, and then erases matching b’s with c’s. First, the machine puts a right end-marker
−| at the end of the input. It then goes to the left end-marker |−, and makes a first forward pass. It then moves
forward until it finds an a or encounters −|. If an a is found, the head moves back to the leftmost cell, and in
one (or two) forward movements attempts to erase one b and one c. If the attempt is unsuccessful, there are
more a’s than b’s or c’s, so M rejects (and halts). If all a’s are successfully erased, then a pass is used to erase
one b followed by another pass for erasing one c. If at some point a b is found but no c is left, the input contains
more b’s than c’s. M rejects and halts in that case. However, if all b’s are successfully erased, M accepts and
halts. The tape content after the different passes for the input cbcabbcac is shown below.
— Page 2 of 2 —