UNIT – I
AUTOMATA
PART – A
1 Define proof by contra positive and induction principle It is the other form of If then statement. The contra positive of the statement „‟If H then C „‟ is „‟If not C then not H‟‟ Induction Principle If S(i) is true for n = i ,then it is to be proved that for all n > i , S(n) implies S(n+1) then S(n) is true for all n ≥ i
2 Define Pumping lemma for regular language. Let L be a regular language. Then there exists a constant n such that for every string w in L ,w>n, z = uvw such that (i)uv<n, v>0 then uv ^{i} w L for all i.
3 State Arden’s theorem. Let P and Q be two regular expressions over _{} . If P does not contain null string _{} over _{} then R=Q+RP, it has the solution R=QP ^{*} .
4 Prove that L = { 0 ^{n} 1 ^{2}^{n} / n 1} is not regular. Let z = uvw = 0 ^{n} 1 ^{2}^{n} , let v = 1 ^{m} ,u = 0 ^{n} ,w = 1 ^{2}^{n}^{}^{m} uv ^{i} w = 0 ^{n} 1 ^{m}^{i} 1 ^{2}^{n}^{}^{m} ,let I = 0 , then uw =0 ^{n} 1 ^{2}^{n}^{}^{m} L. Therefore L is not regular.
5 Write RE which denotes the language L over the set = {a,b} such that all the strings do not contain the substring ab. RE = (b ^{*} a ^{*} ).
6 Write regular expressions for the following. (i)Binary numbers that are multiple of 2. (0/1)*.
(ii)Strings of a‟s and b‟s with no consecutive a‟s consecutive a‟s. (a/b) ^{*} aa(a/b) ^{*} .
.b ^{*} (abb ^{*} )(a / ) (iii) Strings of a‟s and b‟s containing
7 How a Non deterministic finite state automaton (NFA) differs from a Deterministic finite state automaton (DFA). Solution:
DFA 
NFA 

On each input there is one and only one stae to which the automaton move from its current state 
On each input the automaton can be in several states at once 

Next state is completed by determining current state and current symbol 
The state is only partially determined by the current state and current input symbol 

The transition function returns only one state.(i.e) : Q X Q 
The transition function returns zero, one or more 

states.(i.e) 
_{} 
: Q 
X 

2 
Q 
_{8} Define the languages described by DFA and NFA. L(DFA) = { w / δ‟(q _{0} ,w) is in F}.It is the set of strings w that take the start state q _{0} to one of the accepting states. L(NFA)= { w / δ‟(q _{0} ,w)∩F≠}.It is the set of strings w such that δ‟(q _{0} ,w)contains at least one accepting state.
9 Define extended transition function for a DFA. The extended transition function δ‟: Q∑ ^{*} Q is defined as follows.
(i)
δ’(q, ε
) = q
(ε  Empty)
(ii)Suppose w is a string of form xa(w= xa), w∑ ^{*} and qQ , then δ’(q, w)= δ( δ’(q, x),a)
10 Define extended transition function for a NFA.
The extended transition function δ‟: Q∑ ^{*} 2 ^{Q} is defined as follows.
(i) δ’(q,
ε ) = {q}
(ii) Suppose w is of the form xa where a is the final symbol of w and x is the rest of w.
δ’(q,x)= {p _{1}_{,} p _{2}_{,} p _{3}
p _{k} }
k
U
i=1
δ(p _{i} ,a) = {r _{1}_{,} r _{2}_{,} r _{3}_{,}
Therefore δ‟(q,w) ={r _{1}_{,} r _{2}_{,} r _{3}_{,}
r _{m} }
r _{m} }
11 Define extended transition function for a NFA.
The extended transition function δ‟: Q∑ ^{*} 2 ^{Q} is defined as follows.(i) δ‟(q, λ) = {q} (ii)For any
w∑ ^{*} , a∑ and qQ , δ‟(q, wa ) =
δ( q,a).
p δ‟(q, y)
12 Define  closure of a state.
The set of all states reachable from a given state q using λ transitions only. We use λclosure to denote the set of all vertices p such that there is a path from q to p labeled λ.
13 Find the  closure of states 1, 2 and 4 in the following transition diagram.
 closure(1) = {1,2,4,3,6}, closure(2) = {2,3,6}, closure(4) = {4}.
