Beruflich Dokumente
Kultur Dokumente
1. C
2. D
3. D
4. C
5. B
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
c) To show that the strings aabb and aaab are in L(M), we trace a computation of M that accepts
these strings.
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:
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.
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)
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)
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
7.
a)
(a,e/A) (a,e/e)
(b,A/e) (b,e/e)
b)
(a,e/A) (a,e/e)
(b,A/e) (b,e/e)
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
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)
(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}
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