Theory of Computation
Theory of Computation
Theory of Computation
| – 1
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
T F F
F T T
F F T
Table 1.4. Truth table of conditional
11. Tautology: If all the entries of the truth table for any compound proposition are true then the
proposition is termed as tautology.
12. Onto function / subjective / surjection: For the function f : A B, if f(A) = B (the range and
codomain of f are equal and every element of the codomain is actually one of the values of the
functions), the function f is said to be a onto function.
13. One to one function / injective / injunction: For the function f : A B, we say f is one-to-one if
no single element y of B can be f(x) for more than one x in A.
14. Bijection function: For the function f: A B, f is bijection if f is one-to-one as well onto function.
15. Composite function: Suppose we have function f : A → B and g : B → C. the function h : A → C
defined by h(x) = g (f(x)) is called the composite of g and f.
16. Inverse function: For f: A → B, then for any y B there is at least one x A with f(x) = y and f is
onto function and for any y B there is at most one x A with f(x) = y where f is one-to-one.
Therefore for any y B it makes sense to speak of the element x A for which f(x = y)
We denote it x by f -1 (y). For Eg.:- f : A → B f -1 : B → A
17. Relation: A relation R on a set A is a subset of A × A.
18. Equivalence relation: Assume that R is a relation on a set A; in other words, R A × A Then
1. R is reflexive if for every a A, aRa.
2. R is symmetric if for every a and b in A if aRb then bRa
3. R is transitive if for every a, b and c in A if aRb and bRc then aRc. R is equivalence on A if R
is reflective, symmetric and transitive
| – 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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
| – 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 4
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
• By dividing both m’ and n’ by all the factors that are common to both, we obtain =m/n, for
some integer m and n having no common factors. Since m/n= , m= n . Squaring both sides
of this equation, we obtain m2=2n2, and therefore m2 is even.
• If a and b are odd, then ab is odd. Since a conditional statement is logically equivalent to its
contra positive, we may conclude that for any a and b, if ab is not odd, then either a is not odd
or b is not odd.
• However, an integer is not odd if and only if it is even, and so for any a and b, if ab is even, m
must be even.
• This means that for some k, m=2k. Therefore, (2k) 2=2n2.
• Simplifying this and canceling 2 from both side, we obtain 2k2=n2. Therefore n2 is even.
• The same argument that we have already used to show that n must be even, and so n=2j for
some j.
• We have shown that m and n are both divisible by 2. This contradicts the previous statement
that m and n have no common factor. The assumption that is rational therefore it leads to a
contradiction, and the conclusion is that is irrational.
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
| – 5
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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(k) = 1+4+9+….k
Step-3:Proof
of Induction
P(k+1)
14. Prove
Step-1: Basic
We must show that p(0) is true.
| – 6
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
P(0) =
p(k)=
Step-3: Proof of Induction
p(k+1)
=
=
| – 7
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
p(k) = 7+13+19+…..+(6k+1)=k(3k+4)
Step-3: Proof of Induction
P(k+1) = 7+13+19+…..+(6k+1)+(6(k+1)+1)
= k(3k+4)+(6(k+1)+1)
= k(3k+4)+(6k+6+1)
= 3k2+4k+6k+7
= 3k2+10k+7
= 3k2+3k+7k+7
= 3k(k+1)+7(k+1)
= (k+1)(3k+7)
= (k+1)(3k+3+4)
= (k+1)(3(k+1)+4)
Hence by principle of mathematical induction is true.
16. Prove
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
P(k+1) = 1+(1+4+18+…..+(k*k!) + (k+1)*(k+1)!)
= (k+1)! + (k+1)(k+1)!)
= (k+1)! (1+(k+1))
= (k+1)! ((k+1)+1) = ((k+1) + 1)!
Hence by principle of mathematical induction is true.
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
| – 8
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
for k>=10
) ,because 2k>k3
(2k )(2)>(k+1)3
2k+1>(k+1)3 ;k>=10
Hence by principle of mathematical induction 2n>n3 is true.
| – 9
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 10
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
• 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.
| – 11
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 1
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
a b c
q q1 q2 q3
1 C
0
A 0 B 1
1
D
1 0
| – 4
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 1 D
0,1
1
0 D
0
0 0 1 0
1
A 1 B
| – 5
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
5. (a+b)*baaa
b
a B a
b
b
A C
b
b
a
a
a
E D
| – 6
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
A B 0
C
1 0
0 1
P Q R
0
1
M2
Fig 2.9 Finite Automata for string ending in 01
Here Q1={A,B,C} and Q2={P,Q,R} So,Q =
Q1×Q2 ={AP,AQ,AR,BP,BQ,BR,CP,CQ,CR}
q0=(q1,q2)=(A,P)
δ((A,P),0) = (δ(A,0), δ(P,0))
= BQ
δ((A,P),1) = (δ(A,1), δ(P,1))
= AP
δ((B,Q),0) = (δ(B,0), δ(Q,0))
= CQ
δ((B,Q),1) = (δ(B,1), δ(Q,1))
= AR
δ((C,Q),0) = (δ(C,0), δ(Q,0))
= CQ
δ((C,Q),1) = (δ(C,1), δ(Q,1))
= CR
| – 7
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 0
AP 1 1 CP
1 1
AR CR
Fig 2.10 Finite Automata for L1-L2
| – 8
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 1
1 0
P Q R
1
M1 M2 0
0 1
0, 1 1
A B C
0
| – 9
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 10
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
AP BP CP
1 0
1
1 1
AQ 1 BQ CQ
0
0
1
AR 0 BR CR
AP BP CP
1 0
1
1
1
AQ BQ CQ
0 1
0
1
AR 0 BR CR
| – 11
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 0
A B C
0,1
1
0 0
A B C
0,1
1
AA BA CA
0
AB BB CB
1
0
0,1
AC BC CC
| – 12
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
L1 ∩ L2
1
0,1
AA 0 BB 0 CC
1
Fig. 2.20 Finite Automata for L1∩L2
| – 13
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
q δ(q,0) δ(q,1)
q0 { q 0} { q0, q1}
q1 { q 2} { q 2}
q2 { q 3} { q 3}
q3 Ø Ø
Table 2.2 Transition Table
0,1
1 0 ,1 0,1
q0 q1 q2 q3
= 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}
| – 14
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
= δ(q0,1)U δ(q1,1)
= {q0, q1, q2}
| – 15
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ*(q,ya)= Λ( U δ(r,a))
r∈ δ*(q,y)
A string x is accepted by M if δ*(q0, x) ∩ A ≠ Ø. The language recognized by M is the set L(M) of all strings
accepted by M.
| – 16
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 1
0 1
P r S
^
^
^ W
q0
^ ^
0 0
t u v
1
0
δ*(q0,^) = ^({q0})
= { q0,p,t}
| – 17
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
1 b 4
a a
3
| – 18
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
a b 3,4
1 2, 3
b a a
b
4 3
a
C
0 0
1
0
^ ^
A B D
| – 19
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
r∈ δ*( A,^)
=^( U δ(r,1))
r∈(A,B,D)
= ^ (δ(A,1) U δ(B,1) U δ(D,1))
=Ø
δ*(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}
| – 20
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ*(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
0
Fig. 2.26 NFA
δ({A},0) = {A,B,C,D}
δ({A},1) =Ø
δ({A,B,C,D},0) = (δ(A,0) U δ(B,0) U δ(C,0) U δ(D,0))
= {A,B,C,D}
δ({A,B,C,D},1) = (δ(A,1)U δ(B,1)U δ(C,1)U δ(D,1))
= {B,D}
δ({B,D},0) = (δ(B,0)U δ(D,0))
= {C,D}
δ({B,D},1) = (δ(B,1)U δ(D,1))
=Ø
δ({C,D},0) = (δ(C,0)U δ(D,0))
= {D}
δ({C,D},1) = (δ(C,1)U δ(D,1))
= {B,D}
δ({D},0) = {D}
| – 21
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ({D},1) =Ø
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
| – 22
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ*(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))
| – 23
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
=Ø
δ*(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) =Ø
| – 24
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0 1
0
0 0 B 1
0,1
A E
0, 1
0
D
| – 25
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ({B},1) = {E}
δ({E},0) =Ø
δ({E},1) =Ø
| – 26
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ({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
27
W a W
Ø {^} {a}
Fig. 2.31 Basic Languages for NFA-^
• Now, suppose that L1 and L2 are recognized by the NFA-^s M1 and M2, respectively, where for
both i=1 and i=2,
Mi=(Qi,ε,qi,Ai,δi)
• By renaming state if necessary, we may assume that Q1 ∩ Q2 = Ø. We will construct NFA-^s
Mu, Mc, and Mk recognizing the language L1 U L2, L1L2, and L1*, respectively.
Construction Of Mu
f1
q1
’
f1
^
qu
f2
^
q2
’
f2
| – 28
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
Construction Of Mc
• Construction of Mc = (Qc, ε, qc, Ac, δc). In this case we do not need any new states, Let Qc = Q1
U Q2, qc=q1, and Ac = A2. The transition will include all those of M1 and M2 as well as a
εtransition from each state in A1 to q2.
• In other words, for any q not in A1, and α ∈ ε U {^}, δc(q,a) is defined to be either δ1(q,a) or
δ2(q,a), depending on whether q is in Q1 and Q2, for q ∈ A1.
δc(q,a)= δ1(q,a) for every a ε,
And δc(q,˄)= δ1(q,˄) U {q2}
f1 f2
^
qc=q1 q2
’ ’
f1 ^ f2
q1
^ 1
qk
^ f1 f1’
| – 29
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
• Construction of Mk = (Qk, Ʃ, qk, Ak,δk). Let qk be a new state not in Q1 and let Qk=Q1U{qk}. Once
again all the transitions of M1 will be allowed in Mk, but in addition there is a ˄transition from
qk to q1 and there is a ˄-transition from each elements of A1 to qk. More precisely, δk(qk,˄)={q1}
and δk(qk,a)= Ø for a ε. for q A1, δk(qk,˄)= δk(qk,˄) U {qk}.
• Suppose x L1*. if x=˄ then clearly x is accepted by Mk. Otherwise, for some m≥1,x=x1x2….xm,
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 q k. 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.
| – 30
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
1. (00+1)*(10)*
0 ^ 0
^
^
1
^
^ ^ 1 ^ 0
2. (0 + 1)* (10+01)* 11
| – 31
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 32
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
3. (0 + 1)* (10+110)* 1
^
0
^
^
1
^
^ 1 ^ 0
^
^
^
1 ^ 1 ^
^
0
| – 33
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
1. Moore machine
2. Mealy machine
29. Moore Machine
• Mathematiically moore machine is a six tuple machine and define as Mo=( Q,Ʃ, ∆, δ , /\’,q0)
where
Q: A Nonempty finite set of state in Mo
Ʃ: A Nonempty finite set of input symbols ∆: A Nonempty finite set of outputs δ: It is transition
function which takes two arguments as in finite automata, one is input state and other is input
symbol. The output of this function is a single state, so clearly δ is the function which is
responsible for the transition of Mo.
/\’: it is a mapping function which maps Q to ∆, giving the output associated with each state.
1 0
0
A,0 B,1
a b
A,0 B,0 C,1
a
b
| – 34
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
1 1
X,C Y,C Z,B
0 1
0 0
W,A
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.
| – 35
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0/1
1/0
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
| – 36
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
0/0 0/3
2/0 1/2
2/2 1/3
2/1
2/4
0/2
1/0
| – 37
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
a 4
2 b
a a
b 5
1
a
b
b a
6 b
3
b a
7
b
3 5
| – 38
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
δ(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
δ(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
| – 39
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
a b
b a 6
124 357
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
| – 40
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
x y z
Step 3: Let us check whether x yi 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.
| – 41
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 42
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
Equivalent left most derivation tree Equivalent Right most derivation tree
S S
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. S→S+S | S-S | S*S | S/S | (S) |a String
: a+a+a
S→S+S S→S+S a+S S+S+S a+S+S a+S+S a+a+S a+a+S
a+a+a a+a+a
| – 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
S S SS
a + S S S + a
S + S + S
a a a a
Fig. 3.1 Two left most derivation tree for string a+a+a
Here, we have two left most derivation for string a+a+a hence, above grammar is ambiguous.
1
0
1 0
A B C
0
Fig. 3.2 Finite Automata
Equivalent CFG
A→0A
A→1B
B→1B
B→0C
B→0
C→0A
C→1B
| – 4
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 5
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
S→ABA/BA/AA/AB/aA/a/bB/b
S→aA/a
S→bB/b
2) S→Aa/B A→a/bc/B B→A/bb
Grammar after elimination of unit production:
Unit production are S→B,A→B and B→A.
A→a/bc/B
A→a/bc/A/bb
A→a/bc/bb
B→A/bb
B→a/bc/bb
S→Aa/B
S→Aa/a/bc/bb
| – 6
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 7
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
A→ab/aAb
C→aC/a
D→aDa/bDb/aa/bb
Step-3:Replace all mixed string with solid NT:
S→AACD/ACD/CD/AAC/AC/PC/a
A→PQ/PAQ
C→PC/a
D→PDP/QDQ/PP/QQ
P→a
Q→b
Step-4 : Shorten the string of NT to length 2
S→AT1, T1→AT2 ,T2→CD
S→AU1,U1→CD
S→AV1,V1→AC
S→CD/AC/PC/a
A→PQ
A→PW1, W1→AQ
C→PC/a
D→PP/QQ D→PY1, Y1→DP
D→QZ1, Z1→DQ
P→a
Q→b
| – 8
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
X→(
Y→)
| – 9
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
Where S V1.The language L1 *contains strings of the form x = x1x2 …xk , where each xi L1.
Since each xi can be derived from S1, then to derive x from S it is enough to be able to derive
a string of k S1‘S. We can accomplish this by including the productions
S→S1S |
In P. Therefore, let
P = P1U { S→S1S | }
The proof that L1 * L(G*) is straightforward. If x L(G*) , on the other hand, then either x
= or x can be derived from some string of the form S1k in G* . In the second case, since
the only production in G* beginning with S1 are those in G1, we may conclude that x L(G1)k
L(G1)* .
| – 10
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
Stack
| – 1
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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
Design PDA for palindrome with middle symbol c.
| – 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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
10 q1 ^ Z0
12 q2 ^ Z0
| – 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
b,b/b
^,z0/z0
q q1 q2
0
b,z0/z0
b,b/bb
a,z0/z0
a,b/ab
^,z0/z0
a,b/b
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
| – 4
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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 q q2
0 1
^,z0/ z0
Fig. 4.4 PDA accepting Number of a’s and b’s are same.
| – 5
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
^,z0/z0 ],[/˄
},{/ ^
| – 6
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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
8. Design PDA for {anbn+m cm | n,m>=1}
Move No. State i/p Stack Symbol Move
1 q0 a Z0 (q1, aZ0)
3 q1 a a (q1, aa)
4 q1 b a (q2, ^)
5 q2 b a (q2, ^)
6 q2 b Z0 (q3,bZ0)
7 q3 b b (q3, bb)
8 q3 c b (q4, ^)
9 q4 c b (q4, ^)
11 q4 ^ Z0 (q5, Z0)
All other combination (none)
n n+m m
Table 4.6 Transition table for a b c
^,z0|z0
q5
| – 7
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
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
| – 8
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
1 q0 ˄ Z0 (q1,SZ0)
4 q1 b b (q1,˄)
5 q1 ˄ Z0 (q2, Z0)
Table 4.8 Top down PDA equivalent to CFG
(q0,abbaaa, Z0)
(q1,abbaaa, SZ0)
(q1,abbaaa, SbSZ0)
(q1,abbaaa, abSZ0)
(q1,bbaaa, bSZ0)
(q1,baaa, SZ0)
(q1,baaa, bSSZ0)
(q1,aaa, SSZ0)
(q1,aaa, aSZ0)
(q1, aa,SZ0)
(q1,aa, aSZ0)
(q1, a, SZ0)
(q1, a, aZ0)
(q1,˄, Z0)
(q2,˄, Z0)
T→a
Move Production Stack Unread i/p
Z0 a+a*a
shift - aZ0 +a*a
reduce T→a TZ0 +a*a
reduce S→T SZ0 +a*a
shift - +SZ0 a*a
shift - a+SZ0 *a
reduce T→a T+SZ0 *a
shift - *T+SZ0 a
shift - a*T+SZ0 -
reduce T→a*T T+SZ0 -
reduce S→S+T SZ0 -
(POP(S)) Z0 -
accept
Table 4.9 Processing a+a*a by Bottom up PDA
| – 10
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
where qi, qj ∈ Q
a ∈ (Ʃ U ^) B,
C1, C2 ∈ (┌ U ^)
Then for each p1, p2 ∈ Q, add the production
[qi, B, p1]→a[qj C1 p2][p2 C2 p1]
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]
| – 11
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
[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:
S→A|B
A→1EA|1FC
B→1EB|1FD
E→1EE|1FG
F→1EF|1FH
E→^
E→0G
F→0H
H→1
C→0A
D→0B
Step 9: simplification of grammar
Symbol G is not available on left side of grammar so, it can be eliminated.
S→A|B
A→1EA|1FC
B→1EB|1FD
E→1EE|^
F→1EF|1FH|0H
H→1
C→0A
D→0B
| – 12
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
we observed that
L= { aibjck| i < j and i < k } is not context-free. However, although no PDA can test both conditions
i < j and i< k simultaneously, it is easy enough to build two PDAs that test the conditions
separately. In other words, although the intersection L of the two languages
L1 = {a i bjck | i < j} and
L2 = {aibjck | i < k}
is not a CFL, both languages themselves are. Another way to verify that L1 is a CFL is to check it is
generated by the grammar with productions
S→ABC A→aAb|˄ B→bB|b C→cC|˄
Similarly, L2is generated by the CFG with productions
S→AC A→aAc|B B→bB|˄ C→cC|c
The second statement in the theorem follows from the first and the formula
L1∩ L2 =( L1’U L2’)’
If complements of CFLs were always CFLs, then for any CFLs L1 and L2, the language L1’and L2’
would be CFLs, so would their union, and so would its complement. We know now that this is not
the case.
15. Give the difference between Top Down & Bottom Up parsing.
Top Down Parsing Bottom Up Parsing
| – 13
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 14
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
Finite
control
| – 1
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
hr
∆/∆,R ∆/∆,R
∆/∆,R
b/b,R
a/a,R
∆/∆,R a/a,R
a/a,R
b/b,R
q0 q1 q2 q3 ha
b/b,R
| – 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 4
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 5
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 6
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
x/x,R
| – 7
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| – 8
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| 1
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
| 2
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)
lOMoARcPSD|41915712
• On the other hand, suppose that f is μ-recursive. Then by definition, pf is μ-recursive. Let T be a
TM computing it. From the formula for pf we have
g2’(ρf(n))= g2’(g2(f(g1’(n))))
= f(g1’(n))
• for any n. applying this formula when n= g1(x), we obtain
f(x)=f(g1’(g1(x)))= g2’(ρf(g1(x)))
• Just as before, we can now construct a composite TM T f to perform this computation, and it
follows that f is computable.
| 3
Downloaded by Sushil V Chaurasiya (sushilchaurasiya37@gmail.com)