14 Define regular expression and give an example. The language accepted by finite automata are easily described by simple expression called regular
expression Example :
( 0
10 )
*
11 ( 0
01 )
*
15 Construct a finite state machine that accepts exactly those input strings of 0’s and 1’s that ends with
“11”
_{1}_{6} Give a regular expression for the set of all strings having odd number of 1’s RE= 1(0+11)*
17
Construct a DFA for the language L = { a ^{n} b , n ≥ 0}.
19 Give the regular expression for the set of all strings ending in 00.
Regular expression = (0+1) ^{*} 00
20 When two states are equivalent and distinguishable?
We say that two states p and q are equivalent iff for each input string x , δ(p,x) is an accepting state iff δ(q,x) is an accepting state. p is distinguishable from q if there exists an x such that δ(p,x) is in F and v is not in F or vice versa.
21 What are the applications of regular expression?
Regular expression in UNIX, Lexical analysis, Pattern searching
22 Is it true that the language accepted by any NFA is different from the regular language?.Justify your answer. No. Any language accepted by DFA,NFA,NFA is called a regular language. For any finite automaton we can construct an equivalent regular expression and the language represented by regular expressions is a regular language.
23
Prove that
R= Q+RP = Q+(Q+RP)P=Q+QP+QP ^{2} +QP ^{3} + = Q(1+P+P ^{2} +P ^{3} +) =Q( _{} + P+P ^{2} +P ^{3} +)=QP ^{*}
Q+RP= QP ^{*}
Part –B
1.
A) State and prove the pumping lemma for regular languages
Statement: Let
.Language L is accepted by M .Let L and n, then can be written as xyz ,where
L be regular language and M = (Q ,, ,q _{0} ,F) be a finite automata with nstates
i) 
y 1 (ii)xy n (iii) xy ^{i} z L for all i 0 here y ^{i} denotes that y is repeated or pumped i 
ii) 
times. Proof: 
Suppose L is a regular language. and M be a DFA with n states ,such that DFA accepts
the given
regular language L.(i.e) is L =L(M), language of M is same as the given
regular language .Consider a string L and n, string can be written as a _{1} a _{2} _{…} a _{m} with m n Let us assume that states of M are given by q _{0}_{,} q _{1}_{,} q _{2}_{,}_{…}_{.} q _{n}_{}_{1} with q _{0} as the starting state and q _{n}_{}_{1} as final state .After feeding the first i characters of the word = a _{1} a _{2} _{…} a _{m} machine will be in a state r _{i} . ^{*} ( q _{0} _{,} a _{1} a _{2} _{…} a _{i} ) = r _{i} _{.} As the word is fed through the machine M ,the machine will go
through the various states as;q _{o}
possible for the machine to move through distinct states
There is a loop from r _{i} to rj.The string can be divided into three parts. i)x = portion before loop = a _{1} a _{2} _{…} a _{m}
r _{1} r _{2} …… r _{m}_{}_{1} q _{n}_{}_{1}_{,} since the length of _{.} and n it is not
Let
us assume that r _{i} and r _{j} are same.
ii)y 
= 
portion of the loop = a _{i}_{+}_{1} a _{i} _{+}_{2} _{…} a _{j} 
iii) 
z 
= portion of the loop = a _{j}_{+}_{1} a _{j} _{+}_{2} _{…} a _{m} .Since y is a portion relating to loop, it can repeat any 
number of times.
B) Using pumping lemma for regular sets. Prove that the language L = {a ^{n} b ^{n}
/n1} is not regular
L = {a ^{n} b ^{n} /n1} is not regular.
let us assume that L is regular and L is accepted by a FA with n states;
(i) Let us choose the string = a ^{n} b ^{n} _{,}
= 2n n. Let us write as xyz, with
(ii)y 0 and xy n. since
xy n,y must be of the form a ^{r} for some r 0 since xy n, x
must be of the form a ^{s} .Now , a ^{n} b ^{n}
can be written as
a ^{s} a ^{r} a ^{n}^{}^{s}^{}^{r} b ^{n} .let us check whether xy ^{i} z for some i = 2 belongs to L.
_{x}_{y} ^{2} _{z} _{=} _{a} ^{s} _{(}_{a} ^{r} _{)} ^{2} _{a} ^{n}^{}^{s}^{}^{r} _{b} ^{n} _{=} _{a} ^{n} ^{+}^{r} _{b} ^{n}
, r 0,number of a‟s in a ^{n} ^{+}^{r} b ^{n}
is greater than number of
b‟s. Therefore, xy ^{2} z L.Hence by contradiction, therefore the given language is not regular.
2. Obtain the regular expression that denotes the language accepted by
, Using the recursive relation.
Recursive relation : R
Step:1 Find R _{i}_{j} ^{(}^{o}^{)} where k=0 R _{1}_{1} ^{(}^{0}^{)} =ε , R _{1}_{2} ^{(}^{0}^{)} =0, R _{1}_{3} ^{(}^{0}^{)} =1, R _{2}_{1} ^{(}^{0}^{)} =0, R _{2}_{2} ^{(}^{0}^{)} = ε, R _{2}_{3} ^{(}^{0}^{)} = 1, R _{3}_{1} ^{(}^{0}^{)} = φ
ij (k) _{=} _{R} ij (k1) _{+} _{R} ik (k1) _{(} _{R} kk (k1) _{)}_{*} _{R} kj (k1)
R _{3}_{2} ^{(}^{0}^{)} =0 +1, R _{3}_{3} ^{(}^{0}^{)} = ε.
Sept:2 Find
R _{i}_{j} ^{(}^{1}^{)} where k=1 ,here n=3 recursive relation becomes
_{R}
11 (1) _{=} _{R} 11 (0) _{+} _{R} 11 (0) _{(} _{R} 11 (0) _{)}_{*} _{R} 11 (0)
_{R} _{1}_{1} ^{(}^{1}^{)} _{=}_{ε} _{,}
_{R} _{1}_{2} ^{(}^{1}^{)} _{=}_{0}_{,}
_{R} _{1}_{3} ^{(}^{1}^{)} _{=}_{1}_{,} _{R} _{2}_{1} ^{(}^{1}^{)} _{=}_{0}_{,} _{o} _{R} _{2}_{2} ^{(}^{1}^{)} = ε+00, R _{2}_{3} ^{(}^{1}^{)} = 1+01, R _{3}_{1} ^{(}^{1}^{)} = φ
R _{3}_{2} ^{(}^{0}^{)} =0 +1, R _{3}_{3} ^{(}^{0}^{)} = ε.
We have to prove the result is true for n=k+1
1 ^{2} +2 ^{2} +3 ^{2} +……+ k ^{2} +(k+1) ^{2} = = (k(k+1)(2k+1))/6 + (k+1) ^{2}
Step:3 Find
R ^{(}^{2}^{)} where k=2 ,here n=3 recursive relation becomes
ij
11 (1) _{+} _{R} 12 (1) _{(} _{R} 22 (1) _{)}_{*} _{R} 21 (1)
R _{1}_{1} ^{(}^{2}^{)} = R
R _{1}_{1} ^{(}^{2}^{)} =(00)* , R _{1}_{2} ^{(}^{2}^{)} =0(00)*, R _{1}_{3} ^{(}^{2}^{)} =0*1, R _{2}_{1} ^{(}^{2}^{)} =0(00)*, R _{2}_{2} ^{(}^{2}^{)} = (00)*, R _{2}_{3} ^{(}^{2}^{)} = 0*1, R _{3}_{1} ^{(}^{2}^{)} = (0+1)(00)*0, R _{3}_{2} ^{(}^{2}^{)} =(0+1)(00)*, R _{3}_{3} ^{(}^{2}^{)} = ε+(0+1)0*1 In our example the set of final state F={q _{2}_{,} q _{3} } L(M)=R _{1}_{2} ^{(}^{3}^{)} +R _{1}_{3} ^{(}^{3}^{)} where n=3 Hence the regular expression is RE=0*1((0+1)0*1)*(0+1)(00)*+0(00)*
3. A) Prove that 1 ^{2} +2 ^{2} +3 ^{2} +……+ n ^{2} = ∑n ^{2} = (n(n+1)(2n+1))/6.
Proof: Prove by induction. Base step: for n=1 L.H.S =1
and R.H.S=1(2)(3)/6=1
Inductive step : Assume the result is true for n=k 1 ^{2} +2 ^{2} +3 ^{2} +……+ k ^{2} = ∑k ^{2} = (k(k+1)(2k+1))/6. = ((k+1)(k+2)(2k+3))/6 hence it is proved for all values of n
………… B) Prove that for every integer n≥0 the number 4 ^{2}^{n}^{+}^{1} + 3 ^{n}^{+}^{2} is multiple of 13 Proof by induction .Base step: n=0 L.H.S = 4 ^{1} +3 ^{2} =4+9=13 = R.H.S Induction : n=k the result is true: 4 ^{2}^{k}^{+}^{1} +3 ^{k}^{+}^{2} =13 k = 13 x for some integer x
Assume that the result is true for n= k+1. 4 ^{2}^{(}^{k}^{+}^{1}^{)}^{+}^{1} + 3 ^{k}^{+}^{1}^{+}^{2} = 13 (k+1) = 13 x for some integer
x………
= 13(3x+4 ^{2}^{k}^{+}^{1} )=13x hence it is proved.
4. Design FA which accepts even number of 0’s and even no of 1’s. M = (Σ,Q,δ,q _{0}_{,} F) Σ={0,1},
Q = { q _{0} , q _{1}_{,} q _{2} ,q _{3} }, F= { q _{0} } Transition table is given below

