Computer Science Exam Prep Guide
Computer Science Exam Prep Guide
f.V.B.$Cr Gomputer
F
f-
Sem I
Section-l Section-ll
a
I
I
CHAPTERWISE YEARWISE
Paper-ll
Theoretical GomPuter
Science
/IS i11,.;
l, 8'.,.r:,
",;'' .
o t,r$r0il PUBHCffiI0tl$
\
t
ection-!
Expected Questions (Ghapterwise)
Chapterl Preliminaries
o,
t-.4.,,*..)d Chapter 2 Finite Automata
!r8r0lt PUBuG0I|0[$ Chapter 3 Regular Language
Chapter 4
|9/1, Budhwar Peth, Appa Balwant Chowk, Pune - 2.
vebsite: ww t',visioDpune. com
Context Free Grammar and Languages
)Eail: visionpublications@gmail,com Chapter5 PushdownAutomata
info@visionpune.com
Chapter 6 Turing Machine
Edition:
First: 2015
Jecood:2016
{ll rights reserved by Vision Publications. No part ofthis book is to be reproduced or transmitted in
rny fom, Electonic, Mechanical, Photocopy or any information stored in a retrieval system without
orior permission in writing, fiom Vision Publications, nor be otherwise circulated in any form of
binding or cover other than that in which it is published without a similar condition being imposed
@
ln the subsequent purchaser.
Printer
ulsl0lt
AP Vision Design & Prinls Plt Ltd, S.No. 83-2, Shivne Ind. Area, NDA Rd., Pune-23
Note: Due care has been taken while editing, printing and binding ofthe book. Neither the editon
nor publishen of the book hold any r€sponsibility for any mistake that may have inadvertently crept
in.
[f you notice any errors in
the book and wish to
report, please login our to
website www.visionpune.com and write comments on this book on the site. You can search this
book by entering Book ID mentioned below. Thank you.
@
tl
www,visionPune.com
1. Onllne book storo (Checksolect'Buy)
4. qubk Soarqh for books ot dlflerent Unlvorslllos' 1, Define prerix and list all profixos of ths string "xyz". (October 2012)
Solution
5, Opsn your account & gsl dbcount Polnls on each Pulcha3e'
A prefix ofa sting is any number of leading symbols ofthat string
6. Gottho book at your doo., don't wasto tlmo
& money on petrol'
I Prefix ofstring'xyz' = {s, x, xy, xyz}
7. Know the top solllng E speclal books along
wlth new arrlval!'
2. Let A = {a, b} and B = {e, d}. rind A x g. (October 2012)
Eonogolutlonlorallyournged!.ToxtBooks/PaPorsolutlon&compolltlveExams. Solu0on
A={a,b} andB=(e.d}
A x B = {(a e), (a, d), (b, e), (b, d)}
3. ff A = {E} then what is the valuo of lAl? 6pfl 2013)
Solu6on
e is empty string so its length lAl = 0
i lt
4. Let A = {a, b, c} and B = {1, 2, 3}, then writo the Cartesian product of A and B.
(October 2013)
Solution
doo!(!
A x B = ((a, 1), (a,2), (a, 3), (b, 1), (b, 2), (b, 3), (c, l), (c, 2), (c, 3))
,,."'
5. Define term "Empty string" vuith examplo' (Apil 2014)
I Free 5hipping
Solution
I
pI j
6.
Empty string is a string which has only ore member e and is rcpresented as (e )
Solution
What is ths value of n, where n = lel? @pfl 2014)
7.
-&*!"'
w State truelfalse: ProPer suffix sot subsst of suffix set.
ffis
Solution
I
True
W visionpublications@gmail.com
8.
Solution
Stato true/false: Lsngth of string
False
't' is non"zero.
(%
T.Y. P ll-Theoretical Computer Sciencei . Preliminaries ut8t0i
\
. . Preliminarios
a T.Y. P ll. Thsoretlcal Computor Sclence I . Prellminades (^
T.Y. P lt- Theoreiical Computer Science @ u$0i ullt0r
Only those "formulas" that can be produced by application ofrules I thrcugh 4 are Regular 1. L+M=M+L
expression over E. 2. (L+M)+N=L+(M+N)
3. (LM)N = L(MN)
!l f a pw r t.tp tg! !
ow_r! g-{ 9- M gI l!9- age-stiqFli Here note that LM * ML
I Marks for tl}€se Questions may vary fmm 4 to 5 ii, Dlstributivity
Explain with example Standard operations on languagos' l. L(M+N)=LM+LN
)lution 2. (M+N)L=ML+NL
Union: Given languages Lr and L2 we define their union to be the language Lr u L2= {x I x e iii. Identitics md AnhilatoN
L1 ORx e L, )
l $+1=L11=1
Cotrcatenation: Given languages L1 and L2 we define their concatenation to be the
language
2. eL=Le=L
Lr olz= ( xy lx e Ll andY e L2 } i 3. 0L=10=0
Ex. l
iv. Idempotent Loy
a. Ll = {he o} and L2 = {world} then Ll " L2 = {}rslloworld} I. L+L=L
b. L1 = [00, l0); L2 = {0, l}. Ll 'L2 = {000,001, 100, 101}
th
T.Y. P ll- Theoretical computer Science I E . Prsliminaries ursl0I
Closure Laws
I (L)'= L' Fimito Atttowuta,
2 (O)'= e
3. e'= e
Solution
6k-e-'@
Language desffibod by NFA is
L = (a a*b*b)
= The set ofall elements which start with a contain any or none a's followed by any or none b's
and ends with b over {a" b}.
'14, State true/false: lf the length of input string is n, then the output gonarated by
e Mooro machine will bo of length n + 't.
a. Write mapping of 6 in case of NFA with e ' Closure' $pil 2014) Solulion
Solutlon True
Solution b b
one ofthe states as its value'
if," registe, of tf," machine is also called the finite control contains
value of the register is q6 i e stsrt stste of FA'
et t'f," l"iinnirg of computation, the
'
" a
In NFA, one state on one inPut symbol may tansit to none or many states'
,l1. ln how many different ways DFA can bo reprosgnted? - M = ({qo q,, qa qr, q4), {c b}, 6, q0, {qr q, q,))
Solution where 6 is
FA can be repres€nted bY 2 waYs - a b
i. state- transition diagram qo q3 ql
ii. Transition table ar q3 az
olution
e -closue and transition table
0,1
6
0
0 1 €- closure
0
ao q1 qo {qo, q,}
ql at q, {q,) 1
Construct DFA for a languags over {a, b} which accepts all strings that 3tarts
eru0i
a, with 'aa'but not having 'aa'as substring in the further sFing, (October 2012)
q, x x Solution
ql x x x A
q1 X X x x
a a
9s x X x x
qoq,ASqr a
a a,b
s 0
1.<
o,€
1t1
s 0
111 0/0
1,€
0,e
0/0 111
6 0 1 € closure
1t1 ql}
qo qr ao qi qo {qo
qJ (qo qd qi o q, (q,
0/0 q, ql
q2 {qo ft} q2 {q2, qo, q1}
q3 q? q3 q, q3 {q3. or, qo, qr}
Transition table
6 ),
Here final state = q2.
0 1 0 1
qj 0 1 Start state in NFA = q6
ql 0 0
1 1 .. start st3te of DFA = € -closure (q0) = {q, q,} = A
qj 0 I
(s 0 1 .'. 6'(A,0) = e-closure (6^(A, €),0)
0 0
= e-closure ({qo, qr}, 0) = e-closure (qr qo qz) = {qo qr qz) = B
6'(,4., 1) = €-closure (6^ (A, e), t) = A
a=r'::--
={qoqrq2}=B Soluoon
.. Final DFA The table is
00 qj x
c, X
1
1 9r X X x
TTT-' q. X X x x
B B c q5 X X X x X
1 C B c Sqrq,q!q'
0 Mark (final. non-final states) as X
.i Mnk - (q0, q, (qr qr) (qz qr) (qr q) (qo q') (qr q:) (qz qr) (q, q)
Check (qo qr) + mark X
Check (qq q) ma* =
=
gives output .A, if string mark X
construct Mealy machine to accePt strings over (a, b} and Check (qo qr)
=
JJri'i* 'r'"il 6rr!; output'B' if itring contains 'bba' slse gives outPut'c" Check (q1 q) > mark X
(October 2012)
Check (qr qr) + mark X
)lution
Check (qr qa) mark X
Melay machine =
at. Check (qr qs) mark X.
=
. . Minimized DFA
alC alC
a
a tq,q,
b/c alB
b
alB
b
b/B a
T.Y. P ll. Theoretlcal computer Science r l[ r Finite Automata
(k
urfl0,t
T.Y. P ll- Theoretical Computer Science t r Finite Automata
Stan
s
The diagram has 3 nodes i.e. 3 states.
a,b qo: Start state (pointed to by 'start' arow)
q;: Final state indicated by double circle.
a,b
a b a,b Each arc represents the transition made on a state q on some input symbol and reaching to
other state.
Solution
q0 contains one arc on input symbol 'l', rcaching to qe is called a self loop.
Transition table and e moves
lt. Transition table: A tabular listing of 6 function which tells us the set of a states and the i/p
a b € closure alphabet.
d
(qo,q1'qr,qo)
9o o
Transition tqble
ar as d iq1)
q2 {qr,qa} 0 {q2, q!} a. lt is a conventional, tabular.repr€*enlgtion ofa function like 6 that takes two argunents
$
qj {q,} arld retums a value.
q5 {q,}
q4
qs {qr,qs}
{or,q5}
{qr,qs} (q5) b. Rows ofa table corie-spond to the states.
c. .tr['olumns ofa table conespond to rhe input symbols
Stan state ofNFA = qo
d. The entry for the row conesPonding to state q and the column coresponding 10 input
.. start state of DFA = e -closure (q0)
'a' is the state 6(q, a).
= {qo,q,,qrqo) = A
e. Start state is marked by '+' (anow).
. . 6'(4, a) = e-closure (6^ (A, e), a)
f. Accepting states are marked by r (star).
= e-closure (qr 9:, 9r, 9:)
= {qr, q+ qr qr} = B
T.Y. P ll- Theoretical Compubr Scienco .@ a Finite Automata
().
ott 0i
o"
T,Y. P ll- Theoretical Computer Science a t Finite Automata
0llt0i
Exanple
6'(4, b) = e<losure (0" (A, e), b)
Thc transition table conesponding to the function 6 is as shown
--+
N.
9o
0
9z
I
qo qo - start state
= € -closure
= {qn, qr} =
(q4,
c
q,
a
a,b
The execution of an instruction alteN the state of the machine and moves the tspe head one b
L The instruction set is obtained from the tratrsitiotr function ofthe FA,
ii The machine state and the symbol scanned determine the instruction to be executed.
13. Convort following NFA with € moves to DFA, (October 2013)
The objective of a computation of an automaton is to determine the acceptability of the inPut a
string.
/. The computation begins with the tape head, scanning the leftmost square ofthe tape and the s
re8ister containing the state qo.
i. The machine then alters its state as per the instsuction and the tape head moYes to the right a,b
/ii. The instruction cycle is repeated until the tape head scans a blank square, at which time the
a,b
computation terminates. a b a,b
riii. An input string is accepted ifthe computation terminates in an apcepting state Otherwise it
is rejected.
o T.Y. P ll. Theoretlcal Computer Sclonce . E a FinitoAutomata o
ut8l0i
T.Y, P ll- Theoretical computer Scienco @ t Finite Automata
. . final DFA=
olution
Transition table and € moves a,b
a
a b e closure
b
qo b o {qo,q,qr,q.}
= {A,B,C,D,E}
q1 q3 b {q'}
(qz, qo) b
q2 {q:,qd o -
as s qr {q, b
aa
q5 {tu,q5} (q,)- b a
q5 {qo,qs} {qo,q'} {q'}
(qa, q5) a
= e+losure
= {qo, q5} = c
6'(8, a) = e-closure (6"(8, e), a) b,c
olution
I'u"
ao qo (qo, q, e - closure (qo)= {qo, q1, qr, $)
q1 { o € - closure (q1) = {qr, qr, $} i
92 (qz, q") q2 € - closure (q, = (qr, ft) I r the following ( 1 Mark Ouestion
q3 (qr q,) q2 € - closure (q3) = (q3) l these Questions may vary Imn 1 to2
6' (A, b; = s - .1.tue {qo, $, q2} = A 2. Find the Regular Exprsssion for the language containing exactly zb's over
rl . ,= {a, b}. (APrit 2012)
L1nL2 = G; uL)'=G+L;)'
i.e., the language L1 L2, consists ofall words that are not in either Li or Li since Lr and L2 are
^
regular sets. Then, Li and Li are also regular.
(),
T.Y, P ll-Theoretical Computer Science a I Regular Languages l,lst0n
T,Y. P ll.Theoretlcal Computer Science I a Regular Languages
T.Y, P ll-Theoretical Computer Science i Frl I Regular Languages
I
Lj + Lj is also regular, as Li and Li are also regular. 8, State any two oparations on languagEs, (Apfll to'i:J !
Solution
. . (Li + L;)' is rceular.
Operations on languages
'. The class ofregular sets is closed undcr complementation. i. Union
.. Lt n L2 is regular set. ii. Intemection
(u.L;) .
I
S 1 1
Solution
Construct FA for L = {€}. (October 2012)
rlution The set ofall strings over {0,1} where each string has exactly one
.,1,,
in it.
FAforL=(e} I
10. Write RE for tho set A = (aa, aaaa, aaaaaa....)
Solution
R.E. forA=(aa)",n> 1
,olution
. = ab*(a +b)r + ba*
rl'12
rr = ab' (a+b)r 12 = bar
13 rl3
-+- = rto tll
!=ab+ ra = (a+b)r rro=b
17 = a+b
Tt1 a
_,re-,re
r
a
ttz
rro=b
14=a
f2 = floflr
rq=b h=18+19 I
b
h
€
r13: (a + b)* = (r1a * 115)* : 116*
Ql a
r a
e r,
{rc E o"
T.Y. P ii. i!r;(-r.etical Computer Scienco t r Regular Languages ullt0ll T.Y. P ll-Theoretical Computer Science r E a Regular Languages ()'
ullt0i
2 Show that L = (anbncn) is non-regular using'pumping lemma of regular sets,
(October 2013) T
Solution
Step l: Assume that L is regular. Let n be the number ofstates in finite automaton.
Step 2: Let w = a5'ci in L.
By pumping lemma, we can urite w = xyz with lxyl< n and lyl > 0.
Step 3: Now try to find out ry'z e L.
There are few oases by which we can split string into x, y and z.
Cqse l; x=c
y=a
z= bnao
{ Case 2: x= an
v=b"
... , = laba)i
Fori=lw=abaeL.
For i- = 2w = abaaba e L.
)
r
(
T.Y, P ll-Theoretical Computer Science t F;l Regular Languages ullr0
' Construct melay machine that outputs'V'for valid' or 'l'invalid' for a language
(A1ril 2014)
L = a(a + b) 'b. E Ansurer t rk Questions) :
,lution Ma*s for these Questkns nay vary frcm 1 to 2.
,|
L=a(a+b)'b Construction Regular Grammar, G, for following automaton, 6pil 2012)
b,1 a b
I
b
all
brl a
Solutlon
all btl
S-rAslbBla
Transition table
B-rbBle
9o
qi
9r
q1
a,
qj
9o
2, State what is nullable symbol? (April 2012)
er
Solution
9z ar qi q?
ag 9e q3 ar
In a given CFG, a nonterminal N is nullable ii
a. There is a production N -+ e or,
State the steps how pumping lemma is applied, b. There is a derivation that starts at N and leads to e. i.e. N I e
,lution G
given
Pumping lemma is used to prove that ceftain sets are not regular' The steps required for the The nullable symbols are dangerous as they lead to e-productions
I is not regular as follows:
. Assume L is regular. Let n be the nwnber ofstates in FA which accepts L' 3. Define ambiguous grammar. (October 2012)
Solution
Choose a string w such that lwl > n, using pumping lemma, write w = xyz with lxyl < n
A CFG is called ambiguous if for at least one word in the language that it generates there are two
and lyl > 0.
possible derivations ofthe word that conespond to differcnt syntax hees.
. Here you must picked finite integer as'n', the constant mentioned in the pumping lemma' i
Find suitable integer i such that xy'z e L. 4. What is the yield of following derivation tree? (Qctober 2012)
It may then be concluded that L is not regular, so it contadicts th€ assumption we have made I
in step l.
Hence L is not regular.
-,,1\
o,
utsl0lt
t'
Y, \\O
Solution B+CbBlb
E - symbol
does not yield terminal . . eliminating C -+cC lct CbB lb
G: is not reachable ftom start symbol . . eliminating All above productions in CNF.
Rewriting grammar
S +aAIBD
3. Convort the following grammar to GNF (Apnt 2012)
S-+BB
A-+aAlaABlaD
'B+aBlaclBF A-+AAla
B-+AAlBAlb
C+BblaAC
Solution
D+bDlbCib
Grammar is already in CNF.
FiaFla Lets replace S by Ar, A by 42 and B by 43.
'B' and 'C' are not reduceble to terminal symbol .. eliminating.
.. Ar + A3A3
lewriting grammar
42+A2A2la
S)aA
A -+aA aD
Ar , A2Ar l AjA, b
Substituting A3 in Ar Hence, we can say that, CFL'S arc closed under union.
6. Rewrite following CFG after eliminating unit productions' (October 2012) Substituting A2 in Ar and Al
S -) aAblA -)
A -+ Blb
-+ bA b
B+e
. D-+F Substituting 42, Ar in pr
F -+ 01lB p' + blbprl bAjArbprArArlaArbprlbprprlbAlA, DrlbprArA, 0rlaA2pr
Solution . . whole grammar is
' S+ A-+€ Ar)bArlbprA3
A J B-+ € substituting ftmction
Ar-+ blbpl
SrA *A+bl€ 41 -+ bAslbpl43la
.. S -r aAblble p1 -+ bibplibAy',lbplArA, aArlbgriborprlbAdrorlborAdzprlaAzpr
A -+ elb After resubstituting A1, 42, A1 by S, A, B respectively.
D + F and F + 01lB are eliminated as D and F is non reachable from stad symbol'
S --r bBlbp 1B
.. final productions are:
A -+ blbpr
S-+aAblb e
B -+ bBlbplBla
A-relb p1-+ b bpllbBA bplBA aBl bpllbplpllbBA p1b0 rBADrlaBpr
7, convert following grammar to GNF' (October 2012)
S-+AB 8, Construct CFQ fqr L = {arbvcz I x>y+z} , (Apfl 2013)
s -+ AAlsAlb Solutlon
B -r ABla The language set
Solution
L = la, aab, aac, aaabc, aaabb, aaacc, aaaabbc, aaa
The grammar is already in CNF.
To generate shings ofa* when y = 2 = I
Replacing S by Ar
S --r aAla
AbyA,
A e aAla
. BbyA3
A1 -+ A2A3
Whenz=0 wheny=0
A, r bl bBl A + aAla
B -+ cBlc
0r + ArArArA20 rlArA,0 |
C + bclb
T,Y, P ll-Theoretlcal Compuler Sclonce t a context Free Grammar and Languages i#.
(Apfl 2013)
T.Y. P ll-Theoretical Computer Sclence a I Context Free Grammar and Languages .*
9. Rewrite following CFG after eliminating useless sym bols.
0r --r &lAzPr
S -+ 0Ai/BD
A -r 0AA/011 Consider production Ar 9 ArArlb 2< 3 .. leave production
D-rA0 . . Substitute A2 in A1
E -+ 1D/0
Ar -r Ad:Au lbA., ia
Solution
Removing immediate left recursion
i. NT 'E' is not reachable ftom start symbol
Ar + b&la bAz0zla0z
.. it is useless.
-+ lvAzlAzAzqz
Production E -+ lDld
Fz
.. we remove
Substituting 43, in A2 production
ii. NT 'B' is not getting derived to teminal symbol in the grammar
.. it is useless. --)
. . We remove 'B' productions from the grammar Substitute A.2 in pr and p2.
S-+BD pr = bArArlaArlbAr0rArlagzA:lblbArAr0rlaAzgrlbA:0rAuFrla0rAzPrlb9r
B-+0BllB0 A:Fzl
gz= bA:ArArlaAzAzlbAzgz&Arla0z&AzlbAzlbAzAzArPrlaAzA:0zlbAz0zAz
iii. With this NT'D' is unreachable from start symbols
aFzAzAz0rlbAzPu
.. it is useless
.. we remove D -+ A0 Resubstituting S, A, B values for A1 42 43 respectively the final gammar becomes:
A -+ BAlb (Aprit2013)
11. Minimizo tho following DFA
B -r AAla M = ({qo, qr, qr, er, 9o 9s}, { 0, 1 where 6 is given by
Solution 6 0 1
Replace S bY Ar 9o 9r 9o
AbYA2 9t 9e 9s
Qz Qs 9r
BbY43 9r
9r 9r
Ar + ArAra 9r 9s 9t
Qs 0r Qr
A2 + ArArb
Solution
A3 + A2 Ara 9, X
q, x
Consider production Ar -+ ArAzla
9: X x X
Removing immediate Ieft recunion qr x X
q5 x X x X
) ftq,q,ftq.
T,Y. P ll-Theoretical Conputer Sclence . @l a Context Free Grammar and Languages ,# T,Y, P ll.Theoretical Compuler Science I t Context Free Grammar and Languag$
ia
Mark 'X' - one final and one non-final slate Y=ryzlb
.: Mark (qo q) (qr qr) (q, q,) (qo, qr) Z-+aldle
(qo q,) (q, qr) (qr qr) (q,, q) Removing e production
Mark (qr qo), (qo q) as 'X' X --| axbdz I aXbYdZ
Y +XYZ -t let XY + Yl
(qr q: qJ '.Y )Y&
0,1 is in CNF.
Yi -+ XY
0
-+ )b )
.. X-rA1 aA2A3ZIAtXA2Y AtZ
(q,, qJ
Let Xr + ArX, Xi-) A3 Z, X3 --rA2 Y
.'. X r Xr 42 Xr lXr X2 X3
0
Let & -+ Xr A2 .. X -) Xa X3lX5 X3
12, Construct CFG for the following languages: (October 2013)
X5 -+ X1 X2
i. L={a"b'c'lm > 0, n >'l}.
. . Final CNF
ii. L=(w6vRlw€ (a+b) *). X+XaXr lX5 Xr
Solutlon
Y -+YtZlxzlb
L{aabcc,aabbcc,....}
Z-+ald
Terminal string is aacc. -r S -+ aacc Y+XY
To generate multipte (aa)'(cc)* -+S --r aaScc Xr +ArX
To generate string like aab*cc -+ S*r aaAcc and A x2-> A1z
-r bA I b
ijo the final CFG is - Xr-+A2Y Ar)a
c = ({S,A}, {a,b,c}, P, S)
Xa-+X1 42 A2+b
X5+X1X2 43-)d
Where P is:
L
S + aascc I aaAcc aacc 14. Construct FA for the following regular grammar. (October 2013)
A-+bAlb S-+aAlbB
A-+aSla
13. Convert th6 following CFG to the equivalent CNF. (October 2013)
I B-+bSlb
X-+aXbYdZ
Solution
Y+XYZlb Construct a finite automata coresponding to following grammar:
Z-+aldle S-+aA bB
Solution A-+aS a
X + aXbYdZ B+bSlb
T.Y. P ll-Theoretlcal Compute, Scienc€ a @ a Context Free Grammar and Languages
!fi T.Y. P ll-Theoretical Computer Science r 4-15 t Context Free Grammar and Languages
The finite automata accepting the language generated by above grammar will be 16. State and prove union and closure property for CFL. (April 2014)
M = ({qo qr, qz, qr}, {a, b},6, qq, {qr)) Solution
where, q6 conesponds to S : start state IfLr and Iz are CFLS, then there union is also a CFL,
ql coresponds to A, q2 corresponds to B
IlLr is a CFL, then it is generated by grammar Gr = (Vr, ,r, Pr, Sr)
qfnew final state
5 can be defined as: If Iz is a CFL, then it is genemted by gmmmar G2 = ry2, 12, Pr, S,
Production Corresponding transition We have to show L = Lr v Lz.
SraA 6(qe,a)-+q1 Let L b€ generated by a grammar G,
S --t bB 6 (qe, b) -+ qr
A -+ aS 6 (q1, a) -+ q6
G=(V,u%u{S},Lut,P,S)
)
A+a 6(q1,a)-+q1 Let L1 is a language containing equal number ofa's and b's.
B+bS 6(qr,b) -+ Qo .. A CFC Gr = ({Sr), {a, b}, Pr, Sr))
B+b 6(qz,b)-+qr
Pr = {Sr -+ aSr b I ab}
.. The conesponding FA willbe:
a Let L2 is a language generated by gammar Gz = ({Sz}, {a, b, c), Pz, Sr)
aB
,z'\ ,z'\
aB aA lt
Hence, we can say that,
CFL'S are closed under union.
aAB ab
,/\\ I I
JA Here we are applying productions repeatedly in derivation, to get closure.
Abb b
/A\ xr
a/ I
x So the word in L' represented by CFG.
Ab bb abb
I
.. We can say that CFL'S are closed under kleene closure.
abb
a Context Free Grammarand Languages r* T,Y, P ll.Theoretical Computer Science a
IE r Context Free Grammar and Languages
.fi
T.Y. P ll-Theoretical Computer Science
' lE
17. Convort lollowing grammar into GNF'
(Apfl 2014) 18, Explain in detail the differenco b€tween the notations - +and l? a
GG
S+AB Solution
A -r BSld ,
+ directly derives and > means derives.
, B+ASlh
Solution IfA -r p is a Production ol P and o and y are any string in [V u T)', then
Replace S bY Ar, A bY A, and B bY A1
oAy + apy.
' .. Grammar b,ecomes c
A.1 -+ 42 43 We say that the Production A -+ p is applied to the string cA1 to obtain o.Py or oA1 directly
A'z+ArArla derives uP1 in grammar G.
Ar -+ Az Ar lb Two strings are related by (or +) exactly wher the second is obtained from the first by one
= G
Consider A1 A1
+ A2 1 <2 leave
application of some Production.
Az -+ArAr 2<3 leave
+ (derives)
A3+A2A1 2>3 G
S+bsBlbPSB
Let G = ({Ao A,, .... A"), L p, Ae} be a regular right linear gnmmar
The finite automata is constructed as:
A-+bSlbPSla
M= (Q, L 6, qo, F) where
B-+blb0
P -r bsBSP IbPSBSB IbSBS bPSBS Q = Number of states conespoDds to number ofnon-terminals.
is the final grammar in GNF. ! = Number of input alphabets is sarne as number of terminals.
Method 2: Used when production is A -+ a B. l Slate }vhich machines are used for type 1 and typo 2 grammar? wfl2012)
Let G = (V, X, P, S) be a regular grammar then its equivalent FA with €-hansitions Solution
is: Machine used for type 1 grammal 3 Linear bounded automata.
M=(Q.I.6.tsl. ttsl)) Machine used for tlpe 2 grammar a Push down automata.
where, Q is aset ofall productions rules piessnt atLHS as well as RHS. 2. State True/False: Power of PDA and NPDA i3 difterent. fipfl 2012)
r+.
i.e., q is cun€nt state.
w is input left to read.
o, IfM
o is on stack (fi$t symbol ofo is top of stack).
= (Q, X, f,6, qr, Ze, F) is a PDA, we say (q, aw, Za) f- (p, w, po,)
5. State two methods fordefining language accepted by PDA. (October 2013) 12, What are compatible transitions?
Solution Solution
i. The languages accepted by final state by some PDA. Two transitions [q, C] e 6(qi, u, A) and [q6 D] e 6(q1, v, B) are called compatible if any of the
lollowing conditions are satisfi ed:
ii. The languages accepted by empty stack by some PDA.
i. u=v and A=B
6. Tho clasg of languages accopted by DPDA and NPDA is same, Justify truo or ii. u=v and A=eorB=e
false. (October 2013) iii. A=Band u=eorv-e
' Solution iv. u=r orv=E and A=e or B=e
False, there is some class of languages which are not accepted by any DPDA but arc accePted by Compatible traDsitions can be applied to the same machine configurations.
NPDA as shown below.
13. State true / false: A PDA is detorministic if it doas not contain distinct
compatiblo transitions,
Solution
Languages accepled
by NFftDFA True
1, Prove with guitable sxamplo DPDA and NPDA ars not equivalent' 6pfl 2012)
7. State True/Falss: Power of PDA and NPDA is different. Apil 2014)
Solution
Solution
True
i. For finite Automata, the deterministic and nondeteministic models were equivalent with
resp€ct to the languages accepted.
8. State true/fals6: FA accopt every CFL.
The same is not true for PDA. There is some class of languages which are not accepted by any
Solution
DPDA but are ac.epted by NPDA. As shown below.
False
9. State the difforence between 'acceptance by final state' and 'acceptance by accepted by
empty stack'.
- Solution accepted by
Acceplance by final state: PDA accepts its input by consuming it and entering an accepting state. Languages
We call this approach "acceptance by final state". accepled by
' Acceptance by empty stack: The set of strings that cause the PDA to empty its stack, starting
NFA or DFA
10. State True/ false: For a given PDA P, the languages that P accept by final state DPDA is a special case ofNPDA. NPDA and DPDA rre trot equivalent.
and by empty stack are usually same. The languages accf,pted by deteministic pushdown automata include all regular languages
Solution and are a proper subset of the context fiee languages. This family of languages, which is
False important for Fogramming language definition and parsing, consists ofthe languages that car
11. When do vve call a PDA is deterministic? be generated by LR(k) grammars.
Solution i.e., DPDA's accept a class of languages that is between regular languages and the CFLs.
A PDA is deterministic ifthere is at most one tmnsition that is acceptable fbr each combination ol The languages accepted by NPDA, include all the languages which are actepted by DPDA
state, input symbol and stack top. and which are not accepted by DPDA. i.e., all the context free languages.
o.
T,Y, P ll-Theoretical Computer Science t r Pushdown Automata ullt0t T.Y, P ll-Theoretical Computer Sclence a
l-,;l a Pushdown Automatr
slel
a
Example, 5 (q, c, R) = 6(q3, R)
lx. 6(qr, €, R) (qr, s) acceptance by empty stack. 4. Construct PDA fel l = {6nbcm/n, m > {, n < m}. 6pil 2013)
Solutlon
x. 6(q,, e, R) (q" e)
Language set L = {abcc, aabccc, aaabccccc)
(October 2012) 6 (qe, b, R) = enor
2. Construct PDA for L = (a'bmck/ n, m, k > 1, n < m),
6 (q6, c, R) = enor
Solution
6 (qs, a, R) = (q6, BR)
,O41or 1 = 1a" b' ct/ n, m, k > l,n<m)
(qc BB)
1= {abbc, abbcc, abbbc, aabbc
... . }
6 (qo, a. B) --
6 (qo. b. B) - (qr. B)
6 (qo, a, R) = (qo,BR)
6 (qr, b, B) = enor
6 (q6 a, B) = (qq, BB)
6 (q1, a, B) = enor
6 (qo, b, B) (qr, e)
= 6 (q1, c, B) = (q, e)
S (qr, b, B) = (qr, €)
6 (q1, c, R) = (qr, R)
6 (q1, b, R) = (q,, R)
6 (qr, c, R) = (qr, R)
6 (qz, b, R) = enor
6 (q2, e, R) = accept
6 (qr, c, R) = enor
6 (qz, c, R) = 6(qr, R)
I
0" th
T.Y, P ll-Theoretical Computer Science I . Pushdown Automata T.Y. P ll-Theoretical Computer Science I E a Pushdown Aulomata
utst0i
iii Read 2d 'b' pop stack. (q,, BG) -) Push B when TOS is G
6(qr, o, G)
iv Rep€at 2 and 3 for,all b's 6(qr, I, B) (qr, cB) -) Push G when TOS is B
Let the PDA M = Qt, a:) a, b) {R, B 6, RO) 6(q1, 1, c) {(e,, cc; Decision making whether to push G for
6(qo, s, R) -) ERROR (qa e))
) I or POP when TOS is G.
can't start with b or e
6(qo, b, R) ERROR vll. 6(qr, o, B) (q:, e)
POP for all a's and b's
6(qo, a, R) ) (q,), BR) vIl 6(qr, I, G) (qz, e) )
Push B for all a's lx. 0(qr, e, R) (qr. e)
6(qq, a, B) -) (qo, BB)
Acceptance by empty stack.
x 6(qr, e, R) (qz, e)
6(qo, e, B) J ERROR ) if No 'b' after a.
6(qb b, B) (qr, B) Accessible ID's for the above PDA when yp is 001100
Read I't b. No change in stack.
6(qr, b, B) ) (qa e)
Read 2d b, PoP (q1, 01100, R) --+ (qr, 01100,8) --+ Reject
6(qz, b, B) (qr,B)
I
6(qr, s, B) ERROR -) After reading l'r b, string ends. (qj,01100, BR)
6(q1, a, B)
qqr, t, R'l |
-,
-
ERROR
(qr, s)
After reading le b, 'a' aPPears.
Empty stack; accePt
I\
(q1, 1100, 8BR) (q?,'1100, R) ---t (qr, 1100,8) --+ Rejecl
6(q1, e, R) ERROR ) After reading l'i b, string ends.
o(qz, e, B) ) ERROR J No. ofa's # (no ofb's)
12 I
(ql, 100, GBBR)
6.
6(qr, b, R)
examPl6.
J No. ofb's don't match
(Apil 2014) (q,,00,
I\
GGBBR) (q,,00, BBR
Solution
A PDA M = (Q, t, l,6, qe, ft F) is deterministic if
Z'in F, whenever 6(q, e, Z) is non-empty, then 6(q, a, Z) is empty
for all a (q,, 0,
II
BGGBBR) (q,, 0, BR) ---t (qr, s, R) ---+ (qr,6, €)
i:
ii.
nor each
in !.
i
For no q in Q, Z in
in Q and
f u
{e} does 6(q, a, Z) contain mor€ than
and a in E one element'
(q,, r,
I\
BBGGBBR) (q,, t, GGBBR)
I
Accepl
I r Pushdown Automata
a T.Y. P ll-Theoretical Computer Science I E . Pushdown Automata o"
ullt0t
T.Y. P tl-Theoretical Computer Science
The tmnsitions (iii) and (vi) show the nondeterministic natue ofPDA.
6 (qo, a, B) = (qo, BB)
This is a typical example of NPDA which cannot be converted to'equivalent DPDA as NPDA is
D (qn, b, R) = enor
super class ofDPDA. Hence the proof.
6 (q5 c, R) = enor
6 (qo, b, B) = (qr, B)
6 (q1, b, B) = enor 8. W tg a short note on PDA moves.
6 (qr, q B) = enor Solution
6 (q1, c, B) = (qr, e) The PDA moves will be of two types:
6 (qr, c, B) - (qr, e) i. In this an input symbol is used. Depending on the inpul symbol, the top symbol on the stack
6 (qz, e, B) = eror and tlie state ofthe finite conhol, a number of choices are possible. Each choice consists ofa
6 (qr, €, R) = accePt next state for the finite control and a (possibly empty) string ofsymbols to replace the top of
6 (qz, b, B) = enor stack symbol.
6 (q2, b, R) = enor After selecting a choice, the input head is advanced one symbol.
6 (qz, a, R) = enor
6(q, a, z) = {(Pr, tr), (P,, 1. ... (P,,IJ}
6 (q2, a, B) = enor
ID for'aabcc' where, q, Pi: (l < i < m) are states
(qo, aabcc, R) F (qo, abcc, BR) a e X, Z is stack symbol
F (qo bcc, BBR)
Ii ef*(1 <i<m)
F (qr, cc, BBR)
is a PDA in state q, lyith i/p symbol a, top ofstack symbol Z.
F (qr' c, BR)
F (qr'e' R) For any i, PDA entffs in state Pi, replac€s symbol Z by string y1 and advances the input head
= accept one symbol.
(q,, 100, GBBR) Exornpie, consider a move in which PDA writes a s),rnbol on the top of the stack, 6
t\
+\ has a value (q, y)
(qj,00, GGBBR) (qr, 00, BBR) where, lll
=2
I I i.e. 6(q,,0, R) = {(q,, BR)} lyl = z.
(q,,0, BGGBBR) (qz , o, BR) ---) (q,, €, R) --t (qr, 3, e) I
t\ Accept
I If 11l > 1, it allows to increase the length of stack
If lyl = 1, the PDA would simply replace the top symbol by a new symbol and
by l1l new symbols.
9. DPDA is special case of NPDA. DPDA and NPDA are not equivalent' Justify
Solution
For finite Automata, the deteministic and nondeterministic models were equivalent with respect
- to the languages acc€pted.
The same is not tru€ for PDA. There is some class of languages which are not acc€pted by any Answer the followin ark Ouestions) i
DPDA but are accepted by NPDA. As shown below.
.
The languages acc€pted by deterministic pushdown automata include all regular languages and
are a prop€r subset of the context free languages. This family of languages, which is important for l. Diffsrentiato between FA and TM. (Apfl 2012)
programming language definition and parsing consists of the languages that can be generated by Solution
LR(k) gammars. i14
i. Tape head: unidirectional Tape head: bidirectional
i.e., DPDA's accept a class of languages that is between regular languages and the CFLs.
I Only read head present. Read and write head present
The languages accepted by NPDA, include all the languages which are accepted by DPDA and ii lnput tape is filled with special blank symbol 'B'
lnput iap€ not necessarily filled wilh
which are not accepted by DPDA. i.e. all the context fiee languages. e symbol.
lnput tape lixed at one end and lnput tape is infnite at both ends
accepted by infinite at other
Languages
accepted by
2. Write tuple for LBA. (October 2012)
NFA or DFA Solution
LBA is defined formally by;
M = (Q, L r,6, qo, B, l. $, F)
I eI left end marker which is entered in the leftmost cell of tlrc input tape and prevenb th€ Read /
Write head from getting offthe left end of the tape.
$e Iis called rightend marker which is entered in the dghtmost cell of the input taPe and
preyents the Read / Write head from getting offthe right end ofthe tape.
(').
T,Y, P ll-Theoretical Computer Science t r Turing irachine 0llt0i
()"
T,Y. P ll. Theoretical Computer Science a FA r Tuing Machine o"
eliei
T.Y, P ll. Theoretical Computer Science r E r Turing lMachine
urEt0tt
3. Construct TM for L = (a" bz".t l n > l). (October 201 2) 7. Define recursively enumerable languags, (October 2013)
Solution
Solution
L = (abbb, aabbbbb A language L over the alphabet I .rur.,ubl. ifth.r. i, a turing machine T
is called recursively
qo
E
(qo,x,R)
l'lj.,X.,..
(q1,Y, R)
that accepts every word in
complement,ofL (every word in
L and either rejects
f* not in
or loops
L)
for cvery word in the language L', the
q5 err0r (0.,e,-; 8. Giva diagrammatic representation ofTuring Machino (TM). (October 201i)
q6 Accept state Solution
01234567----'
4. State true or falsa: Every recursive language is rocursively enumerable. T;fbTbT;TB]-B l-B
(Apfl 2013). Read/write
Special blank
head lnput
Solution lape
symbol
Finile control Qo
True as in Recunive language L a TM T accepts every word in L and rejects every word in L' and
in Recunively enumerable language a TM T accepts every word in L and either rejects or loops for 9 Construct TM whlch recognize well formedness of parenthesis ove((,[(,],1,)].
every word in language L'.
(October 2013)
, True TMs, with disjoint sets of non-halting states and transition functions 6r and & respectively, we
,l4. write Tr Tz to denote lhis composite TM
Writo lD of LBA.
Solution i. The set ofstates is the union ofthe two sets.
Solution iv. Ifeithsr Tr or T2 would reject during this process, Tr Tz does also
True
input tape 6f UTM?
v. TrT2 accepts Fecisely ifand'vhen T2 accepts.
{ 6. What information should be given/ rocorded on the
Solution
vi. In order to use this composite TM in a larger context, in a manner similar to a transition
diagran, but without showing states explicitly: we Mite: Tr + T2
i. The description ofT in terms of its operation or program area ofthe tape'
ii. The initial configuration ofT iestarting state and the symbolscanned (stat€ areaofthe
tape)' vii. We can also make the composition conditional,. depending on the cunent tape symbol'
T
when
T1 halts. We write: T1 a T2, which stands for the composite nachine Tr T Tz where is:
iii. The data to be given to T (data area ofthe tape)'
ura ,trg,t a -t*.t, o[one problem on lhe inputs to the second and so
( T.Y, P ll- Theoretical CompuGr Science a F7 a Turing Machine
a
T.Y. P ll- Theoretical computer Science I Ic;] I Turing Machine t
utSt0tt
Qr (qu a,L) ( qr, a, L) (qr, a, L) Error ll denotes reflcrive - transitive closure ofrelation F
Ol (q.' a,L) ( qr, a, L) (qr, a, L) Error
9s Accept State
3,
-' What is solvable and unsotvable problom of TM? Give any one example
of 5. Explain in brief variations of TM.
ilnsohafte proutem' $Pfl 2ua) Solution
Solution a. Multitrack Turiry machine: A Multitrack Turing machine is a specific type of Multi-tape
problem in the class'
i.
-' Solvablei If there is a TM (or algorithm), which when applied to any TM which has only one unified tape head. In a standard n-tape Turing machine, n heads move
always,eventually terminates with the conect yes / no answer, then we call the problem
independently along n tracks. In a n-track Turing machine, one head reads and writc's on all
solvable. facks simultaneously. A tape position in a n-track Turing Machine c.ontains n symbols ftom
problem in the class'
ii, Unsolvable: Ifthere is no TM (or an algorithm; which when applied to a the tape alphabet. It is equiYalent to the standard Turing machine and therefore accepts
eyentually terminates with the conect answer yes. we call the pioblem unsolvable' precisely the recursively enumerable languages
Exanples of lLnsolvable Ptoblens:
Control
l. For any programming language, to determine whether or not' One lape head to read
k symbols f.om the k tracks
a. A given program can loop forever on some input' al one step.
f'ack2
c. A given program eventually halts on the given input' : tr
whether or Track k ITJ rrT_l
2. Consider a program to evaluate xn + yn = z', n > 2, the problem to determine
not the Ptogmm will halt ifand when a solution is found'
b. Two-way TM: The tape is infinite to left and riSht end. So the input tape lool6 like -
4, Write a short note on TM moves.
Solution B a\ a- al a" B B B
After x; is processed ID becomes Here lhe input string is ar. a2. ar.... a.. The tape is loaded with adtlank symbols(B) to the left
xt,x:...x,.2Px, )Yr'.'.. x,' ofa, and to the righi of a.. So if qp is the initial state ofthe TM, ID coresponding to the initial
state will be qe, a1,a2,.....an B.
This is representerl asi x1,X1 ...xi-lqxi ."xnl-xl "x,-2Px, ryx,tr" xn'
r Ik i (h
T.Y, P ll- Theoreticat Computer Science
t Turing Machine T.Y. P ll- Theoretlcal Computer Science a Turing Machine
ul|0t
heads are increased. The assumption wite only once tape
c Muhitape TM; Here the number of tapes and read/write
of a finite control with k number ofheads'
is all the tapes are rwo wa1 infinite lt consists a b
Finile conirol
head 1 FSC
..Tape1
R/W head 2
.-.Tape 2
I-T-ftT_ttT_r
R/W head 3
. . Tape (
The language enumerated by an enumerator E is the collection of strings that il eventually prints
out. E may generate the strings in any order, possibly with repetitions. We must also note that there
each of
of the finite control and the symbols scanned by is no input to an enumerator. Also, ifthe enumerating TM do€s not halt, it may print an infinile list
ln a single move, depending on the state
the tape heads, the machine can - ofstrings. A formal definition ofan enumerator follows
Anon--tleterministicTMdiffersfromdeterministicTM,wehaveseenearlierinthissection'
state q and tape symbol X' 6 (q' x) is a set
oftriples' 6. qr,,,r e Q is final state
,ii"'n **;0, such that foreach
Exomple:
"riy
{(qr, Yr, DI), (qz, Yr, D, (q* Y' Dk)}
,11 = 1 a"b" nZ 0 ) the enumerator will output the following things -
where, k is finite integer'
{ e, ab, a2b2, arbr,......)
to be the next move
A NTM chooses at each step, any of the niples
symbol ftom another and the direction from
But it cannot pick a state form one triple, a tape
yet another triPle.
7. Explain operations of UTM.
dehned by a function from 6 : Q x
--r f Solution
From this we can say that transitions in NTM are
subseis ofQ x f x {L,R}. Examine the input to make sure that th€ code for M is legitimate code for some TM. Ifnot U
halts without accepting. Since invalid codes are assumed to represent the TM with no moves,
o Explain Enumerating TM and such a TM accepts no inputs, this action is correct.
Solution ll Initialize the second tape to contain the input w, in its encoded form. i.e. for each 0 ofw, place
Turing machine can use the l0 on the second tape, and for each I ofw, place 100 there.
An Enumerator is a Turing machine with an outPut Print€r'-The
sives a schematic of
an
p'#:;;;';;;; a.ri.. io p,int rh' iollowing
sri;;; diagram (Blanks on the simulated tape of M, which are represented by 1000, will not actually appear
enumerator on that tape, all cells beyond those used for w will hold the blank ofU. However, U knows
that, should it look for a simulated symbol ofM and find its blank, it must replace that blank
by the sequence 1000 to simulate the blank of M)
Place 0, the start state ofM, on the third tape and move the head of U's second tape to the first
simulated cell.
(k
T.Y. P ll- Theqretical Compuier Science t a Turing Machine ut0n
0i is the state on tape 3, and 0 is the tape symbol ofM thal begins at the
position on tape 2
scanned by U.
This transition is the one M would next make. U should:
a. Change the contents oftaPe 3 to 0t i.e. simulate the state change ofM, !o do so, U first
changles all the 0's on tape 3 to blanls and then copies diftom tape 1 to taPe
3'
o Section-l!
Question Paper Solution (Yearwise)
utst0ll
October 2015
Theoretical Computer Science
S+uxv.+w,
GG
where, x e (VvE), u,v e (VuE)*, andw e Et. A symbol that is not useful is said to be
weless symbol.
o"
T.Y. P-llTheoretical Compurer Sciencer
! . 2015 October 1693 urst0i
o, r 2015 October
o.
T.Y. P-ll Theoretical Computer Sci ence't
r 2015 october T.Y, Pll Theoretical Computer Sciencet ut8t0!
q3 q2 q1
1 (ch 5)
Defne lD of PoA. 1
SolutioD
at any tim€ and the remaining i& string to be
ln FA, ID is defined as cunent state of FsM Construct Moore machino and melay mach ins which oulpuB even or odd according to
processed to describe the finite state
machin (ch 2)
numbor of b's sncountgred are even or 0O6 or"1 2 =(a, b).
we need to specif, the curent state, remaining
i/p string to be
In PDA. as we have stack, solultotr
pro..rr.a ,n. ty,bols on the pushdown stack Moor€ Machine
-a (q' x' o) where q e Q' x e I' and oe f*' b a 5
. lfM = (Q, ,, f, 6, qs, za, F) is a PDA, then an tD is (Output)
. a b il,
a
q,
i.e., q is cunent state' qo qo even
rr=(a+b)t 16=o+a)* Language set L = {e, abc, aabcc, abbc, aaabccc, aaabbccc, .......}
e €
e e
q2
q3 (q1, x, R)
(q3, b, L)
(q3, b, L)
(q3,
(q3,
x,
x,
L)
L)
I(q.,, B, R)
€
Construct NPDA for a language: (ch 5)
L= {ooRloe ( 0 + 1)'}
€
SolutioD
15:=q q, rhe PDA M is ({ql q2), {0, 1}, {R, B, G}, 6, q, & 0)
q7
where 0 is
l 6(qr 0, R) (ql, BR)
i 5(q,, 1, R) (qi, GR)
iii. 6(q,, o B) {(qr, BB), (qr, s)}
V 6(q,,0 G) (q,, BG)
rt:=hlt14
6(q1, 1, B) (q, cB)
9z
vi 6(q,,1, G) {(q1, GG), (qr, e)}
ar 9a r5 9r
vii 6(qr, o, B) (qz,
")
6(qr, 1, G) (oz, e1
6(qr, e, R) (Qz, e;
tz:=f4f6I3 6(qz e R) (Q:, e;
€
Define Greibach Normal form (GNF). convert the following grammar into GNF.
S -+ ABAIABIBAIAAIAIB (ch 4)
I=fl+12 A+aAla
B+bBlb
Soluaior
GNF fA context free grammar G = (V, I, P, S) is in GNF if each production has one of the
following lorms:
A -+ a Ar Az Ar ....... An
A-la or
S-+e
where, aeLA,eV-{S} for i= 1,2......n
ah . 2015 October
o"
T,Y, P"ll Theoretlcal Computer Sclencea ut8t0t
Sclencei 2015 October
T.Y. PllTheoretlca I ComPutet
4. Attempt either A or B: [2x5=101
lonversion of CFG into
GNF
4EE
S+ ABA IAB IBA IAA IA IB Show that the rsgular sets ars closed undst complsmentation' (ch 3) t4l
Soludon
A+aAla
Let L be L(M). Some ofstates ofthis FA, M are final states and some are not.
B)bBlb B eliminating unit productions
*o *i productions s +A s -) Let's revene the states of each state, i.e., if it was a final slah mite it non-final and if it was
- if,o" ur" 'nd non-frnal, make it final.
I albB lb
-rABA IAB I BAI AAI
aA
S
The new FA acrcpls all sring that were not accepted by the original FA(L).
.'. the grammar is
albB lb .'. Machine accepts the language L'.
s+ase I AB I sel AAlaAl
A+aAla .'. L' is a regulm set.
. . Grammar ts i.e. make all final states, non-fllral and all non-fmal states fmal
r 1*fr *u,
t bBA I
t
*
bA I aAA I aA I aA I bB la I b where M = ({q1............q5},(a, b},6, ql,(q5})
"t
n-+aAla
B-+bBlb
is the final GNF
o" o,
T.Y. Pll Theoretical Computer Sciencea t, . 2015 October
Similarly, ma* (qz, qn), (qr q.) as * ($, --, Empty stac[ accept
6(qr, e, R) El
mark (q" qr), (q2, q3) as x
mark (qr, qr) as x 6(qr, e, R) ERROR -+ Afler reading l't b, string ends.
0 1
o" Slart
utst0ll Solution
expression is: 0*01*
state.
Melry Machine: l,- is a output function mapping from Q x X -+ A
o.
T.Y. P.ll TheorGtlcal computer Sclonce o
!. ,o,roon, 1693 urar0i
o,i t .2016April
o"
T,Y. Pll Theoreti calComPuter S"i"r"" a ! r 20|6 April T,Y, PJI Theoretical Com puter Science ulSt
Solutiotr
-rK/
,.--. " ,/A SolutioD
We oeate 3 sets Rs R1, R2 containing the numbers giving remainder 0,
& = { 0,3,6,9, 12, Is....}
Rr = {1,4,7, 10, 13, 16, . . . .}
l, 2 respectively.
(ch 5)
Diflerontiate between PDA and FA,
Solution
Diflerence between PDA and FA
0,3,6,9
T is read on
fa is Read/write
1 (ch 6)
Dofine tuPles of LBA.
Sohtion
Solution
Tuoles ofLBA: G = (V,,'
1
) P. S
q,, qd
. wtiere V is set ofNonterminats
9o
q1
,i
q,
0
,l
{qo,
9t
E is set ofterminals
S is start symbol
q2 ,t q3 iq,
and P is set ofpoduction rules in the form: a +p q3 { ,l {qr, qa, qd
is at least as much as the length ofo' except
for a
il;,;J. ofp q4 ,| q5 ar
["t)* isthat-the length
o ] q.
production rule S -+ e i.e lo l< lP I
6'(C,0)= e -closure({)={
6'(C. 1) = € -closure(0)= 0 14: f5 ft
s'iD. o) = e - closure (qz) = 9r = E q,
uip, ri = . - closure (qr, q, = (q2' q4) = F
6'(E,0) = e -closure(q;1=E
6'iE, l)= E -closue(qr)=E
6'G,0)=e-closue(0)=O
6'iF. t) = e - closure (qr, qr) = F
Final slate ofNFA = q,
(qi) = =C
.'.-fina sute ofOfA = € - closue
q5
6 ofDFA '|
0
B
D l2l l1t
B d
,c { 0 €
@
9r 9o r5
D E F f1
E E E
F o F
DFA is
f1
0
0
I=II 12
l1 9s ao l2
@
01
1
3. Attempt any two of the following: [2x5=l0l
(ch 3)
regular explsssion'
Construct FA for th€ following Detine PDA and construct PDA for: L = (an b'a" I m, n > l). (ch 5)
(010 + 00)'(10)' Solutior
solution PDA: A Pushdown automaton M is a seven tuple (Q, X, f, 6, qo, a, F)
r=(01 0 + 00)* (10)*
where, Q = finite nonempty set of stat€s
fl l7
X= an alphabet called input alphabet
., = (0r0 + 00r (10)* I'= an alphabet called the stack alphabet q0 in Q is the initial state.
rl rl & in f is a particular stack symbol called start stack symbol
Fq Q is a set offinal states
6: mapping from Q x (t u {s}) x f to finite subsets ofQ x l*.
f5
@-e@ PDA for L = {a" b'a" lm, n > 1)
Language set = {aba, aabaa, abba, . . .)
f6:
@r@
o. T.Y. PJI Theoretical Compuler SclencE a | 2016April
0.
ur8r0[
T.Y. PllTheoretica lCompute , S"t"nc" r Er 2016 APril
B-+ArBlb
For all a's
'B' for a, for lr b' change state' for all next b's No change in slack . Final CNF is
Logic: Push .
aftu that
"-' POP the sYmbol' S-+ASIBAIAAIAB
rtre pOe M = (iqo, qr, b} B}' 6' q'p' R' $) A+ArAla
' qz) {a, {R'
6(q' iil
'. R)
---' !S9l
ERRoR I can.t sta.rt with e or b
B-+BrBlb
s(qc b, J Aq)a
BR) A2-+b
6(qo, a, R) - (q,
(qnBB)
I
Push B for all a's
6(qs, a, B) - i Conslruct CFG for the follorying: (Ch 4)
) ERROR -) ifNo a's or b's after first a's
6(qp, e, B)
(q,' B)
i. L = {ar bvcr+, I x, y > t},
6(qo, b, B) -+
(q,' B)
Read b's - No action on stack ii. A language conbining s&ing having at least ono occurrence ot'00' over (0,1).
6(q1, b, B) -) ) Solution
6(qz, a, R) -) ERROR , a's before < a's after 4, Attempt either A or B: [2xsrlot
A a
3 b (ch 4) Minimlzo tho following OFA: (ch 2)
Normal Form (CNF):
Construct the following CFG into Chomsky
S -.r ABA
b
A+aAl€(sPsilon)
BJbBI€(Epsilon)
Solutiou
S -+ ABA
A-)aAl€
B-rbBle Solution
'+ eliminating e - Productions ql
A-+aAle -A+a q2
B-+bBlE rB+b q3
qa
fTtTb
qo q2
ar
Rewriting
qo q2 q3 ql q3
AraAIa S-.>ABAIBAIAAIAB ar ar
q2 qo qi
B-)bBlb tq,Tq,Tq.
S + BA IAA I AB are in CNF' lq. lq, lq,
S + ABA not in CNF conYeding mark (qo qz) (qr, qz) (qo.qo) (qr. qo) (qr, qr) (qr. qz)
S --r ABr Br JBA butS+BA Check (qs qr) 3 6(q0,a)rqr 6(qr,a)-+9r
Br-lBA 6(qs, b) j.q2 6(q1, b) --r q3
"... g _r AS (q2, q) - marked
Now A -+ aA and B + bB are not in CNF ... mark (qs, q1) x
.. converting AI = letA2 = b a, Check (q1, q)
= 6(q1, b) --r qs 6(q, b) -+ qa (q1, q) marked x
. . Replacing ... mark (q1, q) x
A+ArAla
( T,Y, PJlTheoretical Compuier Scierce t r 2015Apil
o,
ut3t0i
r Science a r 2016 A ril
T.Y. P-ll TheoreticalCom Pute
ii ii I, i:il;T'
point where
;; g
j'1,
Y":lo-
H: "jj,jrii ffi iT,',1"#:',:',1
T{.';"-;'.r.*itrr",
#;'lf il I#,*;
of rz'
ii,"'* i'strarl to the initial starcon
A UTM is designed to simulate the comPutations of an arbitrary turing machine M. To do so,
the inpm to the universal machine must contain a representation of the machine M and the
string w to be proc€ssed by M.
which We assune that M is a standard TM that accepts by halting. The action ofUTM, U is depicted
iii
,',
f iii'iv-:',,1'tu:11,;:;$:T*x,ii,ff",Tj1"
T, halted From no\'Y' the '
ii"',rr"t1' would reject during this process
Tl T2 does also'
by Let R(M) be the representation ofmach ine M.
R(M) W L,niversal
machino
M h6lts wilh W
Accept
"'r) U Loo!
in a manner simirar to a hansition
i. I i'r::',:':ssnH"',,tfL1[i]:ifi:::"'text'
diasram, but without sno*lng;tuto
t*ptititly: we write: T1-+Tr
tape svmbol'
M do€s nol halt
Thc ouput labeled 'loop' indicates that the comPutation ofU do€s not teminate
vii. we-can ur'o ttt" tttt t#i?i-r"i t'ilii"ia'
depending on the cunent
machine Tr T Tz If M halts and ac.4pls input w. U does $e same.
*t t""i"T' *i-Li-t*ot ior thelompo'ite
when Tt halts' il'' If M does not halt with w, neitha does U. The machine U is called universal since the
ofany TM M can be simulated by U
'l'
where is:
(a, a, s) 4E c
Explain any ono clolurg property. of regular set. (ch 3)
is a Turing machine with
an outPut Printer' The Turing Solution
t Enumerating TM: An Enumerator to nt str ings. The following dia$am
glves a Closure Proprrty of regulsr set: Regular sets are closed under union, concatenation and Kleene
as an oulpul device P
machine can use tle printer closwe, i.e., if L1 and L, are regular sets then Lr u L2, (Lt + L2), LrL2 and L* are also regular'
schematic of an enumerator
| 20r6 April
o,
T,Y. PJI Thooretical Computer Scienca a
Proof
' Lr + L2 means th€ language ofall words in either Lr or Lz. Say regular expressions for Lr and Lr
ar€ rr and 12 resPectiYely.
q5 (cr, x, L1
Accept state
B b
Convert the following cFG into PoA:S -) 1S | 1S0S I I (ch 5)
Also show lhat the sking "11101" is accopted by the PoA'
Solution
The language is not CFG so can't convert it to PDA
Dofine NFA. Gh 2)
Solution '
A non-deterministic finite automata can be defined as
I M=(Q.t,6,qo,F)
I where,
i. Q is a finite non-empty set ofstrtes.
ii. E is a finite set ofinput symbols
iii. qo € Q, is start state.
iv. F e Q is a finite non-ernpty set offinal states.
v- 6 is a tansition function that taltes a state in Q rind an input symbol in X as arguments and
retums a subset ofQ.
i.e. 6: QxE-+24.
where, 2Q is power set ofQ
0.
T.Y. P-ll Theoretical Comnuter Sctence r
! r 2016 Octobet 1693 ut8t0[
J,i
T.Y; PdlTheoretlcal' oorprt"r,Sot"n"u .r,f,1411 I october.,' .rv..,, r o. T.Y. Theorotlcal Compuier Sciencb n 3 20L6,October'r, : ,,r- l:.rq,ri r0# i
ur8t0[ ---r$
ll. Distri6ulivity ' ..; ' 2
; :."r
L -i -i?i+i
tr:i
1. L(M +N) = LM + LN Construct a NFA with € moves fortho glven REi'l.0ttoi'tll':+1l,l0r 'i "cll-i:
e {ChQ)
2. (MrN)L=ML+NL Solutiou
r =01(0+l)*+1+0r
oefine Multitape Turing Machine. (Ch 6) rr=01(0+l)r r21110r ._
= t{t
l,;:14,
Solutiotr , . .-1. I .= ir1ff.-i ,.
A multi-tape Turing machine is like an ordinary turing machine with several tapes. Each tape
has its own head for r€ading and writing. Initially the input appears on tape 1, and the others start out
13= 1116 =($+16)+
blank.
ilE &
State tho machines ussd for CSG and CFG. (ch 4) rr= 0
lq=
16=
11*
I !1i';;1ult.?.
SolutioD I5 r6 i'lri:
Machine used for CSG : Linear Bounded Automata 0 1
sun 0 e
5 ri,
+: [6*rt*: 'lr
1
Solution
RE lbr the DFA is; l* 0(01)* e
t, t; 6)
.lrl
2. Attempt any two ot the following: 12x.5=1
ri,,i,,i,rfli:l
,i,,;, I'ttl I
Construct a DFA to accgpt the set of all strings ovor t. {a, b, c} such that th€ string starts
I
r=Il+
with 'ac'and not having 'cab'as a substring in il. (Ch 2) i
l
rl = f3 14 12 il: tt ,tttttt.tl
Solution
e
l
T.YiPJl Theoretlcal Com putet sctence r f,r U9
'201.6 Obtobe1,,;,. ust0r
fp I . 2016 Oclober o.
6;l
Convert the following NFA with e movesto.DFA.
T.Y;'PJl Theoretical Computer sclence
utsl0n
(ch 2)
0 1
a e
Start € b
b €
Solution 1
D--rbD b
o. o.
T.Y. P.llTheoretical computersclence rf r 2o16 october -: ::: '
ut8l0i
T.Yi P-ll Theoretlcal Com nc0 i t, t 201 October I
:
Consider the production A+ aA ] e 4,A. Attempt any two of the followlng! !
Eliminating e a
i
A+aA a Construct a Mealy machino for a language L ovar = {0, 1} which outpub '$' if string sndsI
In production B -+ AD I aAb -+
wlth'aba', outpub'#' ilstrlhg bndd witli'bab', otisrwige (Ch 2) ituhuts'.'.
Solulion
B -+ D Lab ... for A-+ t br
B+AlaAb
SoB+ADlaAblDlab
Removing unit production
B-+ADlaAblbDlblab b
(qr,d,B) + (qa,€) One state on one input symboltransits to One state on one input symbol transits to
(qa,d,B) -+ (qr,e) one and only state. more than one states.
(q4,d,R) -+ enor It is deterministic in nature. Itisn eterm inistic in nature
-nn
4. B, Attempt any two of the folowlngl
[2x5=1
A + 0A0
42 -+ A, I | 0420 l1
lAt I 1 A, + 0Ar0 lArlll
Removing left recursion
! GIE -- 42--;0420 1 1 0A,0 01 10
Convort the following grammar to GNF:
S-rAAla (ch B-+ll1B
A-+SSlb Substituting A2 in Ar
Soluflon Ar -+ 0A20A, | 1A,l 0Ar0BA, I lpA,
i. Substitute Ar for S, A2 for A, Resubslituting by the values of Aland 42
Al +42A2 la S + 0A0A I lA I 0A0 BAI IBA
42 +Ar Ar lb A-r0A0 lll0A0BltB
ii. Consider A1 -+ 42 tr.2 | a i < j lgI1ore B-+ll1B
iii. Consider A2 -+ 41 A1 | b i> j Converting this gammar to pDA
.. Substitute Ar by 41 production S + 0A0A I 0A0BAI I
Az -+ Ar Az Ar,laAr lb 6 (qs,o,S) -r{(qr, A0A),( q6, A0BA))
Removing immediare lefl recursion
S )IAIIBA
-+ aA b AA is in GNF. 6 (qr,l,s) --+{(qr,A),( q6, BA)}
B-+42ArBlArAr A)0A0l0A0B
Substituting 42 in Ar
6 (qr,o,A) ---+{(qs. Ar),( qp. A0B)}
A1 -+ 42 42l a
A -+ lB I I
-.l aA aA b a
6 (qr,1,A) B),(,qr.e))
Substituting 42 in -r{(q6,
D B -+ lB I I
+qo
6 0 1
'1, Attompt all of the fotlowlng; l'tO x 1 = {01
Qr 9z
IT:a I
9r 9r 9r
Define regular oxpression. (ch 3)
Qz Qo Qr
q1 qa
Solutioo
Qr
*qr ql A regular expression is a set of pattem matching rul€s encoded in a string according to certain
Qr
Sohtion syfltax rule. i
I
I
9r x 1 b
Glve the mapplng of'6' function ot NFA with € moves. (Ch 2)
q? x X
Solution I
er X x i
6 is a aansition functiolr for NFA with e moves
q. x x X 6: Q x (ru {e })-+2a
qo qj q, q3 q. . The intension of Q x (, u -r 2a is ftat 6(q} a) will consist of all states p such that there is a
{B}) I
I
transition Iabeled a from q ro p, where a is either e or a symbol in E. I
[qe, q3] are equivalent and [q2, qa] are equivalent
1 c I
Which tool is usod to provo that the languago is not r€gular. (ch 3)
0 Solutior
Pumping lemma is used to prove that the larguage js not rcgular
Slart
b
a,b
Solution
aal(ab*aXb
I
T.Y. P.ll Thoorotlcrl Qomputer sclencc . i . zorrepar l1@ urf,in
T.Y. PJI TheoreticalCo m uter Stllencel t 2017 o' T.Y. P-li Theoretlcal Computer Sc i"n"". a).
Esl
Dgrine Kleeno closure. lllr
[|'. 2017 April ut8t0n
rj = rr+ 16
Let qo = A be start state of NFA
.'.''6 (A, 0) = qo = 1
€
6(A'1) =q,=B
6 (B,0) = {q,qr}= C
6(B, 1) =ql= D
E (C,0) = (qo,q,) = C
6 (C, 1) = q,=D
D (D,0) = q,=3
1
12 = bab*
= r8Il0I9
0
0
r3 9o Qz e: 9o
0
r=rl+12
Sta.t b a
L€t G = (V, P, S)
', x = {a,
v = {S, A), b, c,d}
Congtruct CFG for language L which accopb set of all palindromss orsl p. b}. (Ch 4)
{a,
q, {q"q,} q?
SolutioD
q, qr (o,,qr; To constsuct grammar G, all the above tluee rules can be used.
a b b Let G = (V, E, P, S)
b a
From (i) S+a, S+b
From (ii) S -+ e
b a,b From (iii)S -+ aSa,S -+ bSb
Taking all together
V= {S}. I = {a. h} P= {S -l :q, '1"'' '! , '
T.Yr PJl Theoretical Corn utel Scfencer 2017 T,Y. Pll Theoretical com pute.Scie.ncet 2017
0:
A b
Rawrite the following CFG after ellminating .
uselesg symbols: (ch 4) , too 1o, 1 {0n1"2"0'I m > 1,n >{ }. (ch 5)
S --r 0A0
OD
A --i Sll lCCl DOA
6(qo, e'R)- ERROR i{{
C-r0lllDD 6(q0,2, R) - ERROR
E-+0C 6(qo, o, R) -+ (qo, BR)
D -+ ODA 5(qo, o, B), -+ (qo, BB) 6(q,, 1 G) -+ ERROR
Solutiou 6(q0,1, B) -+ (q,, GB) 6(q2, '1
G) -+ ERROR
In the given grammar symbol E is useless as it
is not reachable &om any production. 6(q,,'1, G) -+ (q,, GG) 6(qr, o G) l ERROR
If we start aI stafi, we can not terminate the grammar
i.e. no terminal string generated from 6(q,,2, G) -+ (qr, e) 6(qr, z B) -+ ERROR
ammal so the grammar itselfis useless. 6(qr,2, - G) (qr, e) 6(qz, e, B) -+ ERROR
6(qr, o, B) -+ (qs, e)
Construct a TM for L = (wcwRl w E(a + b).) 6(q3,0, B)- (qr, e)
Solution
(ch 6)
6(q., t, R) -+ (qr, e)
The TM is 6(q,, B) -,
e, ERROR
6(q,, o, R) -+ ERROR
(oo, a, n1
(qr, x, L)
(qo, b, R)
(94, x, L)
(q,, c, R)
[a EE
Dofl no
I
-' qo Qr r.t0
!q, 9r qo
q, ql Qr
ql
qa qo
qr qr Qr
9o q7 Qr
Qz ar ql
Solulion
,
qr X
i
q2 X X
q3 X X X
qa X X X
qs
X X X X
q6
X X X X X X
ql X X X X X X
qo q1 q, q3 qa qr q6
'. [qr, qo] [qo, qr] [q2, q5] are equivalent states
0
0
lq3,qJ 90,92 0
i,
lqz,qJ
0
o,
r,!sr0fr
B**1e
tS
\,r'
de-finitio:
L
ct linite st at€-s
lC(r iillJUL .lllJl ldUet.
led o,"r'rout a lpha bct
lnifia! rlate rvhicir is in a
T
a Ut.r,,t svmhol (Cenc
)f final states a \ Ql.
rrE!i;i-n--g--T-rcnrqJ_!.r_q
The a Lrove nlacLitl(r grafhtca ly represented as bclov\
nr-r', rl /.)LrtDUt taDe
-, -r-r-I.
l
t l€rzog n tze
Pet ft>rft
the
c.r r
t o^q '
prfnajjC t5\ob leo
"+{tte 5
t
{ o ,lYl ochrne. r.uiHnout O l4crchrne urith
r*
i
cnemors rnef,nor\ (5+ocg
Ex (Applications):
I
D"rForn
Ex (Application):
ID Text editor, . I
Parser used in HLL Computer
IF]
3) L={a'b'/ n)=2}
t: 2--\
131-r-- <b'B'L)
-_ - - =-)
.,
F
I
Iir __J
It.
l+
v
c
s7) L={ aib"c"/i,n>1,i<n)
a'bncn 7 irn > L, i <= n)
s8) L={ ib"c"1i,n>1,i*n) e
se) L={a c
In other woids (
head move)
The NTM has a finite number of choices of next move (state, new symbol, and
if any of choices leads to an ID
for some slate and symbol scanned. It accepts an input sequence (
with an accepting state.
(
T es of Turing uachine)
m Pos ur ng a chine:
s )
need to break the I ive n p roblem into smallest problems such
solving each o f these smaller P robl<ims, byusing the answers of one problem as the
input
that
data for second, we can arrive a t the fina I a nswer]
To obtain the
A simi ar pioceZu re can also be used in th6 d esign of the Tu ring Machine.
will Ee-comEineo in
solutiort we nlay combine two more Turing Machines. These Turing machines
suc a way that qtput o-|![el!!sJ Tl'1 is input to the second,
the output of second TM is input to
as Composite Turing
third and so on. Also each TM is solvinq a sma Iier problem. This is known
Machine. the
Cil. .rr.of while finding GCD of two unary numbers CTM uses different TMs for copying
numbersl-\
\ffi;, ilHt.g ", ,";"i;o?,;[rr-tne rre]p oia series of subtraction of two unary
c) The processing data to be fed to the Tf4 (This wi ll be the data lape)
Page Nurnber: 93
I
I
{}
il
i
I
I
I
D
I
D
I Two Dimensional TaPe
I
D VV
I
!
I L4 L7 26
t h 9 13 i - 18
*-f- t
25
l
S h 72 19 24 f-" .".-.1 :.
h
D tt i zl , )2-i T- I
r I
i Here the numbers indicate the correspondence of squares in the two tapes: square I of the
two dimensional tape is mapped to square i of the one dimensional tape. h and v are symbols
-\il which are not in the tape alphabet and they are used to mark the left and the top end of the
t tape, respectively.
'-s
One Dimensional Tape:
[{s le [o,Rhi,[- l. - |
The head of a two dimensiona I tape moves one uare up, down, left or right.
Let us simu a te this head move with a one dimensiona I tape
['* tape. If t ad moves down from i,
Let i be the head position of the two dimensional
[** then move the head of the one dimensional tape to right until it hits h or v counting the
i. the of squares visited by the head of
[.r number of squares it has visited after Let k be number
the one dimensional tape. If h was hit first, then from h move the head of the one dimensional
tape further right to the k-th square from h. That is the square corresponding to the square
[.i below i in the two dimensional tape. If y was hit first, then (k+1)-th square to the right from v
is the new head Position.
[.* For example, suppose that the head position is at 8 for the two dimensional tape in the
above table, tnit ir i = 8. If the head moves down to position 13, then for the one dimensional
['= tape, the head moves from position 8 to right. Then it meets h first, which is the third square
from 8. Thus from h, move 3 positions to the right. That is the head position of the one
['* dimensional tape corresponding to 13 on the two dimensional tape.
l" If i = 5 and the head moves down on the other hand, then on the one dimensional tape the
head moves to the right and it hits v first, which is the.second square from i = 5. Thus this
time the third square is the head position of the one dimensional tape corresponding to 9 on
l'* the two dimensional taPe.
lc, similarly formulas can be found for the head position on the one dimensional tape
Ir' corresponding to move up, right or left on the two dimensional tape. Details are omitted. Thus
some iuring machines with a one dimenslonal tape can simulate every move of a Turing
lr'
t
machine wi[h one two dimensional tape. Hence they are at least as powerful as Turing
machines with a two dimensional tape. since Turing machines with a two dimensional tape
obviously can simulate Turing machines with a one dimensional tape, it can be saiC that they
[" are equally powerful.
li
t ..
c
3otvc^ble + u^soh/r^bla' lrTob 6- lr I . booh
I
e.
Lan ua es:
€ ages ls
oft
Th
Th over the
1.
ini;"si'iig'
s
nuttI l'fl :::::,"i
una^uc-cept it tl'" ".
the string is ilin TI
JilI,', the i:language'
"!'''
^
will. when
,ndhultandrejectotne.*irl.t'd"iriing?.r.r,ineatwiviharts;irislinownasadecider
Ini it.uia rc decide the recursive language'
enumerable' All regular, co ntext-free
and
also recursively
No te: All recursi ve lan UA es are iuu
ext-sens itive lan guages are recurs
Page Number: 95
;*E-$
lz,
$
D
r.)
(l Note: All rgqular, context-free, context-sensitive and recursive languages are recursively
\'-enumerable- \
)-"
D 2-4-4 Flectrrsiwely Enurnerable Languages -Lpp
In this subgcction, y.c 6hall study l;rngu{ges a-*rocis,tcd *'ith 'ntring msahines.
$ Definition 2.{.8 A l.urgrrag€ , over &rl inpu! slprratret E i6 said to be r.-
crrrsiuclg eaur*tttble, deooted by Zar, if therc exists n :I\rirrg Inaahillc tlat
D a(cepts it. ll<tursiwcJy enurD(:rlrt le hlguages arc also calle<i Ttirtg dcccptablc
langtagcs, or Tiring recogaisablc langtage-l
b Dei-Bitiott 2,4.O A l:rrlaulr{ie tr over en iuput alphabct E is said to be r€crr-
riuc, deaotrd by lnt:c, if therc cxist-s s I\ring rntr hinc that lcccpts .L, and th^t
D lrrrlts on er.ery inprrt r, € tt. Rccursii'e lnnl4rrageri 6,r€ al6o called Tbiag decid-
t ablc langtrcgcr, or recursii'cly decidable languagcs; rl'e shall discuss tllc concept
"dccidahl{ in Chaptor 3.
TLc terh 'r'Ecurriucn comes frotn the theory of re'cursive functions. It G
B clcar thst ! recursi!.c l&oguage i! a.lso I recursively cnurrrcrablo, lrut on tlrc other
hs.nd, a rccursiyely enunrctatrle lalgrtagc is rot n.lcassarily rccu.$ir.c. That ls,
e No C*rg '@&!a Ae.p.ln8 M*hltE
D ]t.er,.&l r,,
(1ui6s Mr}i,a)
T!"1 Gd.r.r Lu*uir,€
(No Cl.{rB.icd Rul€)
3 T)'rE O 1..{au.{<6 are
(TyI,c O Groru Cpsl
U
0 (Fi6ircstlt. }\u.drEr.,
FigllE 2-r9: Eicr..clitc.l ll.lall6ns b3!*'r,'r \r'tiou5 LsrsxlaBlcrtDEl'B'd
b tb€i' Acc€prina Ma.)ria€
- Page Number: 96
Ei'
rs said to be decidabre'
ransuaee s rocursive
G.tid'Xl;:;,""H"f,t;"
problem: said to be-undecll,"^bl:"1:J-t'"txT:ff[,t""t
undecidabte ,-6^,.>.1p is r.ror recur-sive is
:i
g:
i;i: ul "; ;:i ""? """ :'
$;[#ii:
"':L:''""
.-0,*'"1,il.?i:i".-:".,..,*:1,:lli:!:?l',:l'111:,.T"]}*;ifl*[l#.il;;l*Hi-ii,{#:t
r.t hcr thc pro sram' !" 11;';l ::iJ="." ih. p,o g,u'n * ilt
lrct
and xl'l ll I
given a Progtrtn
s ill run lors 5
LBA and CSG:
I ntroduction to
<191andct'9 (V U T)* one more
cr)Fwithl
rules are of the formppear on R H S. of anY Production '
Th e produ ction not a
sta rt sY mbol 'S '
does
restrict ion is the ion as only S)e not
A)e
ause the pro ductions a re of
the form
o2
We can write Product is called as context sensitiv e bec in context 01 &
This g ramrnar tofA is allowed bY P onlY hich is
aZ (9+e)m eans rep lacemen "Context S ensitive languages
o1.A. n2 => ol..P. called as
generates a lanqu age Autom ata (LBA)"
The g rammar as "Linear B ounded
ne called
accep red by a machi P where
, A)
e.g. G ({ A ,8, C} , ta,b)
P {A ) ABb
ABb , ACb
Cb ) abb ,)
the
ata (LBA): Turing Machine satsfying
near Bo unded Automa utomaton ( LBA) is a nondetermi
nistic
q" Ali near. bounded
llowing two conditions: includes two special sYmbols c
a nd $, the left and
right end-markers'
1) Its input alPhabet over c or
nor may it print another symbol
' from $'
res PectivelY left from c or right
2) The LBA has no moves
$. imP- r, 6l :-9 "
M :,f 5 0, c, $, F ), where a, I, ":1^t.1'J"?;j"'
resPeL,v)
AN LBA will be
denoted
s in e e lnd right end-markers'
TM; c and $ are sym o
non-determini stic
Page Number: 97
G)
Ul N o+ q\nfiipbv uJ e
UJO 3 *,.rm gJN
Q 'v, q' b Q'Y
a6 ob aIofs lfo pu.r3 )
,b
? qmc!.Htrn UJN ?Ja^\r9O (
rtdo.t+st- UJN tr o? ?A/olp^rn@ UcO 0 -,'1
k _. _
- 1}a connPulsonl
upples of q,.cg froit€. Rulp mcl.to
5- ru,optes
m= l0,Z,clogo'FJ
urhqe q = 6a, Of SUrt!€
Z = Se.t, o{ input cjPhobets
d= tronsibion' f11o
9o' iniuiol stcrte
f ' fincrj sttrt€
$Flq {or sJ I €+t s brpples cu-e scilrr'€ onry
trorsition fuq is diFcaJQnb
ocR I d=OxE-->O
NFff C+ d: q XZ-+zo
NOEq\
OFe Con nevar hqS e rroyAg,
Everv DFR iG NFf\ bu-t eva-r! NFR ls noL
opA.
. iF Cons1'ruclion of OFq r- 5rn & lrn. BaO.
r> 5Lo.rt tliLl^r
r) Tt hqs gerror Ststp. in VL
2> [.,usu su].t€. +e'rnsfer crl I
S) =L
9eno, ho{ o,Br aJl State cve. mo\re-
q-) .- obc
2> Subsr+ing.
r1 No Q€fror SRLE-
)i.],put,
>|. Final s+o.Le rno\r.eJ cill efPlah s+€J+
g) '
-obs
s> end t.,.,lt{r .
r) No qerror s+ctg
-) {inal alalg nol rnov€l oJ, S+tttainPuL
s) ab c
*) chqck cr.6 Ev : b1C bocq
boc b
bqcc
€rrnerr fod cf: rrttnsfirlg o's b'3 Ernl
o
e PvQ6 Q!€, Qo
b
\b b evzn o dcl Qt
q_
arb
Odc/ ovqn It
d- odd odd 4t
o. [o.u,cJ sucn bhoL sring bub ct
Subsxing t encl turt-h bbo
bqn nbc.
bona.
d rcrut o5D-sJO-LC 9+
than 6ep,c^Iurc d rour end in j
tlren cornbine oor-qh olha.r .
O. tuhe^ or is w€
lol or llo'
rrconvcrslor oS NEA to oFR toEA equivu]e^t
tY Ftotn dtoq- Or toble-. lo NfA)
,> Orutrt \*onsiHon tfilDlO
cy .Tniuol str'.ts + nd thQ^
+) heut Slcrtp- Ocrufed fl,i: B =
^zQ
NPA wf h € utlbh APfi
l) Frnd+ o.lt 6 CJoSU/v-
) inlfta-l Stctlg =9o. ec]osure --4.
6hen trind 0ll 5+at€ c"ifh fnpur lL
tefnL. +Asn s+?.
.,I D€tr.l
t^''fn of s+ctLe A'O'C"'
T draw d togrrrrn
q Ptnol SW)*' is fhct' sGPPosQ fi'na/ rs
{s then lzhe sto& uhrch cc^}tu'n qt
be4 a.tv, Fincd.
v
1./ * mqhit, N€rDc'e W"v" I
rf. fn,6t6izalto{r lllh.
5Lept: Porl-itlon rtnoJ t ' no n 'iincrJ tfttt"
i0 b loc"L
Pr =t Jt J
bloctsE, BlocL0t
Qo bo j tooJ
9r 1A l l t BrJ
sleP::l- )
BorJt. t -J
U r 0,'{ -J
9oQt
%$a
finoJ Sto.t€ /J &JhicA tqCluele {rnal SW
.thO<rtgn r4oorug rne"ty rnephtne: @.
No F'inoj state
1> Moore:
i) Oroctt slrr,g - StGrL/crntor n I *O
2> glr.& otrrl:tr1,o +, sto*@
o
b
r- trlble
ob A
Qo Qo Q1
9
Qt QL 9t +
r l4eoJgr)Orocu st-r/ng -Sfurb I CrnpLn I
encl
2) grw outpu*, b nput,
ol b/-$ olt
bl$ qt
t-rt.blo
dA dA
{o eo$ (r$
Qt 9r# Qr 9.
\/* Cpnv?rslon .al lloorc ma.hhnitp ., .'--.
elu[ th@tl rn-aohlrte, '
CI
- {D 'Dtqe7l,,rnt
\,4 ^,rlOgte
F+eo+$ rnoohrm TB8EJY
@.
tad-- 6 o.n p
?\^L ql hcrs olP.o.
C
o o p
.\
Qr
Qr 9r 9z- o q5 I
9z Qr Qs o
Qo Qr q3 I
ru0P I I
P Loq t o
f to q D I
o)ucf(qq b) u c[qq9 *
Jcqoq,q,- q) = d[Qo b.1 d rour,ng
= tqoq 'J utuj utfroJ drcw ando
= 9o9t9z of glve,n
9oQr9:-
6'[qo9r Qr t) = d(9o Ou dCQrc)ud( 9r c)
= + U9ou9r
= 9o9t
I (.:t bob=brba b ;
.bbebo t,ueboeb<brbob
) =
(o -bbtn=b'bqb)fr =
(rr a ) p soD ) = ( o er )I
-
"<=6._rib
(tun = ==
l.'::l;i.
(On-buo 6n ob)-P)arnsoo: =
(q a:[ir[,r bb'b )p ) arn5op 3"
(q u )-P )arnsoltr 3 -'(q v),P
ffiu:
.-Iob t-) o (sb} ltstl Drosorr a :.
(to ebrb'6ob)p)lrnsot: ? =
(to U)p)'Snsor: e- (o U),-p
i))
V. ebt b tbob =
(o b) 'arn soltr
? = dro?9 tDnlul
o
[rbeb ] ' (+6J to amp;> 3
teb ) = (qoJ 10 a.ro(bD 9
[-b ] = Go: Jo o-msob
\ o5zi6 r6 ], =' (,olo arr)sop =?
feb'zb',1job I (ob) lo a.rnse/) ?
q
?
g
_J
3
.YJ6 Oq? UJN ?
19 9ao
q q
? -O
d
(q sbeb )arnror) a (ao)p
boab
Conlo) = (o @)P
\/
Cc +beb-ob )amrsr> ? = (9 ) )"P
' o--+bab
Canibnb) -(-
(p + 6c5-c6 ) a.nl$op ? --(o ) ),P
bz-=
) b a6zb
(On0n-lrbn0n=bJ ._t- !'
(=b) $c|e a :
t, (-b n 6 )mf. e -
(o,bo(o ob)_p)sottrD =
@ q ? e <_ '9 €
D ? .D
Fatbeb l = (qtq)
:
[-,b, ob t tg oO
^'5.b+bebl [r o'o ]
[ob]' (oo L
f tb. abl= ['o oo ]
I
rg sb rg sb s6
I tQl 'e6 tQ) €.b 'bb
I Iq s6 ,Q/ S6
I eb
q61, q og nb o zS
-v (€, ob -rb
'<g LO )
eb o0
-
"9 rQ sb o0 rb ob
t 6? [r6tr6eb1 l, bsbl = q, ,
q D
t
uo nllto{ 'lr'ou"oI
t+ b'X;b'obI, td
etg l':au.ra -uot, g fpulJ uot1t1lt)4
9 ro
g'o q
g
q,D p
p
luow?JiuJ.ruthJ @
?rq
c
a n,? ,p
q
D 1)
c q o
.W g
/-ltz6'5 l'ob) D,q'o? fig e5z.6rb obt
6
'' 1b o -7b ab
c ob z-l
t 'C6 o
t6
o '[6 o 2-b
o ,tb o t"b ob
q D a,qt4
o/o
o z)
o/q ofP
o/q a ,^.
.\ q :aV.t V)a[*l Ft-aW
'["bl=ob
V(. €'v
T r$ 'Lb qb
o eb ab -cI 6<- 3x € . _p
0 t$ -$ tb fT'o1 =p
o tb g ob ob [q 'D] -?
aA
q t? I s,, -b ,b ob ]=g j s"ldnI
Y
"r()
}J
g
q
q n
.'aL/.rqcouJ arooh
-O
p
<$q q q)q eb G---=-----:-
q u g
gi! v q-Qq q fl
q
Ud 1c atdcul9
o rno
qDg Ptra I tI dto saat6 aurqrou [fou* J arooqJ g
o o 6"r
@
1
I
I
I a
o
O ?\
P 5 p o P 5 Plo
qr q q ll
q i
q I
r
I
I r 5 o Y rlo 5
5
I
I 6 p o b 5 PJo o
@ o I @ o A
P s Plo p 5/o PIo
q q r I g qtfi tlo f
f r 5 o r rls 5io
S S Plo o 5 SJo P)
\ lo
D
I
l oJl
@ P/o
P 5
'r !' qI1 r t o tlo
o l o
r r 5 rt$.
S 5 Plo o oI D
a. (o+:. 66y )*)* t'
o-r- l Cot) F)
o+ ( ol)x)x
'l
e
e o )e
€
o
9- e
e
t (ot)h e
I C Cot
e
€ o1 b
e.
/
0 aCo+b)*b + bC a+b)ho
o +b)x
_l
e o-l b €
I
{
I
e CI+ b)ts
\1
4?
{ \
<.
\
\
a e co+ b € b
€
e e+b e
/g \
L a e
b
e €
b bco+b) € a
.,
e
J---l a+b €
7
e cL .<.,
"\
O. Co+oD'a abbr-
+ b) x abut
@
Ca+ € CL € b r
e
.7 €
e e G
---)
e
e €L
€
e h
---J
sAtFRoN
A l-
5 Push Ocxrn Rutornu+,s DATE
FAGE ITC
AE, 15 delino
q5 lnn o:ntrgurollon ol PoF cr.u'
I
CcaP FgQat
Co u ol ,
{rnr'!e conld
N SAFFRON
PAGE NO.
DATE;
a) Saline CFG.
R ele t>lructlrfg oI lofn{^nar ts clqftned b
+ lss denotPd oS G \r rJg P,5) urharo
Y, tinibe sa*. o{ non- hP-i rorrW iteLl YTJ.J]GbIq)
-t:Selo I tp-rcotncu Csrurcrtt ,61 1U 3 Ctl ro'b0l
P, f,inibs 3a}-of, pmdn'd,--) p L,rhare,,Q tS |+,O Sat
oc nofr- tprrnine,.l tf\g CcForbn ol )arm\tuil
\ non - tQ.rrnif\oj,
6: [u \s non-tg0nqjne! ceiltod 6tcrrL' 6 \mbo\ .
o)Th\s
Grorsrrarers C C fc)
c-lctsscr I e $ riclr Ctods oD I ar'!S
onQrcrbpJ
U.rh'rch el.rg 6uiLo.b,le {bf rDOeIinO Co6fd1n.
al F4O 6| oC hi h - loval I Iorn(-nrt T CalO be
$Pau{:tqd q$r\ Q-cr r AfOt-eXL Fraa g re\reerar
QK: C., PflScA L.
ci>-th Of,a \}$ad in Co n) 'i\er dorr Oi
6> The. ft-creh\ n a tfleLt, O cceptx Itq e- clors of lGrtq. fs
push sD\Pn Butqgo-rqa.C pO f, ),
to) p or CfnNer:
The I ' lo.c beol b SinrLe ouioroa*€ ear\ be
dedCribe u-rt 6ar of TOd ft i5 tlr o cta
fqgulqf grOI-o\Co\OJ .
SAFFRON
PAGE NO
C,ATE :
OFfl P.DA.
tt, i5 el fDqehlna- O:L ig rDcrahi oa
U)(l-hotr-}- nr\erno \rtf Fn rl\ef6\o Ca\€-rk
S RDtr NDOA,
l> \ess RU 1)
CFL Is t-roE Q \*d '>> N 0R CsJl hand\€,
r_-rY .T\DfD S CPL
'l=x (qJUJR
Potrrcr oF'F+ poA q NpOA tS dtpprr
lI^uq
{ffi
SAFFRON
{dt-s
N B
n Orl \5Ara aain bo rooultl la.
SA fno\Rx urotai
tltro.ftoo. ffn NPluo is chgos C-t5
f{: ( O.'E , t- , d, 9o,zo, F)
UrbeJe. I 6eI. o{ S\c,.}s-
F I
r")+
qo " ioiuc^J
F.
-Lo
fi'nerJ
: lt'luol s\eul svrr'bol ,
(r
o uJ4
hjhlch lool io u$eaj to
TCs
longtro^g e PAGE N ;ryr
6 Begulor [o1g ucr3al ufn P inel
6. Purrptin q ternmq.
La-b l'4="tO,: , C, qo , F j bo o {r n ile- qubnnaio
urruh n 5t0rc. Le| L be uha. \l{cr.I BaL g,c Q{},apl er
M LQyzeL$. lzl >, l-a tl'ren thor eK(6L Q,VrW 6UOh
thor, Z= UYLI] UiLh {uvl .-.< tzl t 1\l>o $ 0\rruleL \Si>l
lin ln.
lgrnmcr: cr-
t> Ptr-m \n lqrnrno shou.rd bo useal t0 [ovo tho.h i\ren
5 is noL ra ulojt I
Lmion: LtuLz
inHrbQctpn:'Lr OLz
G)rnpli p6')an \uHon ++f T,
kleans s+cLr : l=t t+.
CoO CqII-en obb n Lr. [2
d ( Fperanee : Lr -Lt_
TQVQISA = LR
Hcnbigious = leFt.ttpo * Rig hb \te,a-
N /-- saFERoN
DATE
6) Oe.line CNf :
6) saFi ne Q$p :