Académique Documents
Professionnel Documents
Culture Documents
(bijection).
The range and codomain of f(x) = x2 are equal or every element of codomain is actually one of
the value of the function. So function f is onto function.
Given function is one to one because no single element of codomain can be f(x) for more than
one element in domain.
The function f(x) = x2 is onto function as well as one-to-one function. So, it is called as bijection
function.
7. What is Proof?
A proof of a statement is essentially just a convincing argument that the statement is true.
There are several methods for establishing a proof, some of them are :
1. Direct Proof
2. By Contradiction
3. By Contra positive
4. By Mathematical Induction
X=45 & y= 11
xy= 2(2xy+x+y)+1
= 2(2(45)(11)+45+11)+1
= 2(1046)+1
xy=2093
Hence proved.
Suppose P(n) is a statement involving an integer n. Then to prove that P(n) is true for every n>=n 0,
it is sufficient to show these two things:
1. P (n0) is true.
2. For every k>= n0, if P(k) is true, P(k+1) is true.
12. Prove
Step-1: Basic step
We must show that p(0) is true.
0 = 0(0+1)/2
And, this is obviously true.
Step-2: Induction Hypothesis
k >= 0 and
1+2+3+4…..+k =
Step-3: Proof of Induction
p(k+1) = 1+2+3+….+k+(k+1)
= + (k+1) by induction hypothesis
P(k+1) =
Hence by principle of mathematical induction is true.
13. Prove
Step-1: Basic
We must show that p(0) is true.
P(0)= =0
And, this is obviously true.
Step-2: Induction Hypothesis
k >= 0 and
P(k) = 1+4+9+….k2 =
Step-3:Proof of Induction
P(k+1) = + (k+1)2
=
Hence by principle of mathematical induction is true.
14. Prove
Step-1: Basic
We must show that p(0) is true.
P(0) = =0
16. Prove 1+
Step-1: Basic
We must show that p(0) is true.
P(0)= (0+1)! =(1)! = 1
And, this is obviously true.
Step-2: Induction Hypothesis
k >= 0 and
p(k) = 1+(1+4+18+…..+(k*k!)) = (k+1)!
Step-3: Proof of Induction
17. Prove
Step-1: Basic
We must show that P(1) is true.
P(1) = (1)2 = 1
And, this is obviously true.
Step-2: Induction Hypothesis
k >= 0 and
p(k) = 1+3+5+…..+(2k-1)=k2
Step-3: Proof of Induction
P(k+1) = 1+3+5+….+(2k-1)+(2(k+1)-1)
= k2 + (2(k+1)-1)
= k2 + (2k+2-1)
= k2 + 2k+1
=(k+1)2
Hence by principle of mathematical induction is
true.
>( )3 (2k)
(2k )(2)>(k+1)3
2k+1>(k+1)3 ;k>=10
Hence by principle of mathematical induction 2n>n3 is true.
21. Prove that Integer Bigger than 2 have prime factorization using
strong PMI
Basic step:
P(2) is the statement that 2 is either a prime or a product of two or more primes. This is true
because 2 is prime.
Induction hypothesis:
K ≥ 2, and for every n with 2≤n≤k,n is either prime or a product of two or more primes.
Statement to be shown in induction step:
K+1 is either prime or a product of two or more primes.
Proof of induction step:
We consider two cases. If k+1 is prime, the statement p(k+1) is true. Otherwise, by definition
of a prime, k+1 = r*s, for some positive integer r and s, neither of which is 1 or k+1. It follows
that 2 ≤ r ≤ k and 2 ≤ s ≤ k. therefore, by the induction hypothesis; both r and s are either
prime or the product of two or more primes.
Therefore, their product k+1 is the product of two or more primes, and p(k+1) is true.
Hence, integer bigger than 2 have prime factorization.
1(0+1)*1
12. String starts and ends with same character.
0(0+1)*0 or a(a+b)*a
1(0+1)*1 b(a+b)*b
13. All string of a and b starting with a
a(a/b)*
14. String of 0 and 1 ends with 00.
(0+1)*00
15. String ends with abb.
(a+b)*abb
16. String starts with 1 and ends with 0.
1(0+1)*0
17. All binary string with at least 3 characters and 3rd character should be zero.
(0+1)(0+1)0(0+1)*
18. Language which consist of exactly two b’s over the set ∑={a,b}
a*ba*ba*
19. ∑={a,b} such that 3rd character from right end of the string is always a.
(a+b)*a(a+b)(a+b)
20. Any no. of a followed by any no. of b followed by any no. of c.
a*b*c*
21. String should contain at least 3 one.
(0+1)*1(0+1)*1(0+1)*1(0+1)*
22. String should contain exactly two 1’s
0*10*10*
23. Length of string should be at least 1 and at most 3.
(0+1) + (0+1) (0+1) + (0+1) (0+1) (0+1)
24. No.of zero should be multiple of 3
(1*01*01*01*)*
25. ∑={a,b,c} where a should be multiple of 3.
((b+c)*a (b+c)*a (b+c)*a (b+c)*)*
26. Even no. of 0.
(1*01*01*)*
27. Odd no. of 1.
0*(10*10*)*10*
28. String should have odd length.
(0+1)((0+1)(0+1))*
29. String should have even length.
((0+1)(0+1))*
30. String start with 0 and has odd length.
0((0+1)(0+1))*
31. String start with 1 and has even length.
1(0+1)((0+1)(0+1))*
32. Even no of 1
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 2
Unit 2 – Regular Languages & Finite Automata
(0*10*10*)*
33. String of length 6 or less
(0+1+^)6
34. String ending with 1 and not contain 00.
(1+01)+
35. All string begins or ends with 00 or 11.
(00+11)(0+1)*+(0+1)*(00+11)
36. Language of all string containing both 11 and 00 as substring.
((0+1)*00(0+1)*11(0+1)*)+ ((0+1)*11(0+1)*00(0+1)*)
37. Language of C identifier.
(_+L)(_+L+D)*
a b c
q q1 q2 q3
δ(δ*( δ*(q,a),b),c)
δ(δ(δ* (q,^a),b),c)
δ(δ(δ(δ*(q,^),a),b),c)
δ(δ(δ(q,a),b),c)
δ(δ(q1,b),c)
δ(q2,c)
q3
1 C
0
A 0 B 1
1
1 0 D
0 C
1
1 0
A B 0
0 1 D
0,1
1
0 D
0
0 0 0 0
1
1
A B
1
1
1
Fig 2.5 Finite Automata for {00}*{11}*
5. (a+b)*baaa
b
a B
a
b
b
A C
b
b
a
a
a
E D
on themselves.
0, 1 0, 1 0,1 0, 1
q0 q1 q2 q3 q4
A B 0
C
0 1
P Q R
0
1 1
AR CR
Fig 2.10 Finite Automata for L1-L2
L1 U L2 0
1 BQ 1 CQ
1
0
AP 0 0 1 CP
1
1
1
AR CR
0 1 1
AP 0 CP
1
1
AR CR
Fig. 2.12 Finite Automata for L1∩ L2
1 0
P Q R
1
0
AP BP CP
1 0
1
1 1
AQ 1 BQ CQ
0
1
0
AR 0 BR CR
L1 ∩ L2
0 0
AP BP CP
1 0
1
1
AQ BQ 1 CQ
0 1
0
1
AR 0 BR CR
1
Fig. 2.17 Finite Automata
L2
1
0,1
0 0
A B C
AA BA CA
0
AB BB CB
1
0
0,1
AC BC CC
L1 ∩ L2
1
0,1
AA 0 BB 0
CC
1
Fig. 2.20 Finite Automata for L1∩L2
0,1
1 0,1 0,1
q0 q1 q2 q3
r∈δ*{ q0,1}
= U δ( r,1)
r∈{ q0, q1}
= δ{ q0,1}U δ( q1,1)
= { q0, q1}U{q2}
= { q 0, q 1, q 2}
= U δ( r,1)
r∈( q0)
= δ( q0,1)
= {q0, q1}
= δ(q0,1)U δ(q1,1)
= {q0, q1, q2}
For x ∈ Ʃ* and p ∈δ*( p, x) is the set of all states q ∈ Q such that there is a sequence of
transition corresponding to x by which M moves from p to q.
^ W
q0
^ ^
0 0
t u v
1
0
δ*(q0,^) = ^({q0})
= { q0,p,t}
1 b 4
a a
3
b a a
b
4 3
a
C
0 0
1
0
^ ^ D
A B
δ*(B,^) = {B,D}
δ*(B,0) = ^ ( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ(B,D)
= ^(δ(B,0)U δ(D,0))
= ^{ C,D}
= {C,D}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,˄)
=^( U δ(r,1))
r∈(B,D)
= ^(δ(B,1)U δ(D,1))
=Ø
δ*(C,˄) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,˄)
=^( U δ(r,0))
r∈(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,˄)
=^( U δ(r,1))
r∈(C)
= ^(δ(C,1))
= ^{B}
= {B,D}
δ*(D,˄) = {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈(D)
= ^(δ(D,0))
= {D}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈(D)
= ^(δ(D,1))
=Ø
C
0 1
0
1 0
0
0 0
A B D
A
0
0
1
ABCD BD
0
0
1
1 CD
A
1 0
Ø D
1
0,1 0
Fig. 1.27 Finite Automata
1
0
0
^ B 1
A E
^
0
D
1
δ*(B,^) = {B}
δ*(B,0) =^( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ (B)
= ^(δ(B,0))
= ^{ C}
= { C}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,^)
= ^( U δ(r,1))
r∈(B)
= ^(δ(B,1))
= {E}
δ*(C,^) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,^)
=^( U δ(r,0))
r∈(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,^)
=^( U δ(r,1))
r∈(C)
= ^(δ(C,1))
= ^{B}
={B}
δ*(D,^)= {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈(D)
= ^(δ(D,0))
= ^ {E}
= {E}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈(D)
= ^(δ(D,1))
= {D}
δ*(E,^) ={E}
δ*(E,0) =Ø
δ*(E,1) =Ø
0 1
0
0 0 B 1
0,1
A E
0,1
0
D
δ({C},0) =Ø
δ({C},1) = {B}
1 0
ABCDE BDE CE
0
0
1 0,1
0 1
A Ø C 1
1
0 0,1 0
DE B
E
1
1 0
D
1
W a W
Ø {^} {a}
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 23
Unit 2 – Regular Languages & Finite Automata
f1
q1
f1’
^
qu
f2
^ q2
’
f2
f1 f2
^
qc=q1 q2
f1’ ^ f2’
q1
^ 1
qk
^ f1 f1’
where xi ∈ L1 for each i, Mk can move from qk to q1 by a ˄-transition; for each i, Mk moves
from q1 to an element fi of A1 by a sequence of transition corresponding to xi; and for each i,
Mk then moves from fi back to qk by a ˄-transition.
It follows that (˄x1˄) (˄x2˄)…… (˄xm˄)=x is accepted by Mk. On the other hand, if x is
accepted by Mk, there is a sequence of transition corresponding to x that begins and ends at
qk. Since the only transition from qk is a ˄-transition to q1, and the only transition to qk are ˄-
transition from elements of A1, x can be decomposed in the form
x= (^x1˄) (˄x2˄)…… (˄xm˄)
Where, for each i, there is a sequence of transition corresponding to xi from q1 to an element
of A1. Therefore, x∈ L1*.
Since we have constructed an NFA-˄ recognizing L in each of the three cases, the proof is
complete.
0 ^ 0
^
^
1
^
^ ^ 1 ^ 0
2. (0 + 1)* (10+01)* 11
^
0
^
^
1
^
^ ^
1 ^ 0
^
^
^
0 ^ 1
^
^
^
1 ^ 1
3. (0 + 1)* (10+110)* 1
^
0
^
^
1
^
^ 1 ^ 0
^
^
^
1 ^ 1 ^
^
0
0
0
A,0 B,1
a b
A,0 B,0 C,1
a
b
1 1
X,C Y,C Z,B
0 1
0 0
W,A
AA
4. Construct a moore machine that takes binary number as an i/p and produces residue
modulo ‘3’ as an output.
0 1 ∆
q0 q0 q1 0
q1 q2 q0 1
q2 q1 q2 2
Table 2.7transition Table
0 1
1 0
q0,0 q1,1 q2,2
1 0
Fig. 2.41 Moore M/c to produces residue modulo ‘3’
transition.
q0 : Is the initial state of Me and q0 ∈ Q.
B
0/n
A 1/n
0/n
1/n
C
1/y
Fig. 2.43 Mealy M/c for (0+1)*(00+11)
3. Design a mealy machine where Ʃ={0, 1, 2} print residue modulo 5 of input treated as
ternary (base 3).
1/4
0/0 0/3
2/0 1/2
2/2 1/3
2/1
2/4
0/2
1/0
S-2: Recursively interacting over the pairs of state for any transition for
δ(p,x) = r
δ(q,x) = s
and for x ∈ ε. If r and s are distinguishable make p and q as distinguish.
S-3: If any iteration over all possible state pairs one fails to find a new pair of states that are
distinguishable terminate.
S-4: All the states that are not distinguished are equivalence.
a 4
2 b
a a
b 5
1
a
b
b a
6 b
3
b a
7
b
δ(2,a)=4 δ(2,b)=5
Consider pair (1,3)
δ(1,a)=2 δ(1,b)=3
δ(3,a)=6 δ(3,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (1,4)
δ(1,a)=2 δ(1,b)=3
δ(4,a)=4 δ(4,b)=5
Consider pair (1,5)
δ(1,a)=2 δ(1,b)=3
δ(5,a)=6 δ(5,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (1,7)
δ(1,a)=2 δ(1,b)=3
δ(7,a)=6 δ(7,b)=7
pair (2,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,3)
δ(2,a)=4 δ(2,b)=5
δ3(,a)=6 δ(3,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,4)
δ(2,a)=4 δ(2,b)=5
δ(4,a)=4 δ(4,b)=5
Consider pair (2,5)
δ(2,a)=4 δ(2,b)=5
δ(5,a)=6 δ(5,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (2,7)
δ(2,a)=4 δ(2,b)=5
δ(7,a)=6 δ(7,b)=7
pair (4,6) is distinguish, so It’s a distinguished pair.
Consider pair (3,4)
δ(3,a)=6 δ(3,b)=7
δ(4,a)=4 δ(4,b)=5
pair (6,4) is distinguish, so (3,4) is distinguish.
Consider pair (3,5)
δ(3,a)=6 δ(3,b)=7
δ(5,a)=6 δ(5,b)=7
Consider pair (3,7)
δ(3,a)=6 δ(3,b)=7
δ(7,a)=6 δ(7,b)=7
Consider pair (4,5)
δ(4,a)=4 δ(4,b)=5
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 33
Unit 2 – Regular Languages & Finite Automata
δ(5,a)=6 δ(5,b)=7
pair (6,4) is distinguish, so (4,5) is distinguish.
Consider pair (4,7)
δ(4,a)=4 δ(4,b)=5
δ(7,a)=6 δ(7,b)=7
pair (6,4) is distinguish, so (4,7) is distinguish.
Consider pair (5,7)
δ(5,a)=6 δ(5,b)=7
δ(7,a)=6 δ(7,b)=7
a b
b a
124 357 6
b
a
Fig. 2.46 Minimized Finite Automata
Application: (Explain the application of the Pumping Lemma to show a Language is Regular or Not)
The pumping lemma is extremely useful in proving that certain sets are non-regular. The general
methodology followed during its applications is :
Select a string z in the language L.
Break the string z into x, y and z in accordance with the above conditions imposed by the
pumping lemma.
Now check if there is any contradiction to the pumping lemma for any value of i.
34. Use the pumping lemma to show that following language is not
regular: L = {ww|w ϵ {0,1}*}
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=anb anb
ῳ ῳ
| ῳ|=2n+2>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
Since |xy|<=n, y must be of the form ar | r>0
Now ῳ=anbanb= as ar an-s-rbanb
x y z
i
Step 3: Let us check whether x y z for i=2 belongs to L.
Xy2z= as a2r an-s-rbanb= an+rbanb
Since, r>0, an+rbanb is not of the form ῳῳ as the number of a’s in the first half is n+r and
second half is n. Therefore, xy2z L. Hence by contrdiction we can say language is not
regular.
35. Prove that the language L = {0n: n is a prime number} is not
regular.
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=ap ,where p is prime and p>n
| ῳ|= | ap| = p>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
We assume that y= am for m>0.
Step 3: Length of x yi z can be written as given below.
Xyiz= |xyz|+|yi-1|=p+(i-1)m
As |y|=| am |=m
Let us check whether P(i-1) m is prime for every i.
For i=p+1, p+(i-1)m= P+ Pm =P(1+m)
So xyp+1z L. Hence by contrdiction we can say language is not regular.
36. Use Pumping Lemma to show that following language is not
regular. L = { wwR / w ε {0,1}* }
Step 1: Let us assume that L is regular and L is accepted by an FA with n states.
Step 2: Let us chose the string
ῳ=anb ban
ῳ ῳR
| ῳ|=2n+2>=n
Let us write w as xyz with
|y|>0
And |xy|<=n
Since |xy|<=n, x must be of the form as.
Since |xy|<=n, y must be of the form ar | r>0
Now ῳ=anbban= as ar an-s-rbban
x y z
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 35
Unit 2 – Regular Languages & Finite Automata
S - S S - S
S * S a a S
S /
a a a
a
Table 3.1 Difference between left most & right most derivation
An Ambiguous CFG :
A context free grammar G is ambiguous if there is at least one string in L(G) having two or more
distinct derivation tree. (or, equivalently two or more distinct leftmost derivation or rightmost
derivation)
1) Prove that given grammar is ambiguous. SS+S | S-S | S*S | S/S | (S) |a
String : a+a+a
SS+S SS+S
a+S S+S+S
a+S+S a+S+S
a+a+S a+a+S
a+a+a a+a+a
S S
S + S S + S
a + S S + S a
S
a a a a
Fig. 3.1 Two left most derivation tree for string a+a+a
1
0
1 0
A B C
0
Fig. 3.2 Finite Automata
Equivalent CFG
A0A
A1B
B1B
B0C
B0
C0A
C1B
BA/bb
Ba/bc/bb
SAa/B
SAa/a/bc/bb
Stack
accepting L.
b,z0/bz0 a,a/ ^
a,a/aa
a,z0/az0
c,a/a ^,z0/z0
c,b/b q2
q0 q1
c,z0/z0
a,b/ab b,b/bb
b,b/ ^
b,a/ba
r
Fig. 4.2 PDA for xcx
String:abcba
Move No. Resulting State unread i/p Stack
Initial q0 abcba Z0
1 q0 bcba aZ0
4 q0 cba baZ0
9 q1 ba baZ0
11 q1 a aZ0
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 2
Unit 4 – Pushdown Automata, CFL & NCFL
10 q1 ^ Z0
12 q2 ^ Z0
b,a/ba
^,b/b
a,a/aa
^,a/a
a,z0/az0 a,a/a b,b/ ^
b,z0/bz0 b,a/a a,a/^
b,b/b
a,b/b ^,z0/z0
q q1 q2
0
b,z0/z0
b,b/bb
a,z0/z0
a,b/ab
^,z0/z0
Fig. 4.3 PDA for even-odd length palindrome
String:aba
Move No. Resulting State unread i/p Stack
Initial q0 aba Z0
4 q0 ba aZ0
10 q1 a aZ0
12 q1 ˄ Z0
q2 ˄ Z0
String:aaabbb
Resulting State unread i/p Stack
q0 aaabbb Z0
q0 aabbb aZ0
q0 abbb aaZ0
q0 bbb aaaZ0
q1 bb aaZ0
q1 b aZ0
q1 ˄ Z0
q2 ˄ Z0
accepted
a,z0/ az0
a,a/ aa
b,a/ ^
b,a/ ^ ^,z0/z0
q q1 q2
0
^,z0/ z0
Fig. 4.4 PDA accepting Number of a’s and b’s are same.
3 q1 { { (q1,{{)
4 q1 [ { (q1,[{)
5 q1 { [ (q1,{[)
6 q1 [ [ (q1,[[)
7 q1 ] [ (q1,˄)
8 q1 } { (q1,˄)
9 q1 ˄ Z0 (q0,z0)
Table 4.4 Transition table for balanced string of parenthesis
{,[/{[
{,{/{{
[,z0/[z0 [,[/[[
{,z0/{z0
q0 q1
[,{/[{
^,z0/z0 ],[/˄
},{/ ^
a,a/ aa
a,b/^
b,z0/ bz0
^,a/a
a,z0/ az0
q0 q1
b,b/bb
b,a/ ^
Fig. 4.6 PDA for more a’s than b’s
^,z0|z0
q5
n n+m m
Fig. 4.7 PDA for a b c
9. Design PDA for {aibjck | i,j,k>=1 & j=i or j=k}
Move No. State i/p Stack Symbol Move
1 q0 a Z0 (q1, aZ0)(q4,z0)
2 q1 a a (q1, aa)
3 q1 b a (q2, ^)
4 q2 b a (q2, ^)
5 q2 c Z0 (q3, Z0)
6 q3 c Z0 (q3, Z0)
7 q3 ^ Z0 (q7, Z0)
8 q4 a Z0 (q4, Z0)
9 q4 b Z0 (q5,bZ0)
10 q5 b b (q5, bb)
11 q5 c b (q6, ^)
12 q6 c b (q6, ^)
13 q6 ^ Z0 (q7, Z0)
All other combination (none)
i j k
Table 4.7 Transition table for a b c ,j=i or j=k
a,z0|z0
b,b/bb ^,z0|z0
a,z0|z0 c,b|^
b,z0|bz0 c,b|^
q4 q5 q6
i j k
Fig. 4.8 PDA for a b c ,j=i or j=k
(POP(S)) Z0 -
accept
Table 4.9 Processing a+a*a by Bottom up PDA
Solution:
Step 1: Add the production for the start symbol
S[q z q]
S[q z p]
Step 2: Add production for the δ( q, 1, z) (q ,xz)
[q z q]1[q x q][q z q]
[q z q]1[q x p][p z q]
[q z p]1[q x q][q z p]
[q z p]1[q x p][p z p]
Step 3: Add production for the δ( q, 1, x) (q ,xx)
[q x q]1[q x q][q x q]
[q x q]1[q x p][p x q]
[q x p]1[q x q][q x p]
[q x p]1[q x p][p x p]
Step 4: Add the production for δ( q, ^, x) (q ,^)
[q x q]^
Step 5: Add the production for δ( q, 0, x) (p ,x)
[q x q]0 [p x q]
[q x p]0 [p x p]
Step 6: Add the production for δ( p, 1, x) (p ,^)
[p x p]1
Step 7: Add the production for δ( p, 0, z) (q ,z)
[p z q]0 [q z q]
[p z p]0 [q z p]
Step 8: Renaming variable name
Original name New name
[q z q] A
[q z p] B
[p z q] C
[p z p] D
[q x q] E
[q x p] F
[p x q] G
[p x p] H
The set of production can be written as:
SA|B
A1EA|1FC
B1EB|1FD
E1EE|1FG
F1EF|1FH
E^
E0G
F0H
H1
C0A
D0B
Step 9: simplification of grammar
Symbol G is not available on left side of grammar so, it can be eliminated.
SA|B
A1EA|1FC
Dixita Kagathara, CE Department | 2160704 – Theory of Computation 10
Unit 4 – Pushdown Automata, CFL & NCFL
B1EB|1FD
E1EE|^
F1EF|1FH|0H
H1
C0A
D0B
15. Give the difference between Top Down & Bottom Up parsing.
Top Down Parsing Bottom Up Parsing
A parser is top-down if it discovers a A parser is bottom up if it discovers a
parse tree top to bottom parse tree bottom to top
A top down parser for a given In bottom up parsing, the source
grammar G tries to derive a string string is reduced to the start symbol
through a sequence of derivation of the grammar. Bottom up parsing
starting with a start symbol. method is also called shift reduce
Top down parsing methods are: parsing.
Top down parsing(with Bottom up parsing methods are:
backtracking/without Naïve bottom up parsing
backtracking) Operator precedence
Recursive decent parser parsing
Finite
control
h
r
∆/∆,R ∆/∆,R
∆/∆,R
b/b,R
a/a,R
∆/∆,R a/a,R
b/b,R a/a,R
q0 q1 q2 q3 ha
b/b,R
Q
1
Fig. 5.2 TM accepting {a+b}*aba
∆/∆,L
q2 q3
b/b,L
a/∆,R
a/a,L
a/∆,L
∆/∆,R ∆/∆,R
q0 q1 q4 ha
b/∆,R b/∆,L
∆/∆,L
q5 q6 ∆/∆,R
(odd pal)
a/a,R
b/b,R
a/A,R
A/A,R
∆/∆,R
q0 q1
∆/∆,S
B/B,R ha
q5
C/C,R
∆/∆,S
B/B,R q6 C/C,R
n n n
fig.5.4 TM accepting a b c
A/A,R
B/B,R
a/a,R b/b,L
b/b,R a/a,L
b/B,R
B/B,L
∆/∆,R a/A,R
A/A,L
q0 q1 q2 q3 q4
∆/∆,L b/B,L
B/B,L
a/A,L
∆/∆,S
A/A,L
A/a,L ha
q5
B/b,L
∆/∆,R
∆/∆,S
q6
b/B,R
a/A,R
a/a,R
b/b,R
B/B,R
q7 q8 a/a,R
A/A,R
b/b,R
∆/∆,R
∆/∆,R
B/∆,L A/∆,L
q9
∆/∆,L
a/a,L
b/b,L
a/a,R a/a,R
∆/∆,R
b/b,L
q2 q3
b/b,L a/a,L
a/A,R
a/a,L
∆/a,L
∆/∆,R ∆/∆,R ∆/∆,L
q0 q1 q4 q5
b/B,R ∆/b,L
∆/∆,L ∆/∆,R
q6 q7
ha q8
a/a,R a/a,R
∆/∆,S
b/b,R b/b,R
A/a,L
B/b,L ∆/∆,R
∆/∆,L
∆/∆,R
q7 h
a
∆/∆,S
x/x,L
b/b,R q3
a/a,R a/∆,L ∆/a,S
a|∆,R
q0 q1 q2 ha
b/a,L a/b,L
b|∆,R
∆/∆,L
∆/∆,R
b/∆,L
q4 ∆/b,S
b/b,L
∆/∆,S
Fig. 5.8 TM to delete a symbol