0 
1 

*q _{0} 
q 
2 
q 
1 

q 
1 
q 3 
q 
0 

q 
2 
q 
0 
q 3 

q 
3 
q 
1 
q 
2 
5. Show that if L be a set accepted by an NFA then there exists a DFA that accepts L
For each state [q _{1}_{,} q _{2} _{…} q _{i} ]
in Q ^{1} the transitions for each input symbol can be obtained as
(a) ^{1} ([q _{1}_{,} q _{2}
_{…} q _{i}
] , a ) = ( q _{1}_{,} a) ( q _{2}_{,} a) ………( q _{i}_{,} a)
= [q _{1}_{,} q _{2} _{…} q _{k} ]Add the state [q _{1}_{,} q _{2} _{…} q _{k} ] to DFA if it is not already added in Q ^{1}
(b)Then find the transitions for input symbol from for state [q _{1}_{,} q _{2} _{…} q _{k} ].If we get some state [q _{1}_{,} q _{2} _{…} q _{k} ].which is not in Q ^{1} of DFA then add this state Q ^{1} . ©If there is no new state generating then stop the process after finding all the transitions. (d)The state [q _{1}_{,} q _{2} _{…} q _{n} ] Q ^{1} of DFA if any one state q _{i} is a final state of NFA then [q _{1}_{,} q _{2} _{…} q _{n} ] becomes a final state . The final state is F ^{1} of DFA.
6. Convert an NFA to a DFA given NFA M = (Σ,Q,δ,q _{0}_{,} F) Σ={0,1},
Q = { q _{0} , q _{1}_{,} q _{2} ,q _{3} },F= { q _{0} },

