You are on page 1of 10

Answer for Exercises of Chapter 5 (Questions at Page 190, Introduction to Theory of Computer

Science: Definitions and Examples)

Part A Multiple Choices Questions

1. C
2. D
3. D
4. C
5. B

Part B Structured Questions

1.
a) The state diagram of M is
e, A/e
a, e/A e, A/e b, A/e

e, e/e
q0 q1 q2

b, A/e

b) (q0, aab, ) (q0, ab, A) (q0, b, AA) (q2, , A) (q2, , ) accept


(q0, abb, ) (q0, bb, A) (q2, b, ) reject
(q0, aba, ) (q0, ba, A) (q2, a, ) reject

c) To show that the strings aabb and aaab are in L(M), we trace a computation of M that accepts
these strings.

State String Stack


q0 aabb
q0 abb A
q0 bb AA
q2 b A
q2

State String Stack


q0 aaab
q0 aab A
q0 ab AA
q0 b AAA
q2 AA
q2 A
q2

Both of these computations terminate in the accepting state q2 with an empty stack.
d) The PDA M accepts the language {aibj | 0 j i}. Processing an a pushes A onto the stack. Strings
of the form ai are accepted in state q1. The transitions in q1 empty the stack after the input has
been read. A computation with input aibj enters state q2 upon processing the first b. To read the
entire input string, the stack must contain at least j As. The transition (q2, , A) = [q2, ] will pop
any As remaining on the stack.
The computation for an input string that has fewer as than bs or in which an a occurs after a b
halts in state q2 without processing the entire string. Thus strings with either of these forms are
rejected.

2.
a) (q0, a, ) = {[q0, A]}
(q0, b, ) = {[q0, B]}
(q0, , ) = {[q1, ]}
(q1, a, A) = {[q1, ]}
(q1, b, B) = {[q1, ]}
b) {wwR | w {a, b}*}.
c) The computations of ab in M are as follows:

State String Stack


q0 ab
q1 ab

State String Stack


q0 ab
q0 b A
q1 b A

State String Stack


q0 ab
q0 b A
q0 BA
q1 BA

The computations of abb in M are as follows:

State String Stack


q0 abb
q1 abb

State String Stack


q0 abb
q0 bb A
q1 bb A

State String Stack


q0 abb
q0 bb A
q0 b BA
q1 b BA
q1 A

State String Stack


q0 abb
q0 bb A
q0 b BA
q0 BBA
q1 BBA

The computations of abbb in M are as follows:

State String Stack


q0 abbb
q1 abbb

State String Stack


q0 abbb
q0 bbb A
q1 bbb A

State String Stack


q0 abbb
q0 bbb A
q0 bb BA
q1 bb BA
q1 b A

State String Stack


q0 abbb
q0 bbb A
q0 bb BA
q0 b BBA
q1 b BBA
q1 BA

State String Stack


q0 abbb
q0 bbb A
q0 bb BA
q0 b BBA
q0 BBBA
q1 BBBA

d) State String Stack


q0 aaaa
q0 aaa A
q0 aa AA
q1 aa AA
q1 a A
q1

State String Stack


q0 baab
q0 aab B
q0 ab AB
q1 ab AB
q1 b B
q1

e) To show that the string aaa and ab are not in L(M), we trace all computations of these strings
in M, and check whether none of them accepts these strings. We have listed all the
computations of ab in (b), and none of them accepts it. Now we trace all computations of aaa
in M.

State String Stack


q0 aaa
q1 aaa

State String Stack


q0 aaa
q0 aa A
q1 aa A
q1 a

State String Stack


q0 aaa
q0 aa A
q0 a AA
q1 a AA
q1 A

State String Stack


q0 aaa
q0 aa A
q0 a AA
q0 AAA
q1 AAA
Since none of the computations above is accepted, we have aaa is not in M.

3.

(, )
q0 q2
(b, A)
(a, ) (a, A) (b, )

q1 q4 q3

(b, )
a) or
b)
(a,eX)
(b,eY)
(c,Y/e)
(d,Xe)

(a,eX) (b,eY) (c,Y/e) (d,Xe)


(b,eY) (c,Y/e) (d,Xe)
c)
d)
(a,eX)
(b,Xe)
(c,eY)
(d,Y/e)

e)
(a,eX) (b,Xe) (c,eY) (d,Y/e)
(b,Xe) (c,eY) (d,Y/e)

f)
(a,eX) (b,eX) (c,X/e) (d,Xe)
(b,eX) (c,X/e) (d,Xe)

g)
(b,ae) (c,ee)
(e,$/e)
(e,ee)
(a,ea) (b,ee) (c, ae)
(e,ee) (e,ee) (e,$/e)
(e,e$)
e, $/e
a, e/A
b, A/e
q2 q3 q8
a, e/A e, A/e
b, $/$
e, e/$ e, e/A
(a /A) q1 q4 q5
(a B/)
q0 e, $/e
(b AA/) e, e/B
(b /BB) a, $/$
(b A/B) b, e/B e, e/B
q6 q7

q1 b, e/B a, B/e
h) or
(a /A)
(b A/)
(b /B)
(a B/)

q1
i)
j)
b, Xe
e, eX (a, eX b, Xe (a, eX b, ee

e, eX b, Xe e, ee
q0 q1 q2 q0 q1
or
k)
(a,ea) (c,ee) (b, ae)
(e,ee) (e,ee)
q0 q1 q2
l)
(a,e/A) (b,A/e) (b,e/) (c /e)

(a, e) (b,A/e) (b,e/) (c /e)


q0 q1 q2 q3 q4
or
(b,A/e)
(a,e/A) (b,e/B) (c B/e)
(e,e/e) (e,e/e)
q1 q2 q4

m)
a, A b, A

