Professional Documents
Culture Documents
VANNARPETTAI, TIRUNELVELI.
Question Bank
http://francisxavier.ac.in
Page 1
UNIT I
1.
http://francisxavier.ac.in
Page 2
Page 3
Robotics
Artificial Intelligence
Knowledge Engineering.
15. Define Transition Diagram.
Transition Diagram associated with DFA is a directed graph whose vertices
corresponds to states of DFA, The edges are the transitions from one state to another.
16. What are the properties of Transition Function()
(i)
(q. )=q
(ii)
For all strings w and input symbol a
(q,aw)= ((q.a),w)
(q,wa)= ((q,w).a)
(iii)
The transition function can be extended that operates on states and
strings.
17. Lists the operations on Strings.
(i)
Length of a string
(ii)
Empty string
(iii)
Concatenation of string
(iv)
Reverse of a string
(v)
Power of an alphabet
(vi)
Kleene closure
(vii) Substring
(viii) Palindrome
http://francisxavier.ac.in
Page 4
UNIT II
1. What is a regular expression?
A regular expression is a string that describes the whole set of strings according to
certain syntax rules. These expressions are used by many text editors and utilities to search
bodies of text for certain patterns etc. Definition is: Let _ be an alphabet. The regular
expression over _ and the sets they denote are:
i. _ is a r.e and denotes empty set.
ii. _ is a r.e and denotes the set {_}
iii. For each a in _ , a+ is a r.e and denotes the set {a}.
iv. If r and s are r.e denoting the languages R and S respectively then (r+s),
(rs) and (r*) are r.e that denote the sets RUS, RS and R* respectively.
2.
Differentiate L* and L+
_
L* denotes Kleene closure and is given by L* =U Li i=0
example : 0* ={_ ,0,00,000,}
Language includes empty words also.
_
L+ denotes Positive closure and is given by L+= U Li i=1 q0 q1
http://francisxavier.ac.in
Page 5
7. Reg exp denoting a language over _ ={1} having (i) even length of string (ii) odd length of
a string
(i) Even length of string R=(11)*
(ii) Odd length of the string R=1(11)*
8. Reg exp for: (i) All strings over {0,1} with the substring 0101 (ii) All strings beginning
with 11 and ending with ab (iii) Set of all strings over {a,b}with 3 consecutive bs. (iv)
Set of all strings that end with 1and has no substring 00
(i)(0+1)* 0101(0+1)*
(ii)11(1+a+b)* ab
(iii)(a+b)* bbb (a+b)*
(iv)(1+01)* (10+11)* 1
9. Construct a r.e for the language which accepts all strings with atleast two cs over the set
={c,b}
(b+c)* c (b+c)* c (b+c)*
10.
11. .Reg exp for the language that accepts all strings in which a appears tripled overthe set
={a}
reg exp=(aaa)*
12. .What are the applications of pumping lemma?
Pumping lemma is used to check if a language is regular or not.
(i)
Assume that the language(L) is regular.
(ii)
Select a constant n.
(iii)
Select a string(z) in L, such that |z|>n.
(iv)
Split the word z into u,v and w such that |uv|<=n and |v|>=1.
(v)
You achieve a contradiction to pumping lemma that there exists an i Such that
uvi
http://francisxavier.ac.in
Page 6
http://francisxavier.ac.in
Page 7
UNIT III
1. What are the applications of Context free languages
Context free languages are used in :
(i) Defining programming languages.
(ii) Formalizing the notion of parsing.
(iii) Translation of programming languages.
(iV) String processing applications.
2. What are the uses of Context free grammars?
Construction of compilers.
Simplified the definition of programming languages.
Describes the arithmetic expressions with arbitrary nesting of balanced parenthesis {
(, ) }.
Describes block structure in programming languages.
Model neural nets.
3. Define a context free grammar
A context free grammar (CFG) is denoted as G=(V,T,P,S) where V and T are finite
set of variables and terminals respectively. V and T are disjoint. P is a finit e set of
productions each is of the form A->_ where A is a variable and _ is a string of symbols from
(V U T)*.
4. What is the language generated by CFG or G?
The language generated by G ( L(G) ) is {w | w is in T* and S=>w. That is a G
string is in L(G) if:
(1) The string consists solely of terminals.
(2) The string can be derived from S.
5. .What is : (a) CFL (b) Sentential form
L is a context free language (CFL) if it is L(G) for some CFG G.
A string of terminals and variables
is called a sentential
S => ,where S is the start symbol of the grammar.
form if:
Page 8
B b | A.
S->a
S->Ab
S->aBa
A->b
A->
B->b
B->A are the given set of production.
A-> is the only empty production. Remove the empty production
S-> Ab , Put A-> and hence S-> b.
If B-> A and A-> then B ->
http://francisxavier.ac.in
Page 9
12. What are the three ways to simplify a context free grammar?
(i) removing the useless symbols from the set of productions.
(ii) By eliminating the empty productions.
(iii) By eliminating the unit productions.
13. What are the properties of the CFL generated by a CFG?
Each variable and each terminal of G appears in the derivation of some word in L
.here are no productions of the form A->B where A and B are variables.
14.
Page 10
A sentential form is a string containing a mix of variables and terminal symbols or all
variables.This is an intermediate form in doing a derivation.
Q is a
Page 11
http://francisxavier.ac.in
Page 12
UNIT IV
1. What is a formal language?
Language is a set of valid strings from some alphabet. The set may be empty,finite or
infinite. L(M) is the language defined by machine M and L( G) is the language defined by
Context free grammar. The two notations for specifying formal languages are: Grammar or
regular expression Generative approach) Automaton(Recognition approach)
2. .What is Backus-Naur Form(BNF)?
Computer scientists describes the programming languages by a notation called BackusNaur Form. This is a context free grammar notation with minor changes in format and some
shorthand.
3.
4. Find L(G) where G= ( {S} ,{0,1}, {S->0S1 ,S->_ },S ) S->_ , _ is in L(G)
S-> 0S1 =>0_1=>01
S->0S1=>0 0S11=>0011
Thus L(G)= { 0n1n | n>=0}
5.
What is a parser?
A parser for grammar G is a program that takes as input a string w and produces as output
either a parse tree for w ,if w is a sentence of G or an error message indicating that w is not a
sentence of G.
6.
8.
http://francisxavier.ac.in
Page 13
12.
14.
Page 14
16.
17.
19.
20.
21.
http://francisxavier.ac.in
Page 15
UNIT V
1. What are(a) recursively enumerable languages (b) recursive sets?
The languages that is accepted by TM is said to be recursively enumerable (r. e ) languages.
Enumerable means that the strings in the language can be enumerated by the TM. The class of r. e
languages include CFLs.
The recursive sets include languages accepted by at least one TM that halts on all inputs.
2. What are the various representation of TM?
We can describe TM using:
Instantaneous description.
Transition table.
Transition diagram.
3. What are the possibilities of a TM when processing an input string?
TM can accept the string by entering accepting state.
It can reject the string by entering non-accepting state.
It can enter an infinite loop so that it never halts.
4. What are
http://francisxavier.ac.in
Page 16
Page 17
Page 18
Page 19
The halting problem for TMs is: Given any TM M and an input string w, does M halt on w?
This problem is undecidable as there is no algorithm to solve this problem.
31.Define PCP or Post Correspondence Problem.
An instance of PCP consists of two lists , A = w1,w2,.wk and B = x1,..xk of strings
over some alphabet _ .This instance of PCP has a solution if there is any sequence of integers
i1,i2,..im with m >=1 such that wi1, wi2,wim = xi1,xi2 ,xim The sequence i1 ,i2 ,im is a
solution to this instance of PCP.
32.Define MPCP or Modified PCP.
The MPCP is : Given lists A and B of K strings from _ * ,say A = w1 ,w2, wk and B= x1,
x2,..xk does there exists a sequence of integers i1,i2,ir such that w1wi1wi2..wir =
x1xi1xi2xir?
33 . What is the difference between PCP and MPCP?
The difference between MPCP and PCP is that in the MPCP ,a solution
is required to start with the first string on each list.
34. What are the concepts used in UTMs?
Stored program computers.
Interpretive Implementation of Programming languages.
Computability.
http://francisxavier.ac.in
Page 20
16 Marks
UNIT 1
Deductive
(ii)
If and only if
(iii)
Induction
(iv)
Proof by contradiction
= n(n+1)(n+2) / 6.
[8 marks]
http://francisxavier.ac.in
{p,q}
*s
s
Page 21
Solution:
Final Table:
Input Symbols
[p]
[p,q]
[p]
[p,q]
[p,q,r]
[p,r]
[p,r]
[p,q,s]
[p]
[p,s]
[p,q,s]
[p,s]
[p,q,r]
[p,q,r,s]
[p,r]
[p,q,s]
[p,q,r,s]
[p,r,s]
[p,r,s]
[p,q,s]
[p,s]
[p,q,r,s]
[p,q,r,s]
[p,r,s]
States
Start
q0
q2
Solution:
Input Symbols
q0
q0 ,q1
q0
q0 ,q1
q0 ,q1
q0 ,q2
q0 ,q2
q0 ,q1
q0
States
http://francisxavier.ac.in
Page 22
6. Construct the following - closure of each state and find its equivalent DFA.
{q}
{p}
{r}
{q}
*r
{r}
Solution:
Input Symbols
q0
q0 q1 q2
q1 q2
q2
q1
q1 q2
q2
q2
q2
States
7. (i) Prove that a language L is accepted by some DFA if L is accepted by some NFA.
Basis If
So,
=0, the n w =
by definition.
Induc tions hypothes is : Ass ume inductive ly tha t the state m e nt holds
of
Let
, then
with
Now,
http://francisxavier.ac.in
Page 23
(ii) If L is accepted by an NFA with -transition then show that L is accepted by an NFA without
transition.
Pr oof:
Let
be the give n
with
We cons truct
Where,
for all
and
and
i.e.
Page 24
Basis :
, the n
But
by definition of
with
By de finition of
Since
Whe n
i.e.
then
Page 25
UNIT 2
1. Explain in detail about closure properties of Regular set.
Closure properties of regular set:
If the regular set is closed under particular operations is said to be closure properties of
regular set
Theorem1:
The regular set is closed under union,concatenation,and kleen closure
Union
L(M)=L(M1)L(M2)
Concatenation L(M)=L(M1)L(M2)
r and s regular expression denoting the R and S respectively. The regular expression r+s,
rs, r* denoting the languages RS,RS,R* respectively
.
From this equivalence of regular expression and NFA`s definition the theorem proved.
Theorem 2:
The regular set is closed under complementation.
Proof:
Let L be a regular set and L is contained in *
Since L is a regular set then there exist M1, which accept the L
M1={Q,1,,q0,F)
Now we can define the DFA for *-L
M2=(Q,,,q0,Q-F)
http://francisxavier.ac.in
Page 26
The and 1 they may be some different. There is no transition for this symbol which
are and not in 1.
Now we can introduce a new state called as dead state d.
(d,a)=d for all a in
(q,a)=d for all q in Q
for all a in -1
Since, *-L is accepted by DFA M, we can say *- L is a regular set.
Hence the theorem proved.
Theorem 3:
A regular is closed under intersection.
Proof:
Let L1 be a regular set then there exist DFA
M1={Q1,,1,q1,F1}
Let L2 be a regular set then there exist DFA
M2={Q2,,2,q2,F2)
Now we define DFA M for intersection
M={Q1xQ2,,,[q1,q2],F1xF2}
([P1,P2],a)=[1(P1,a),2(P2,a)]
Where
P1 is a state in Q1
P2 is a state in Q2
For each state P1 in Q1 and For each state P2 in Q2. So,the regular set is closed under
intersection.
Theorem 4:
A regular set closed under Substitution.
Definition of Substitution:
Let R be a regular set and R*
Let Ra be a particular regular set and Ra*
* is a subset of *
http://francisxavier.ac.in
Page 27
a1,a2,anR
a1,a2,.an is a string in R
w1,w2,.wnRa
w1,w2,.wn is a string in Ra
If the string R is replaced by the string in Ra and will get resultant string, then the
resultant string is also a regular set.
Substitution formally defined as
The function mapping * onto the subset of *.
The f is a function of substitution then the substitution function defined as,
F:**
f() =
f(xa)=f(x)f(a)
Extends this definition to languages and it defined as
F(L)= f(x)
X in L
Example:
f(0)=a , f(1)=b* and find f(010)
f(010)=f(0)f(1)f(0)
=ab*a
Proof:
Let R be a regular set and R*
Let Ra be a regular set and Ra*
* is a subset of *.
If the string R is replaced by the string in Ra and it will get a resultant string, then
the resultant string is also a regular set.
The substitution of Union, Product and Closure is Union, Product and Closure of
Substitution.
Substitution of Union f(L1L2)=Union of substitution f(L1)f(L2)
http://francisxavier.ac.in
Page 28
Similarly Substitution of Product and Closure is the Product and Closure of Substitution.
Hence the theorem is proved.
Theorem 5:
A regular set is closed under Quotient of arbitrary languages.
(q0,xy)
=F
ii.
(q0,y)
=F
iii.
(q0,xy/y)
=F
Theorem 6:
A regular set is closed under homomorphism and inverse homomorphism.
Homomorphism:
Every homomorphism is a substitution and it is denoted as
h(a).
Its function is defined as, h:**
http://francisxavier.ac.in
Page 29
Example:
h(a)=aa h(b)=abaa and find h(aba)
h(aba)=h(a)h(b)h(a)
=aaabaaaa
Inverse homomorphism:
h-1[L]={x|h(x)=L}
h-1{w]={x|h(x)=w}
Proof:
Let L be a regular set then there exist DFA ,
M={Q,,,q0,F}
Now we can define DFA for h(a) and that can be defined as
M={Q,,,q0,F}
We can define
(q,a)=(q,h(a))
Hence the regular set is closed under homomorphism and inverse homomorphism.
2. Select n,
Where,n be a number of states in pumping lemma
3.Select Z=(0),such that |Z|=nn
4. Split Z into uvw,|uv|n,|v|1
uv=0^m, |uv|=mn
v=0^j
w=0^(n- m)
verification:
http://francisxavier.ac.in
Page 30
Z=uvw
=0^m.0^(n-m)
=0^n
Since the above four conditions are satistifed uvw is in L(M).
To Find uv^kw:
Hence proved.
Begin
For p in F and q in Q-F do mark (p,q)
For each pair of distinct states (p,q) in F F or (Q-F) (Q-F) do
If for some input symbol a ((p,a),(q,a)) is marked then
Begin
Mark(p,q)
Recursively mark all unmarked pair on the list
http://francisxavier.ac.in
Page 31
For (p,q) and on the list of other pairs that are marked
End
Else
For all input symbols a do
Put (p,q) on the list for ((p,a),(q,a)) unless
(p,a)=(q,a)
end
2. Select n,
Where,n be a number of states in pumping lemma
3.Select Z=ab,such that |Z|=2nn
4. Split Z into uvw,|uv|n,|v|1
uv=a^m, |uv|=mn
w=a^(n-m).b
v=a^j
verification:
Z=uvw
=a^m.a^(n- m).b
= ab
Since the above four conditions are satistifed uvw is in L(M).
To Find uv^kw:
http://francisxavier.ac.in
Page 32
Hence proved.
The powerful tool used for proving the given language are not regular and
Also useful for developing algorithms to answer the question whether the given language are finite
or infinite.
Pumping Lemma:
If , L is a regular language then it is accepted by DFA, M
Where,M=(Q,,,q0,F)
Assume the set of state of n and the input string contains m number of symbols where,mn
And let, (q0,a1a2ai)=qi
(q0,a1)=q1
(q0,a1a2)=q2
(q0,a1a2a3)=q3
(q0,a1a2an)=qn
In the last case it is not possible for (n+1) number of state. Since, there are only n number of
states.So, we can say all (n+1) number of states are not distinct.
http://francisxavier.ac.in
Page 33
So, there are two integers say j and k such that, j<k and it will be inbetween 0 to n.
0j<kn
So,we can say qj=qk
(diagram)
qm is a final state and it is in F. If, qm is in F then a1a2aj.ak+1am string is accepted by finite
automata and it is a regular language L(M).
To check whether the string a1a2aj.ak+1am is accepted
(q0,a1a2aj.ak+1am)=?
= ((q0,a1a2aj)ak+1am)
= (qj,ak+1am)
=qm which is in F
Hence,it is accepted by FA is in L(M)
To check whether the string a1a2aj.aj+1ak.ak+1am is accepted.
(q0,a1a2aj.aj+1ak.ak+1am)=?
= ((q0,a1a2aj),aj+1ak.ak+1am)
= (qj=qk,aj+1ak.ak+1am)
= ((qj=qk, aj+1ak), ak+1am)
= (qj=qk,ak+1am)
=qm which is in F
Hence,it is accepted by Fa is in L(M)
Consider a language a1a2aj.aj+1...ak.ak+1am the substring aj+1ak can be 0,1,2,3 or any
number of time then the string is accepted by FA is in L(M).
Lemma:
Lregular language
Zis a string in where |z|n
Now,split this Z to uvw such that |uv|n and |v|1.
If these conditions are satisfied then we can say ,u v^i wis in L(M).
http://francisxavier.ac.in
Page 34
How will you prove the given language is not regular using pumping lemma:
2. Select n,
Where,n be the states from the pumping lemma.
3.Select a String Z from L, where L is given |Z|n.
4. If, we select a string Z which satisfies the condition, split the Z into uvw, where |uv| n, |v|1.
5.Make a contradiction to the assumption by showing for the string u, v, w, there exist an integer I
for u v^I w is not regular.
Proof:
From 1 and 2 if set L is a regular set then it is accepted by DFA,
M=(Q, , , q0,F)
If there is x Rm y iff (q0,x)= (q0,y) where,x and y are string in L
http://francisxavier.ac.in
Page 35
For each Z in *
To Find (q0,xz):
(q0,xz)= ((q0,x),z))
= ((q0,y),z)
(q0,xz)= (q0,yz)
If, (q0,x)= (q0,y) then xz Rm yz exist which is right invariant equivalence relation.
Finite:
Equivalence class is that for each state that is reachable from q0.
Since, the number of states are finite the equivalence class is finite.
(diagram)
Regular class:
Each state that is reachable from a (ie) aa, ab, ac, ad, ae, af.
1. Ca= aa={,00,0000,000000,}
The language is described by the expression called regular expression.
The regular expression for Ca is (00)*
http://francisxavier.ac.in
Page 36
2. Cb= ab={0,000,00000,}
The regular expression for Cb is (00)*0
3. Cc= ac={1,001,00001,0000001,}
The regular Expression for Cc is (00)*1
4. Cd= ad={01,0001,000001,00000001,}
The regular Expression for Cd is (00)*01
5. Ce={10,0010,010,00010,0010,0100,}
The regular expression for Ce is (0)*10(0)*
6. Cf={11,110,111,1101,011,00011,}
The regular expression is 0*10*(0+1)*
By Myhill-Nerode Theorem:
L is the union of some of equivalence classes [String accepted by DFA]
(ie)L=Cc U Cd U Ce
To minimizing the number of states of DFA we go for refinement
By combining the number of equivalence classes we can deduce the minimized equivalence
classes.
Number of state = Number of equivalence classes
Page 37
Transition Diagram
UNIT 3
1. Design a Push down Automata which accepts the language L={ww^R|w is in (0+1)*} by
empty stack? Verify the string w=001100 is accepted or not.
A non-deterministic Push down Automata, M which accepts the given language is given by,
M=({q1,q2},{0,1},{R,B,G},,q1,R,)
Where, Q is the set of states(ie)Q={q1,q2}.
is the set of input symbols(ie) ={0,1}.
is the set of stack symbol(ie) ={R,B,G}.
qo is the initial state(ie)q0=q1.
Z0 is the special stack symbol(ie)Zo=R.
F is the set of final states(ie)F= .
is the transition function which is given by,
1. (q1,0,R)={(q1,BR)}
2. (q1,1,R)={(q1,GR)}
3. (q1,0,B)={(q1,BB),(q2, )}
http://francisxavier.ac.in
Page 38
4. (q1,1,B)={(q1,GB)}
5. (q1,0,G)={(q1,BG)}
6. (q1,1,G)={(q1,GG),(q2, )}
7. (q2,0,B)={(q2,)}
8. (q2,1,G)={(q2,)}
9. (q2,,R)={(q2,)}
10. (q2,,R)={(q2,)}
Thus, a PDA is constructed for the given language L.
To verify for the string w=0110 which is of the form L={ww^R|w is in (0+1)*}.
(q1,0110,R) (q1,110,BR)
(q1,10,GBR)
(q1,0,GGBR)
(q2,0,BR)
(q1,,BGGBR)
(q2,,R)
(q2,,)
(q2,1100,R)
(q1,100,GBBR)
(q1,00,GGBBR)
(q2,00,BBR)
(q1,0,BGGBBR)
(q2,0,BR)
http://francisxavier.ac.in
Page 39
(q1,,BBGGBBR)
(q2,,R)
(q2,,)
Therefore, the string is accepted by the above constructed PDA and the language accepted by
the PDA is L={ww^R|w is in (0+1)*}.
By theorem-4
w.k.t. G=(V,T,P,S)
where,V=set of objects [q,A,p] for, all q,p, in Q and A in plus S.
V={S,[qo,Zo,qo],[qo,Zo,q1],[q1,Zo,qo],[q1,Zo,q1],[qo,X,qo],[qo,X,q1],[q1,X,q0],
[q1,X,q1]};
T={0,1}
P is the set of production
S[qo,Zo,qo]
S[q0,Z0,q1]
i)(qo,0,Zo)=(qo,XZo)
[qo,Zo,qo]0[qo,X,q1][q1,Zo,qo]
[qo,Zo,q1]0[qo,X,q1][q1,Zo,q1]
ii) (qo,0,X)=(qo,XX)
[qo,X,qo]0[qo,X,q1][q1,X,qo]
http://francisxavier.ac.in
Page 40
[qo,X,q1]0[qo,X,q1][q1,X,q1]
iii) (qo,1,X)=(q1,)
[qo,X,q1]1
iv) (q1,1,X)=(q1,)
[q1,X,q1]1
v) (q1,,X)=(q1,)
[q1,X,q1]
vi) (q1,,Zo)=(q1,)
[q1,Zo,q1]
http://francisxavier.ac.in
(10)
Page 41
Solution:
( q, , I ) = { (q, a) (q, b) (q, I a) (q, I b) (q, I0) (q, I1) }
(q, a*a + b00, E) + ( q, )
(6)
Solution:
S->XaaX
->aXaaX
->abXaaX
->abbXaaX
->abbaaX
->abbaabX
-> abbaaba
5. Prove the Theore m If L is L(M2) for some PDA, M2,Then L is N(M1)for some PDA, M1.
Proof:
M1 to simulate M2. When M2 reaches the final state,for emptying the stack of M1. We
Introduce a new state qe,for emptying the stack of M1 when M2 reaches final State.
New Stack Symbol Xo is the bottom marker of stack of M1.
Definition of M2:
M2 is is a PDA that accepts the language by reching the final state is denoted as PDA M2,
M2=(Q,, ,,qo,Zo,F)
Definition of M1:
M1 is a PDA that accepts the language by emptying the stack is denoted as PDA,M1,
M1=(QU{qe,qo},, U{Xo},,qo,Xo,)
Where, qo is the initial state of M1,where is defined as,
1. ( qo,a,Xo)=(qo,ZoXo)
http://francisxavier.ac.in
Page 42
2. Expect the initial move all other moves of M1 and M2 are equal,
(q,a,X)= (q,a,Z)
for all q in Q
and a in
and Z in
3.
( qo,,)=(qe,)
4. ( q,,Xo)=(qe,)
To Prove:
Let , x be the input string for the PDA,M2,
Then the Initial ID of M2 is,
*
( qo , x , Zo ) ( q , , ) q is in F.
M2
Let, x be the input string for PDA M1,then the Initial ID is,
( qo , x , Xo ) ( qo , x , ZoXo )
M1
Now, the ID becomes,
*
( qo , x , ZoXo ) ( q , , Xo )
M1
From third definition ,
( q , , Xo ) ( qe , , Xo )
M1
From Fourth definition,
( qe , , Xo ) ( qe , , )
M1
That is L(M2)=N(M1) that is the language accepted by PDA, M2 by reaching the fina l state is equal
for some PDA , M1 accepts the same language by emptying the Stack.
http://francisxavier.ac.in
Page 43
Hence Proved.
UNIT 4
1. Conve rt the following Grammar into GNF
A1A2A3
A2A3A1|b
A3A1A2|a
First check whether the given problem is in CNF Form(ie)
ABC
Aa
The above problem is in CNF and hence we go for GNF.
Step-1:
1) A1A2A3
Apply Step-1
http://francisxavier.ac.in
Page 44
Ai Aj where, ji
Which is in correct form.
2) A2A3A1
Apply Step-1
It is in Correct form .Since, 32
3) A2b
Since, it starts with the terminal.
It is in correct form.
4) A3A1A2
Apply Lemma 1(13)
Until , Ak Al where,l k.
A1 is replaced by its production
A1A2A3
A1A2A3A2
It doesnot satisfy the condition .Hence Apply Lemma 1
A3A3A1A3A2
A3bA3A2
A3A3A1A3A2 , satisfies the condition
The Resultant productions after step-1:
A1A2A3
A2A3A1 | b
A3A3A1A3A2 | bA3A2 | a
Step-2:
In production, A3A3A1A3A2
A3bA3A2
A3 a
L=k since apply lemma-2
Ai
Ai B
Bi
Bi B
http://francisxavier.ac.in
Page 45
2)A1A3A1A3
A1bA3A2A1A3
A1aA1A3
A1aB3A1A3
A1bA3A2B3A1A3
3)A2A3A1
A2bA3A2A1
A2bA3A2B3A1
http://francisxavier.ac.in
Page 46
A2aA1
A2aB3A1
A2b
4)B3A1A3A2
B3bA3A2A1A3A3A2
B3bA3A2B3A1A3A3A2
B3aA1A3A3A2
B3aB3A1A3A3A2
B3bA3A3A2
5)B3A1A3A2B3
B3bA3A3A2B3
B3bA3A2A1A3A3A2B3
B3bA3A2B3A1A3A3A2B3
B3aA1A3A3A2B3
B3aB3A1A3A3A2B3
Page 47
16) B3bA3A3A2
17) B3bA3A3A2B3
18) B3bA3A2A1A3A3A2B3
19) B3bA3A2B3A1A3A3A2B3
20) B3aA1A3A3A2B3
21) B3aB3A1A3A3A2B3
22) A3bA3A2
23) A3bA3A2B3
24) A3aB3
if,m<n
Page 48
Step1:
In the initial state if we find 0 in the input tape and then replace 0 by B and move right until one
is found.
Step2:
Then again move right then if any 0 found replace by 1 then move left until a Blank B is found
To Design a Turing machine:
M=({qo,q1,q2,q3,q4,q5,q6},{0,1},{0,1,B},,qo,B,)
is defined as,
1) (qo,0)=(q1,B,R)
2) (qo,1)=(q5,B,R)
3) (q1,0)=(q1,0,R)
4) (q1,1)=(q2,1,R)
5) (q2,0)=(q3,1,L)
6) (q2,1)=(q2,1,R)
7) (q2,B)=(q4,B,L)
8) (q3,0)=(q3,0,L)
9) (q3,1)=(q3,1,L)
10) (q3,B)=(qo,B,R)
11) (q4,0)=(q4,0,L)
12) (q4,1)=(q4,B,L)
13) (q4,B)=(q6,0,R)
14) (q5,0)=(q5,B,R)
15) (q5,1)=(q5,B,R)
16) (q5,B)=(q6,B,R)
Page 49
4. Explain the TM model with an example and verify the computation of TM with the an
example.
Turing Machine:
It consist of three components,
1)Input Tape
2)Tape Head
3)Finite Control
In one move of the TM ,
1)It changes the state.
2)The scanned input symbol is replaced by which was written in the transition function.
3)Input tape head is moved to right or left.
Formal Definition of Turing machine:
It is a device M defined as,
M=(Q,, ,,qo,B,F)
Where, Q is a set of states
is a set of input symbols
is a set of tape symbols
qo is an initial state and qo is in Q
B is in is a Blank symbol.
F is the set of Final state in Q.
is the transition function mapping to Q Q {L,R}
ID of Turing Machine:
ID of Turing Machine is 1 p 2
Where, p is the state
1 , 2 are strings of symbols.
If the move is,
http://francisxavier.ac.in
Page 50
(q,xi)=(p,y,L)
It goes from q to p and xi is changed to Y and the input tape is moved left.
http://francisxavier.ac.in
Page 51
n n n
5. (i) Show that the language {0 1 2 /n>=1} is not a Context free language.
Solution :
U = an
Vwx = bn
Vx = bn-m
Y= Cn
Z=uvwx(Vx)i-1 y
Multiple tracks
Checking of symbols
Subroutines
BbBavv
Solution:
Sc3c4
Ac1A|a
Bc2B|b
C1a
C2b
C3c1A
C4c2B
http://francisxavier.ac.in
Page 52
Page 53
S3 S1 W
G3
So we can conclude that the string from L1 and L2 can be derived in the languages L1L2. Thus if
L1 and L2 are CFL, then the union of L1 and L2 also a CFL.
Page 54
Let L1 be a context free language .So we can define a context free grammar G1 which derives L1
G1= {V1, T1, P1, S1}
Now we can define L1* a context free language. So we can define a context free grammar G5 which
derives L1*
G5= {V5, T5, P5, S5}
Where
P5P1S5S1|
If W is in L1 then W can be derived from S1 from the grammar G1 in any number of steps
*
S1 W
G1
If W is a string in L1* that is W is in L1
S2 S1 W
G5
G5
S1 derives W from P1
Since P1 is in P5 we can say W is derived from S5 in grammar G5
L1* is in CFL.
Hence the CFLS are closed under Kleen closure.
THEOREM 2:
CFLS are closed under substitution.
Let L be a context free language. So we can define a context free grammar G which derives L
G= {V, T, P, S}
Let La be a context free language. So we can define a context free grammar Ga which
derives La
Ga= {Va, Ta, Pa, Sa}
Now we can define a new grammar G`
G`= {V`, T`, P`,S`}
http://francisxavier.ac.in
Page 55
Where
V=VVa
T`=Ta
S`=S
P`=set of production of G and Ga the P and Pa and a production formed from the
production A by substituting Sa for each a in
We can prove this with an example:
Let L be a language which consist of as and bs.
Let La= {0n1n|n>=1}
Let Lb= {WWR|W(0+2)*}
The language La is derived from the grammar Ga which is Sa 0Sa1|01
The language Lb is derived from the grammar Gb which is Sb0Sba|2Sb2|
Substitution
.f(a) = La
.f(b) = Lb
L is derived from the grammar G
S asbs|
Apply substitution Now we can define a grammar G`
S SaSSbS
Sa 0Sa1|01
Sb 0Sba|2Sb2|
Derive any string from the grammar
SSaSSbS 01SSbS 01SbS 01S 01 01
After substituting we can define a string with have equal number o f ones and zeros.
Therefore CFLS are closed under substitution.
THEOREM 3:
CFLS are closed under homomorphis m and inverse homomorphis m.
Homomorphism is a substitution. So we can prove CFLS are closed inverse homomorphism.
Let L be a CFL and L=h(a) and L be accepted by PDA M
M={Q,,,,q0,Z0,F}
http://francisxavier.ac.in
Page 56
` (q, a, z) = (p, )
Initial ID of PDA M
http://francisxavier.ac.in
Page 57
*
[q0, x, Z0] | (p, , )
M
We have the transition for M`
*
({q0, ], h(x), Z0) |([p, ], , )
M
So we can say h-1(x) is a CFL. Hence we conclude that the context free language closed
under inverse homomorphism.
THEOREM4:
If R is a regular set and L is CFL and RL is CFL.
R is a regular set and it can be accepted by the finite automata and it can defined as,
M= {Qa,a,a,q0,Fa)
L is CFL then it will accepted by PDA which can be defined as,
M= {QM,,,M,P0,Z0,FM)
We have to prove that RL is CFL.
Construct M`,
M` A to M
M`= {QAQM,,,`,[q0,p0],Z0,FAFM)
. q0 is the initial state of qA
. p0 is the initial state of qM
` ([q, p],a , z)=([q` , p`], )
.iff
A (q ,a) = q`
M (p, a, z)= (p`, )
since there is PDA for M`.
Page 58
Considered a CFL
L2= {ai bi cj | i1and j1)
Considered a CFL
L3= { ai bj cj| i1 and j1)
L2 is CFL which can be define a CFG G2
S AB
A aAb|ab
BaB|c
Derived string
SABaAbBaabbBaabbc
L3 is CFL which can be define a CFG G3
SCD
CaC|a
DbDc|bc
Derived string
SCDacDaaDaabc
We can define
L2L3= {ai cj|i1 and j1)
L2 is a CFL and L3 is a CFL but L2L3 is not CFL.
So we can conclude that CFL`S are not closed under intersection.
2.CFLS are not closed under comple mentation.
If the two languages L1 and L2 are CFL.
L1L2 is a CFL and its complementation is not a CFL aond which is equal to L1L2
since L1L2 is not a CFL.
So we can conclude that CFL`S are not closed complementation.
http://francisxavier.ac.in
Page 59
UNIT 5
1. Prove that the universal Language Lu is recursively enume rable and not a recursive.
Recursive:
Definition
Instance of PCP
Modified PCP
Undecidability of PCP
P class Definition
NP class Definition
http://francisxavier.ac.in
Page 60
http://francisxavier.ac.in
Page 61