0 
1 

q 
0 
{ q _{0} } 
{ q _{0}_{,} q _{1} } 
q 
1 
{ q _{2} } 
{ q _{2} } 
q 
2 
{ q _{3} } 
{ q _{3} } 
q
3
Ø
ø
Soltion: L(M)= ( 0
1)
*
1( 0
1)
( 0
1)
7.
M _{1} = (Σ _{1} ,Q _{1} ,δ _{1} ,q _{1}_{,} F _{1} ) ,Σ={0,1},Q _{1} = 2 ^{Q} Transition table is given below
, q _{1} = q _{0}_{,}
F _{1} = { q Q _{1} / q∩F≠ ø }, δ _{1} (q _{1}_{,} a)=Ụ δ(p,a)

0 1 

q 
0 
{ q _{0} } 
{ 
q _{0}_{,} q _{1} } 

{ q _{0}_{,} q _{1} } 
{ q _{0}_{,} q _{2} } 
{ 
q _{0}_{,} q _{1} ,q _{2} } 

{q _{0}_{,} q _{2} } 
{ q _{0}_{,} q _{3} } 
{ 
q 0, q 1, q 3 } 

{q _{0}_{,} q _{1} ,q _{2} } 
{ q 0, q 2, q 3 } 
{ 
q 0, q 1, q 2, q 3 } 

{ 
q _{0}_{,} q _{3} } 
{ q _{0} } 
{ 
q _{0}_{,} q _{1} } 

{q 0, q 1, q 3 } 
{ q _{0}_{,} q _{2} } 
{ 
q _{0}_{,} q _{1} ,q _{2} } 

{q 0, q 2, q 3 } 
{ q _{0}_{,} q _{3} } 
{ 
q 0, q 1, q 3 } 

{q 0, q 1, q 2, q 3 } 
{ q 0, q 2, q 3 } 
{ 
q 0, q 1, q 2, q 3 } 


0 
1 

q 
0 
{ q _{0}_{,} q _{1} } 
q 0 

q 
1 
q 
2 
q 1 

q 
2 
q 
3 
q 3 

*q _{3} 

q 2 
Convert the given NFA to DFA
New DFA M _{1} = (Σ _{1} ,Q _{1} ,δ _{1} ,q _{1}_{,} F _{1} ) ,Σ={0,1},Q _{1} = 2 ^{Q} , q _{1} = q _{0}_{,} F _{1} = { q Q _{1} / q∩F≠ ø }, δ _{1} (q _{1}_{,} a)=Ụ δ(p,a) Transition table is given below

0 
1 

q 
0 
{ 
q _{0}_{,} q _{1} } 
q 
0 

q 
1 
q 
2 
q 
1 

q 2 
q 
3 
q 
3 

q 3 

q 
2 

{ q _{0}_{,} q _{1} } 
{ 
q 0, q 1, q 2 } 
{ 
q _{0}_{,} q _{1} } 

{ q 0, q 1, q 2 } 
{ 
q 0, 
q 1, q 2, q 3 
} 
{ 
q 0, q 1, q 3 } 

{ } q 0, q 1, q 3 
{ 
q 0, q 1, q 2 } 
{ 
q 0, q 1, q 2 } 

{ q 0, q 1, q 2, q 3 
} 
{ 
q 0, 
q 1, q 2, q 3 
} 
{ 
q 0, 
q 1, q 2, q 3 
} 
8. Compute closure (ii) Convert the automaton to a DFA
ε
a
b
c
P 
{ ф} 
{p} 
{q} 
{r} 
q 
{p} 
{q} 
{r} 
{ ф} 
r 
{q} 
{r} 
{ ф} 
{p} 
Solution: closure (p)={p,q,r},closure (q)={q}, },closure ( r )={r} Construction of DFA Transition table is given below M _{d} =(q _{d} ,, _{d} ,q _{0} ,F _{d} )

d 
a 
b c 

r 



{q,r} 
{p,q,r} 
{r} 
{p,q,r} 