(, )
q1 q2
(, )

q0 q3
a,
(, )
q4
b,
n)
(a,e/a) (b,a/e)
(c,e/e)
(e,e/e) (e,e/e)
q1 q1 q3
(e,e/e)

q0 (a,e/e) (b,e/b)
(c,b/e)
(e,e/e) (e,e/e) (e,e/e)
q2 q2 q4

o)
(a,eA) (b,Ae) (b,ee)
(e,ee) (b,ee)
q0 q1 q2

(e, Ae)

q3
(e, Ae)
p)
(a,e) (b, Ae)
(a,e)
q0 q1 q2
e, e/A
e, e/e
(b, Ae)

q3

q)
(a,e/A) (b,A/e) (c, /e)

(e,ee) (e,ee)
q0 q1 q2

r)
a /A a A/
b /B / b B/
a /
b /
q0 q1

4.
(a,e/A) (a,A/e)
(b,e/B) (b,B/e)
(c,e/C) (c,C/e)

(d,e/e)
q0 q1 q2

5. Give the state diagram of a PDA M that accepts {a2ibi+j| 0 j i} with acceptance by empty stack.
Explain the role of the stack symbols in the computation of M. Trace the computations of M with input
aabb and aaaabb.

6. The machine M
a, A b, A

b, A
q0 q1

accepts the language L = {aibi | i 0} by final state and empty stack.


a) Give the state diagram of a PDA that accepts L by empty stack.
b) Give the state diagram of a PDA that accepts L by final state.

7.
a)
(a,e/A) (a,e/e)
(b,A/e) (b,e/e)

(e,e/B) (b, B/e)


q0 q1 q2

b)
(a,e/A) (a,e/e)
(b,A/e) (b,e/e)

(e,e/B) (b, B/e)


q0 q1 q2

8. Let L = {a2ibi | i 0}.


a) Construct a PDA M1 with L(M1) = L.
b) Construct an atomic PDA M1 with L(M2) = L.
c) Construct an extended PDA M3 with L(M3) = L that has fewer transitions than M1.
d) Trace the computation that accepts the string aab in each of the automata constructed in (a), (b),
and (c).

9. Let L = {a2ib3i | i 0}.


a) Construct a PDA M1 with L(M1) = L.
b) Construct an atomic PDA M2 with L(M2) = L.
c) Construct an extended PDA M3 with L(M3) = L that has fewer transitions than M1.
d) Trace the computation that accepts the string aabbb in each of the automata constructed in (a),
(b), and (c).

10.
a) This language accepts the strings which start with a and followed by b. The number of bs is
double than as.
b)
(a,e)
(b,Ae) (b,ee)
q0 q1 q2

(b,Ae)
n 2n
c) L = { a b | n > 0}
d) S aSbb | aAbb
A
e) (q0, aabbbb, ) (q0, abbbb, A) (q0, bbbb, AA) (q1, bbb, A)
(q2, bb, A) (q1, b, ) (q2, , ) accept

f) S aSbb aaSbbbb aaAbbbb aabbbb

11.
a) (q0, bbcbb, ) (q0, bcbb, A) (q0, cbb, AA) (q1, bb, AA)
(q1, b, A) (q1, , ) accept

b) S aS | bS | cA
A aA | bA |
c) S bS bbS bbcA bbcbA bbcbbA bbcbb bbcbb

12. a)
(0,e,X) (1,X,e)
(1,X,e)
q0 q1

b)
(0,e,X) (1,X,e)
(1,X,e)
q0 q1

13. a) (q0, aaabbb, ) (q0, aabbb, A) (q0, abbb, AA) (q0, bbb, AAA)
(q1, bb, AA) (q1, b, A) (q1, , ) accept

b) (q0, abb, ) (q0, bb, A) (q1, bb, A) (q1, b, ) reject


14.
a)
(a,eX) (b,X/e) (c,X/e) (e,Xe)
(e,ee) (e,ee) (e,Xe)
q0 q1 q2 q3

b)
(e,eX) (a,eX) (b,X/e) (c,Xe)
(e,eX) (e,ee) (e,ee)
q0 q1 q2 q3

15. a)
CFG : S XC | AY
X aXb |
C cC |
A aA |
Y bYc |

b)
(a,e/a)
(b,a/e)
(c,e/e)
(e,e/e)
q1 q3
(e,e/e)

q0 (a,e/e)

(e,e/e) (e,e/e)
q2 q4
(b,e/b)
(c,b/e)

16.
On seeing a ( push it on the stack
On seeing a ) pop a ( from the stack
If attempt to pop an empty stack, reject
If stack not empty at the end, reject
Else accept
OR
First push a bottom-of-the-stack sysmbol $ and move to q0
On seeing a ( push it onto the stack
On seeing a ) pop if a ( is in the stack
Pop $ and move to final state qf
,e/(

e, e/$ e, $/e
q0 q qf

), (/e
5 Push-down
Automata

17.
a)
S aABA | aBB (q0, a, )= {[q0, ABA], [q1, BB]}
A bA | b (q1, b, A)= {[q1, A], [q1, ]4}
B cB | c (q1, c, B)= {[q1, B]5, [q1, ]6}

b) Draw the PDA machine M that accept L(G).

M: Q = {q0, q1}
= {a, b, c}
= {A, B}
F = {q1}
(q0, a, ) = {[q0, ABA] }
(q0, a, ) = { [q1, BB] }
(q1, b, A) = {[q1, A] }
(q1, b, A) = {[q1, ] }
(q1, c, B) = {[q1, B] }
(q1, c, B) = {[q1, ]}

18.

(i) c
(ii) i
(iii) k
(iv) j
(v) e
(vi) g
(vii) a
(viii) h
(ix) f
(x) b
(xi) d

164 | P a g e

You might also like