0% found this document useful (0 votes)
23 views

ct2 Sol

The document contains two questions about formal languages and automata theory. Question 1 asks to design a PDA with one state to accept a language and then convert it to an equivalent CFG. Question 2 asks to design a Turing machine to accept another language and describe its working using an example input string.

Uploaded by

aayushstudy2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

ct2 Sol

The document contains two questions about formal languages and automata theory. Question 1 asks to design a PDA with one state to accept a language and then convert it to an equivalent CFG. Question 2 asks to design a Turing machine to accept another language and describe its working using an example input string.

Uploaded by

aayushstudy2003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CS21004 Formal Languages and Automata Theory, Spring 2012–13

Class test 2

Maximum marks: 20 Date: 11-April-2013 Duration: 1 hour

Roll no: Name:

[ 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)

L1 = {α ∈ {a, b}∗ | #a(α) 6 #b(α)}

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:

a, S/AS ( All a’s must be matched, so push A’s )


a, A/AA ( whenever there are not surplus b’s so far )
a, B/ǫ ( One a matched with an earlier b )
b, S/BS ( This b is to be matched with an a )
b, B/BB ( This b is to be matched )
b, A/ǫ ( This b is to be matched )
b, S/S ( This b is not matched )
b, B/B ( This b is not matched )
b, A/A ( This b is not matched )
ǫ, S/ǫ ( The last move to empty the stack )

(b) Convert the PDA of Part (a) to an equivalent CFG. (4)

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:

L2 = {α ∈ {a, b, c}∗ | #a(α) 6 #b(α) 6 #c(α)}

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.

Initially |− c b c a b b c a c All the remaining tape cells are blank

After Pass 1 |− c b c a b b c a c −| The right end-marker is placed

After Pass 2 |− c b c b b c a c −| One a is erased

After Pass 3 |− c b b c a c −| One b and one c are erased

After Pass 4 |− c b b c c −| One a is erased

After Pass 5 |− b c c −| One b and one c are erased

After Pass 6 |− b c c −| No more a found

After Pass 7 |− c c −| One b erased

After Pass 7 |− c −| One c erased

After Pass 7 |− c −| No b found. Accept and halt.

— Page 2 of 2 —

You might also like