{p,q,r} 
{p,q,r} 
{q,r} 
{p,q,r 





1
2
4
5
6
3
UNIT  II
PARTA
Let G = Sol:
s , c, a , b, P , s where P consists of S
aca , C
aca
/ b ,Find L(G).
Sacaaacaaaaacaaa( caca)…
a
^{i} ca ^{i} a ^{n} ca ^{n} a ^{n} ba ^{n} (cb)
L(G) = a
Find L(G),where G = s, 0 ,1, s 0 s1, s , s Sol: S _{} 0s1 00s11( s0s1)… 0 ^{n} s1 ^{n} 0 ^{n} 1 ^{n} . Hence L(G) = s _{} _{0} _{1} _{/} _{n} _{} _{0}_{}
What is Chomsky Normal form? Chomsky Normal form:i)NT T. set of NT, ii) NTT Where, NT Non terminal, T terminal
Find L(G),where P consists of S asb , s ab .
Sol: S asb
n
b
a
n
/n
0
n
n
aasbb
aaasbbb
*
a
n
b
n
…
_{H}_{e}_{n}_{c}_{e}
_{L} _{=} s a b
n
n
/ n
1
.
Let G =(S,C,a,b ,P,S) where P consist of SaCa, CaCa / b .Find L(G) Solution:SaCaaaCaa ….a ^{n} ba ^{n} .Thus L(G) = a ^{n} ba ^{n} / n ≥1.
Convert the following grammar G in GNF form S ABb / a , A aaA / B , B bAb Solution:
A
aXA ,
X
a , _{Y}
_{} _{b} .The rule for Bwill be B baY ,
Now convert the rule for S to GNF.
S 
aXABY 
/ bAYBY 
/ a , 
S aXABY 
/ bAYBY 
/ a , _{A} _{} _{a}_{X}_{A} _{/}_{b}_{A}_{Y}_{,} X a , _{Y} _{} _{b} _{.} 
7
8
9
10
11
Define a derivation tree for a CFG. A derivation tree for a CFG G = (V,T,P,S)is a tree satisfying the following:
a)Every vertex has a label which is a symbol of VT
vertices must be in V (d) If n has a label ‟ a‟ and vertices n _{1}_{,} n _{2}_{,} n _{3}_{,} n _{4}_{,}_{…}
from the left with label
in P
What are the closure properties of context free Language? CFL is closed under union, concatenation and Klee closure .CFL is also closed under substitution,
homomorphism.CFL is not closed under intersection, complementation. CFL‟s are used to prove that certain languages are not context free.
.b)The label of the root is S c)the internal
n _{k} are sons of the vertex n ,in order
X _{1}_{,} X _{2}_{,} X _{3}_{,} X _{4}_{,}_{…} X _{k} respectively. Then A
X _{1}_{,} X _{2}_{,} X _{3}_{,} X _{4}_{,}_{…} X _{k} must be a production
(e) If vertex n has label λ
then n is a leaf and is only son of its father.
The closure properties of
Let G = s , c, a , b, P , s,P = S asb / a , A
aabbaa. Soln: SaASaSbASaabASaabbaSaabbaa .
Show that id+id*id can be generated by two distinct leftmost derivation in the grammar EE+E/ E*E/ (E)/id Soln : i)EE+E id+E id +E*E id +id*E id +id*id
SbA / ss / ba .Find a derivation tree whose yield
ii)EE*EE+E*Eid+E*Eid+id*Eid+id*id.thereforeid+id*id can be generated by two distinct LMD .Thus it is ambiguous.
Let G = (N,T,P,S), P = S A1 B / a , A 0 A / , B 0 B / 1 B / give a leftmost and rightmost derivation for the string 00101.
Soln: SA1B0A1B00A1B001B0010B00101B00101(LMD) SA1BA10BA101B A1010A10100A10100101 (RMD) Therefore the given grammar is ambiguous.
^{1}^{2} Write CFG for L(G) = a
_{S}_{o}_{l}_{n}_{:}_{P}_{=} _{} _{S}
asc
/ bpc , s
m
b
n
c p 
/ 
m n 
p , 
p 

ac 
/ bc , p 

bc _{} _{.} 
1
.
13 Is context free language is closed under complementation? Justify. Proof: Let L _{1} & L _{2} are the two CFLs. Assume that complement of a CFL is a CFL itself. Hence L ^{„} _{1} &L ^{„} _{2}
is a CFL,(by rule)but L ^{„} _{1} L ^{„} _{2} = L _{1} ∩ L _{2} which may or may not be
CFL. The L _{1} & L _{2} are arbitrary CFLs, there may exist L ^{„} _{1} &L ^{„} _{2} which are not CFL. Hence the complement of certain language may or may not be CF. Therefore, we can say that CFL is not closed
both are CFLs, thus L ^{„} _{1} L ^{„} _{2}
under complement operation.
14 _{F}_{i}_{n}_{d} _{L}_{(}_{G}_{)} _{f}_{o}_{r} _{C}_{F}_{G} _{S} asb
/ aAb
, A
Soln: S asb
Hence
L = a
aasbb
n
b
m
a
m
b
n
*
a
/ m , n
n
sb
n
1
.
bAa 
, A 
ba . 

a n aAbb 
n 

