Sei sulla pagina 1di 27

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 2n / n 1} is not regular. Let z = uvw = 0 n 1 2n , let v = 1 m ,u = 0 n ,w = 1 2n-m uv i w = 0 n 1 mi 1 2n-m ,let I = 0 , then uw =0 n 1 2n-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.

1- 2  3  6  b 4 5 a b 7
1-
2
3
6
b
4
5
a
b
7

- 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”

0 1 1 1 S S 0 1 S 2 0 1 0 0 S
0
1
1
1
S
S
0
1
S
2
0
1
0
0
S
3

16 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}.

a a b s s s 2 0 1 a, b a, b b s
a
a
b
s
s
s
2
0
1
a, b
a, b
b
s
3
18 Construct a DFA which accepts all strings over ∑ = {0,1} ending with 00.
18 Construct a DFA which accepts all strings over ∑ = {0,1} ending with 00.
1
0
0
0
S
S
S
0
1
2
1
1
0
1
S
3

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

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 n-states

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 mn 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 r0 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.

xy 2 z = a s (a r ) 2 a n-s-r b n = a n +r b n

, r0,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

the regular expression that denotes the language accepted by , Using the recursive relation. Recursive relation

, Using the recursive relation.

Recursive relation : R

Step:1 Find R ij (o) where k=0 R 11 (0) =ε , R 12 (0) =0, R 13 (0) =1, R 21 (0) =0, R 22 (0) = ε, R 23 (0) = 1, R 31 (0) = φ

ij (k) = R ij (k-1) + R ik (k-1) ( R kk (k-1) )* R kj (k-1)

R 32 (0) =0 +1, R 33 (0) = ε.

Sept:2 Find

R ij (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 11 (1) =ε ,

R 12 (1) =0,

R 13 (1) =1, R 21 (1) =0, o R 22 (1) = ε+00, R 23 (1) = 1+01, R 31 (1) = φ

R 32 (0) =0 +1, R 33 (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 11 (2) = R

R 11 (2) =(00)* , R 12 (2) =0(00)*, R 13 (2) =0*1, R 21 (2) =0(00)*, R 22 (2) = (00)*, R 23 (2) = 0*1, R 31 (2) = (0+1)(00)*0, R 32 (2) =(0+1)(00)*, R 33 (2) = ε+(0+1)0*1 In our example the set of final state F={q 2, q 3 } L(M)=R 12 (3) +R 13 (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 2n+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 2k+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 2k+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 = { qQ 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 = { qQ 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

PART-A

Let G = Sol:

s , c, a , b, P , swhere 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 , sSol: 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)NTT. 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

Hence

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 aXA /bAY, 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+Eid +E*E id +id*Eid +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) SA1BA10BA101BA1010A10100A10100101 (RMD) Therefore the given grammar is ambiguous.

12 Write CFG for L(G) = a

Soln: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 Find L(G) for CFG 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

A0

19 Eliminate the production from the CFG given below A0 B 1 | 1 B 1 B0 B | 1 B |

Answer:

B0 B | 1 B | 0| 1

A0 B 1 | 1 B 1 | 01 |11

20 If the CFG is as below S0A | 1B |C A0S| 00 B1 | A

C01

then remove the unit productions.

Answer:

S0A | 1B | 01

A0S| 00 B1 | 0S| 00 C01

1 (i) Show that the grammar 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

is ambiguous.

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, AaA | a, BbB | 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 S0A0 | 1B1 | BB AC

B S|A

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 7-tuples 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)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 xrepresents 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: 2015-16

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