Bca (CS-73)
Bca (CS-73)
Ans :
CFG (Context Free Grammar ) – It is language generator. It operates on strings. CFG contains
Two terms :
Terminal
Non terminal
Example :
abb
=>asb
=>aBb
=>abb
Abbb
=>asb
=>abBb
=>abbb
1
{ambcn | n∈N}
ambcn where, n ϵ N
Let context free grammar(G) = (V, Ʃ, R, S)
Where,
V = {S, B, a, b, c}
Ʃ = {a, b, c}
R = {S → a s c,
S→aB,
B→Bc,
B→b}
a, y
push (a) a, x a,a
push (a) pop
0 1
^,x , ^,y ^ ,y 2
nop nop nop
b,b
b, y pop
b, x push (b)
Push (b)
( 0 , a, x , push (a), 0)
( 0 , a, y , push (a), 0)
( 0 , b, x , push (b), 0)
( 0 , b, y , push (b), 0)
2
( 0 , ^, x , nop, 1)
( 0 , ^, y , nop, 1)
( 1 , a, a , pop, 1)
( 1 , b, b , pop, 1)
( 1 , ^, y , nop, 2)
Question.3 : Find the minimum state finite automaton equivalent to the following
transition diagram:
Ans :
State Input
0 1
a φ (a, b)
(a,b) (a, c) (a, b)
(a, c) φ (a, b, d)
(a, b, d) (a, c) (a, b, d)
1
Minimum State finite automata :
1 0
1 0 a,b,d
a a, a,c
1
, b
Question.4 Establish the following equality of regular expressions:
b*(abb*+aabb*+aaabb*)* = (b+ab+aab+aaab)*
Ans :
One of the above regular expression generate same language. The Automata which made by
this regular expression read all the words which satisfy these regular expression.
L.H.S = b*(abb*+aabb*+aaabb*)*
3
b *{bb*(a + aa + aaa)}*
= b*( a + aa + aaa )*
= {b + b ( a+ aa + aaa )}*
= b* ( a+ aa + aaa )*
Question.5 Take any regular expression and find the transition system. Using this transition
system, find equivalent regular expression and check your result.
Ans : Regular Expression - ( a + b )* a a ( a + b )* a,b
a
a
a q2
q0 b q1
State Input
a b
q0 q0, q1 φ
q1 q2 q0
q2 q2 q2
This FA will accept words with a double a somewhere in them. The state stays as the start state
till we encounter an a which takes as to the next state q1. If the next letter is a we go to the final
state q2 where we stay till the word is accepted whatever be the following letters. But if the letter
is b the FA goes back to q0 to wait for the next a. So, the language which is accepted here can
be defined by the regular expression
( a + b )* a a ( a + b )*
State Input
a b
q0 q0, q1 φ
q0,q1 q0,q1,q2 q0
q0,q1,q2 q0,q1,q2 q0,q2
q0,q2 q0,q1,q2 q2
4
q2 q2 q2
a a
q0 Q0,q1
Q0,q1.q2
b
a b
q 0,q2
q2 b