a 
n 
abAabb 
n
*
a
n
b
m
a
m
b
n
15 Find the derivation tree for the grammar, G = s , A , B , a , b, P , s,where
_{P} _{=} _{}_{S}
bA
/ bB , A
ab , B
aBb
/ a _{}
16 Define Parse diagram. A data structure to represent the source program in a compiler is called Parse diagram(tree).A Parse diagram can have nodes and edges.
17 What are the two major normal forms for context –free grammar? a)Chomsky Normal form b) Greibach Normal form
18 Consider the CFG G={V,T,S,P} Remove useless symbol
Answer: 
S 11 A  11 
A 0 
19 Eliminate the production from the CFG given below A 0 B 1  1 B 1 B 0 B  1 B 
Answer:
B 0 B  1 B  0 1
A 0 B 1  1 B 1  01 11
20 If the CFG is as below S 0A  1B C A 0S 00 B1  A
C 01 
then remove the unit productions. 
Answer: 
S 0A  1B  01 
A 0S 00 B1  0S 00 C 01
1 _{(}_{i}_{)} _{S}_{h}_{o}_{w} _{t}_{h}_{a}_{t} _{t}_{h}_{e} _{g}_{r}_{a}_{m}_{m}_{a}_{r} S a / abSb a) S abSb abaAbb ababSbb abababb
PART  B
/ aAb
, A
bs / aAAb
b) S aAb abSb ababSbb abababb
(ii) Consider the following productions
_{i}_{s} _{a}_{m}_{b}_{i}_{g}_{u}_{o}_{u}_{s}_{.}
S aB / bA 

A aS / bAA 
/ 
a 
for the string aaabbabbba, find leftmost derivation. 
B bS / aBB 
/ 
b 
S aB aaBB aaaBBB aaabBB aaabbSB aaabbaBB aaabbabB aaabbabbS aaabbabbbA aaabbabbba
2 (i)Find a grammar in Chomsky normal form equivalent to
S
AB
/ aB
, A
aab
/ , B
bbA
form.
Step1:Eliminate productions, Null able symbols = {A} After elimination productions, we get a set of productions P _{1}
P
1
S
A
B
AB
aaB
bbA
/
B
/
/
bb
aB
Step:2Elimination of the unit production _{S} _{} _{B} .the equivalent set of productions is given as P _{2}
P
2
S
A
B
AB
aab
bbA
/
bbA
/
bb
/
bb
/
aB
Step:3 Every symbol is , in a production of the form _{S} _{} _{} with ≥2 should be a variable. This can be done by adding the two two productions _{C} _{} _{a} _{C} _{} _{b} The equivalent set is represented as P _{3}
1
,
2
P
3
S
A
B
AB
C
C
2
1
/
C
C
1
C
B
2
2
A
C
/
2
C
A
2
/
C
C
2
,
2
C
C
1
2
/
C
1
a
B
,
C
2
b
Original production 
Equivalent production in CNF 

S 
AB 
S 
AB 

S 

C 
2 
C 
2 
A 
S 
C 
2 
C 
3 
, C 
3 
C 
2 
A , 

S 

C 
2 
C 
2 
/ 
C 
1 
B 
S 

C 
2 
C 
2 
/ C 
1 
B 

A 

C 
1 
C 
1 B 
A 

C 
1 
C 
4 
, C 4 

C 
1 
B 

B 
C 
2 
C 
2 
A 
, C 
1 a 
B 
C 
2 
C 
3 
, C 
1 
a 

B 
C 
2 
C 
2 
, 
C 
2 
b 
B 
C 
2 
C 
2 
, C 
2 
b 
(ii) Obtain the Greibach Normal form
Step:1 The given grammar there is no null production or unit production
Step:2 Every production of the form
roduction A _{1} A _{2} A _{3}_{,} A _{2} A _{3} A _{1} / b _{,} A _{3} A _{2} A _{3} A _{2} / b Step:3 Since the right side of the production
A _{3} A _{2} A _{3} A _{2} begins with a lower numbered variable substitute A _{2} in A _{3} the resulting production are
A _{1} A _{2} A _{3}_{,} A _{2} A _{3} A _{1} / b _{,} A _{3} A _{3} A _{1} A _{3} A _{2} / b A _{3} A _{2} /a
Step :4 the new symbol B is introduced in A _{3} to derive the first symbol as a terminal strings as per lemma
2 GNF the resulting production (After simplification) A _{1} a A _{1} A _{3}_{,} bA _{3} A _{2} A _{1} A _{3} , b A _{3}_{,} b A _{3} A _{2} B _{3} A _{1}
A _{3} Similarly we can derive A _{2}_{,} A _{3} _{,} B _{3} in GN F form.
A _{1} A _{2} A _{3}_{,} A _{2} A _{3} A _{1} / b _{,} A _{3} A _{1} A _{2} / a
A
i
A
j
with I >j must be modified to make i≤j.The resulting
3
Construct a grammar in GNF which is equivalent to the grammar
S
AA
/ a , A
SS
/ b
We can proceed for renaming of variables , variables S and A are renamed as A _{1} and A _{2} respectiviely .The set of Productions after renaming becomes Step:1 A
Step:2 Every production of the form
should be modified) A _{2} → A _{2} A _{2} A _{1} ,A _{2} →aA _{1} The resulting
A _{2} A _{1} /a A _{1} /b
Step:3 The ) A _{2} production A _{2} → A _{2} A _{2} A _{1} /a A _{1} /b contains left recursion. Left recursion from A _{2}
production can be removed through introduction of B _{2} producion
A _{2} → aA _{1} B _{2} /b B _{2} ,
The resulting set of production is
1
A
2
A
2
,
A
1
a
,
A
2
A
A
1
1
,
A
2
i
A
b
A
j
with I >j must be modified to make i≤j (A _{2} production
set of productions
is A _{2} → A _{2} A _{2} /a, A _{2} → A _{2}
B _{2} → A _{2} A _{1} B _{2} /A _{2} A _{1}
A
1
A
2
A
2
/
a
,
A _{2} → aA _{1} B _{2} /b B _{2} ,
B _{2} → A _{2} A _{1} B _{2} /A _{2} A _{1}
Step:4 A _{2} production are in GNF form A _{1} and B _{2} can be converted to GNF with the help of A _{2} productions. The final set of production is in GNF form production rule P is given by
B
A
A
2
2
1
B
2
aA
aA
1
B
/ bB
2
2
A
/ aA
A
/ bB
2
2
1
1
2
aA
1
B
2
A
1
B
2
/ bB
2
A
1
/ b
/ aA
B
2
1
A
2
/ aA
1
/ bA
2
A
2
B
2
/ a
/ bA
1
B
2
/ aA
1
B
2
A
1
/ aA
1
A
1
/ bA
1
Where set of variables V={A _{1} ,A _{2} ,B _{2} } Set of terminals T={a,b} start symbol = A _{1} set of production P
4 Find a grammar in Chomsky normal form equivalent to
S aAbB, A aA  a, B bB  b
Solution:
S
R
T
A
A
B
B
P
Q
b
RT
PA
QB
PA
a
QB
b
a
5 Begin with the grammar S 0A0  1B1  BB A C
B SA
CS and simplify using safe order
i) Eliminate productions.
ii) ) Eliminate unit productions
iii) Eliminate useless symbols
put the grammar in Chomsky‟s normal form
Solution:
S
X
Y
S
P
Q
S
XY
0
SX
PQ
1
SP
SS
S
S
YY
SS
6 Obtain the Chomsky normal form equivalent to the grammar SbA  aB, AbAA  aS  a, BaBB  bS  b.
Solution:
R _{1} B R _{2} B R _{1} S
A
A
_{B} b
B
B
R
S
S
R _{2} R _{3}
R _{2} S R _{1} R _{4} _{1} a
R _{2} b R _{3} AA R _{4} BB
7 Show the context free language are closed under union operation but not under intersection Step 1:CFL are closed under union Proof: Let L1 and L2 be two CFL and G1 and G2 be CFG such that G1 € L1 and G2 € L2 G1 = {V _{1} , ∑, P _{1} , S _{1} }
P _{1} ={ S1 A _{1} S _{1} A _{1}  B _{1} SB _{1} 
A 
_{1} > a 
B _{1} b 

} 

G 
_{2} = {V _{2} , ∑, P _{2} , S _{2} } 
P _{2} ={ S _{2} aA _{2} A _{2}  bB _{2} B _{2}
A 
_{2} > b 
B _{2} a 

} 

L 
= L _{1} U L _{2} then P = P _{1} U P _{2} 
P={ S S _{1}  S _{2}
S _{1} A _{1} S _{1} A _{1}  B _{1} SB _{1} 
A _{1} > a
B _{1} b
S _{2} aA _{2} A _{2}  bB _{2} B _{2}
A _{2} > b
B _{2} a
}
UNIT III Part  A
1 Define pushdown Automaton
A pushdown Automaton is a  NFA with stack data structure where it can push strings into and pop strings out of stack.
It consists of 7tuples P = ( Q,,,,q _{0}_{,} z _{0} _{,} F),Where Q is a finite set of states, is a finite set of input symbols,is a finite set of nonempty stack alphabets, is a transition function,q _{0} is an initial state _{,} Z _{0} is the initial start symbol of the stack _{,} F is the set of accepting states.
is defined as :Q() Q ^{*}
2
What are the different ways of language acceptances by a PDA and define them There are two ways of language acceptances, 1)Acceptance by final state .L(M)= w  (q _{0}_{,} w,Z _{0} ) ^{*} (q, ,) for some q in F and in ^{*}
2)Acceptance by empty stack. N(M)= w  (q _{0}_{,} w,Z _{0} ) ^{*} (q, ,) for some q in Q.
3 Define the instantaneous descriptions(ID) of pushdown Automaton Let P= ( Q,,,,q _{0}_{,} z _{0} _{,} F) be a PDA then the instantaneous description is given by (q _{0} , x, Z _{0} )= (q _{1}_{,} x) where q _{0} is current state, x is current input symbol, Z _{0} is the current stack symbol, q _{1} indicates next state and x represents top of the stack
4 Define Acceptance by Final State For PDA P= (Q,,,,q _{0}_{,} z _{0} _{,} F) L(P)= w  (q _{0}_{,} w,Z _{0} ) _{P} ^{*} (q, ,) for some state q in F and any stack string .That is, starting in the initial ID with w waiting on the input, P consumes w from the input and enters an accepting state.
5 Define Acceptance by Empty stack For PDA P= ( Q,,,,q _{0}_{,} Z _{0} _{,} F) N(P) = w  (q _{0}_{,} w,Z _{0} ) ^{*} (q, ,) for some q in Q. N(P) is the set of inputs w that P can consume and at the same time empty its stack.
6 Define equivalence of acceptance by final state and empty stack The language accepted by empty stack PDA will also be accepted by final state PDA. The language accepted by final state PDA will also be accepted by empty stack PDA.
7 Define rules for the conversion of Grammars to PDA Let G= (V, T, Q, S) be a CFG. Then PDA P that accepts L(G) by empty statck as follows P=({q}, T, VT, , q, S) where the transition function is defined by
1. For each variable A, (q, , A)= {(q, )  A > is a production of P}.
2. For each terminal a, (q, a, a)= {(q, )}.
8 Convert the given expression to PDA I > a  b  Ia  Ib  I0  I1 (q, , I) = {(q, a), (q,b), (q, Ia), (q, Ib), (q,I0), (q,I1)}
(q, a, a) = {(q, )}, (q, b, b) = {(q, )}, (q, 0, 0) = {(q, )}, (q, 1, 1) = {(q, )}
9 Define Deterministic PDA
A PDA P= ( Q,,,,q _{0}_{,} Z _{0} _{,} F) is a deterministic if and only if the following two conditions are
met:
1. (q, a, X) has at most one member foe any q in Q, a in or a = , and X in .
2. (q, a, X) is non empty, for some a in , then (q, , X) must be empty.
10 What is the additional feature a PDA has when compared with NFA? 1. Stack which is used to store the necessary tape symbols and use the state to remember the conditions.
2. Two ways of language acceptances, one reaching its final state and another by emptying
its stack.
11 State the pumping lemma for CFL’s? Let L be any CFL. Then there exist a constant n ,depending on L, Such that if z is in L and │z│≥
n, then z = uvwxy such that
i) │vx│≥1,
ii) │vwx│≤ n
iii) For all I ≥ 0
u v ^{i} w x ^{i} y is in L.
12 Equivalence of PDA and CFG A language is generated by a CFG,
1. if and only if it is accepted by a pda by empty stack
2. if and only if it is accepted by a pda by final state.
& 503
Academic Year: 201516
13 Construct a pda for the context free grammar
S > aSA  a
A > bB
B > b
(q _{0}_{,} , Z _{0} ) = (q _{1} ,SZ _{0} ) (q _{1} , ,S)= {(q _{1}_{,} aSA), (q _{1} , a)} (q _{1} , ,A)={(q _{1} , bB)} (q _{1} , ,B)={(q _{1} ,b)} (q _{1} , a,a)= {(q _{1}_{,} )} (q _{1} , ,B)= {(q _{1}_{,} )}
14 Define Non Deterministic PDA Nondeterministic PDAs are able to handle situations where more than one choice of action is available. In principle it is enough to create in every such case new automaton instances that will handle the extra choices. The problem with this approach is that in practice most of these instances fail. This can severely affect the automaton's performance as the execution of multiple instances is a costly operation.
15 Is it true that Non deterministic PDA is more powerful than that of Deterministic PDA. Justify. Yes. It is true that non deterministic PDA is more powerful than that of deterministic PDA. This is because the class of languages accepted by NPDA is larger than that of class of languages accepted by DPDA.
16 Define the rule for construction of CFG from given PDA
If q _{0} is the start state and q _{n} is the final state of PDA then [q _{0} Zq _{n} ] becomes the start state of
CFG. Z represents stack symbol.
For (q _{i} , a, Z _{0} ) = (q _{i}_{+}_{1} , Z _{1} Z _{2} ) (q _{i}_{,} Z _{0} q _{i}_{+}_{k} ) > a (q _{i}_{+}_{1} Z _{1} q _{m} ) (q _{m} Z _{2} q _{i}_{+}_{k} )
For (q _{i} , a, Z _{0} ) = (q _{i}_{+}_{1}_{,} ) can be converted as (q _{i} Z _{0} q _{i}_{+}_{1} ) > a
17 What are the main applications of pumping lemma in CFL’s?
The main applications of pumping lemma in CFL is to prove a particular language is not a CFL .
Let L be any CFL. Then there exist a constant n ,depending on L, Such that if z is in L and n, then z = uvwxy such that i) │vx│≥1,
ii) │vwx│≤ n
iii) For all I ≥ 0
│z│≥
u v ^{i} w x ^{i} y is in L.
18 Design a PDA for accepting a language {L= a ^{n} b ^{n}  n >=1} The ID:
(q _{0}_{,} a, Z _{0} ) = (q _{0}_{,} aZ _{0} ), (q _{0}_{,} a,
) (q _{0} , aaabbb, Z _{0} ) = (q _{0} , aabbb, aZ _{0} )
a) = (q _{0}_{,} aa), (q _{0}_{,} b, a) = (q _{1}_{,} ), (q _{1}_{,} b, a) = (q _{1}_{,} ), (q _{1} , , Z _{0} ) = (q _{2}_{,}
= (q _{0} , abbb, aaZ _{0} )
= (q _{0} , bbb, aaaZ _{0} )
= (q _{1} , bb, aaZ _{0} )
= (q
Molto più che documenti.
Scopri tutto ciò che Scribd ha da offrire, inclusi libri e audiolibri dei maggiori editori.
Annulla in qualsiasi momento.