You are on page 1of 65

FRANCIS XAVIER ENGINEERING COLLEGE

VANNARPETTAI, TIRUNELVELI.

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING

CS2303 - THEORY OF COMPUTATION

Third Year CSE ( Sem:V)

Question Bank

http://francisxavier.ac.in

Page 1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING THEORY


OF COMPUTATION(CS2303)
Third Year CSE( Se m:V)
2 marks Questions and Ans wers

UNIT I
1.

Why are switching circuits called as finite state systems?


A switching circuit consists of a finite number of gates, each of which can be in any
one of the two conditions 0 or 1.Although the voltages assume infinite set of values,the
electronic circuitry is designed so that the voltages corresponding to 0 or 1 are stableand all
others adjust to these value. Thus control unit of a computer is a finite statesystem.

2. What is a : (a) String (b) Regular language


A string x is accepted by a Finite Automaton M=(Q, , .q0,F) if (q0,x)=p, for
some p in F.FA accepts a string x if the sequence of transitions corresponding to the symbols
of x leads from the start state to accepting state.
The language accepted by M is L(M) is the set {x | _(q0,x) is in F}. A language is
regular if it is accepted by some finite automaton.
3. Define: (i) Finite Automaton(FA) (ii)Transition diagram
FA consists of a finite set of states and a set of transitions from state to state that
occur on input symbols chosen from an alphabet _. Finite Automaton is denoted by a 5tuple(Q,, ,q0,F), where Q is the finite set of states , _ is a finite input alphabet, q0 in Q is
the initial state, F is the set of final states and _ is the transition mapping function Q * _ to Q.
Transition diagram is a directed graph in which the vertices of the graph correspond
to the states of FA. If there is a transition from state q to state p on input a, then there is an
arc labeled a from q to p in the transition diagram.
4. . What are the applications of automata theory?
_ In compiler construction.
_ In switching theory and design of digital circuits.
_ To verify the correctness of a program.
_ Design and analysis of complex software and hardware systems.
_ To design finite state machines such as Moore and mealy machines.
5. What is Moore machine and Mealy machine?
A special case of FA is Moore machine in which the output depends on the state of
the machine. An automaton in whch the output depends on the transition and current input is
called Mealy machine.

http://francisxavier.ac.in

Page 2

6. What are the components of Finite automaton model?


The components of FA model are Input tape, Read control and finite control.
(a)The input tape is divided into number of cells. Each cell can hold one i/p symbol
.
(b)The read head reads one symbol at a time and moves ahead.
( c)Finite control acts like a CPU. Depending on the current state and input symbol
read from the input tape it changes state.
7. Differentiate NFA and DFA
NFA or Non Deterministic Finite Automaton is the one in which there exists many
paths for a specific input from current state to next state. NFA can be used in theory of
computation because they are more flexible and easier to use than DFA .
Deterministic Finite Automaton is a FA in which there is only one path for a specific
input from current state to next state. There is a unique transition on each input
symbol.(Write examples with diagrams).
8. What is _-closure of a state q0?
_-closure(q0 ) denotes a set of all vertices p such that there is a path from q0 to p labeled _.
Example :closure(q0)={q0,q1}
9. .Give the examples/applications designed as finite state system.
Text editors and lexical analyzers are designed as finite state
systems. A lexical
analyzer scans the symbols of a program to locate strings corresponding to identifiers,
constants etc, and it has to remember limited amount of information .
10. Define automaton.
Automaton is a abstact computing device. It is a mathematical model of a
system,with discrete inputs,outputs,states and set of tranitions from state to state that occurs
on input symbols from alphabet .
11. what is the principle of mathematical induction.
Let P(n) be a ststement about a non negative integer n. Then the principle of
mathematical induction is that P(n) follows from
(i)
P(1) and
(ii)
P(n-1) implies P(n) for all n>1.
Condition(i) is called the basis step and condition (ii) is called the inductive step. P(n-1) is
called the induction hypothesis.
12. List any four ways of theorem proving
(i)
Deductive
(ii)
If and only if
(iii)
Induction
(iv)
Proof by contradiction.
13. Define TOC
TOC describes the basic ideas and models underlying computing. TOC suggests
various abstract models of computation, represented mathematically.
14. What are the applications of TOC?
Compiler Design
http://francisxavier.ac.in

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

18. Lists the operations on Languages.


(i)
Product
(ii)
Reversal
(iii)
Power
(iv)
Kleene star
(v)
Kleene plus
(vi)
Union
(vii) Intersection
19. Define Graphs.
A graph denoted by G=(V,E) consists of a finite set of vertices (or) nodes V and a set E,
a pair of vertices called edges.
20. Define Substring.
A string v appears within another string w(w=uv) is called substring of w. IF
w=uv,then substrings u & v are said to be prefix and suffix of w respectively.

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

3. What is Ardens Theorem?


Ardens theorem helps in checking the equivalence of two regular expressions. Let P and
Q be the two regular expressions over the input alphabet _. The regula r expression R is
given as : R=Q+RP Which has a unique solution as R=QP*.
4. Write a r.e to denote a language L which accepts all the strings which begin or end with
either 00 or 11.
The r.e consists of two parts:
L1=(00+11) (any no of 0s and 1s) =(00+11)(0+1)*
L2=(any no of 0s and 1s)(00+11) =(0+1)*(00+11)
Hence r.e R=L1+L2 =[(00+11)(0+1)*] + [(0+1)* (00+11)]
5. Construct a r.e for the language over the set _={a,b} in which total number of as are
divisible by 3
( b* a b* a b* a b*)*

6. what is: (i) (0+1)* (ii)(01)* (iii)(0+1) (iv)(0+1)+


(0+1)*= { _ , 0 , 1 , 01 , 10 ,001 ,101 ,101001,}
Any combinations of 0s and 1s.
(01)*={_ , 01 ,0101 ,010101 ,..}
All combinations with the pattern 01.
(0+1)= 0 or 1,No other possibilities.
(0+1)+= {0,1,01,10,1000,0101,.}

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.

What are the applications of Regular expressions and Finite automata


Lexical
analyzers and Text editors are two applications.
Lexical analyzers:
The tokens of the programming language can be expressed using regular
expressions.
The lexical analyzer scans the input program and separates the tokens.For eg
identifier can be expressed as a regular expression
as:
(letter)(letter+digit)*
If anything in the source language matches with this reg exp then it is recognized as
an identifier.The letter is{A,B,C,..Z,a,b,c.z} and digit is {0,1,9}.Thus reg exp
identifies token in a language.
Text editors:
These are programs used for processing the text. For example UNIX
text editors uses the reg exp for substituting the strings such as: S/bbb*/b/
Gives the substitute a single blank for the first string of two or more blanks in
a given line. In UNIX text editors any reg exp is converted to an NFA with transitions,
this NFA can be then simulated directly.

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

w is not in L.Then L is not a regular language.


13. What is the closure property of regular sets?
The regular sets are closed under union, concatenation and Kleene closure.
r1Ur2= r1 +r2
r1.r2= r1r2
( r )*=r*
The class of regular sets are closed under complementation, substitution, homomorphism
and inverse homomorphism.
14. .Reg exp for the language such that every string will have atleast one a followed by
atleast one b.
R=a+b+
15. Write the exp for the language starting with and has no consecutive bs .
reg exp=(a+ab)*
16. Lists on the closure properties of Regular sets.
(i)
Union
(ii)
Concatenation
(iii)
Closure
(iv)
Complementation
(v)
Intersection
(vi)
Transpose
(vii) Substitutions
(viii) Homomorphism
17. Let R be any set of regular languages. IsUR regular? Prove it.
Yes. Let P,Q be any two regular languages .As per theorem
L( R )=L(P UQ)
=L(P+Q)
Since + is a operator for regular expresstions L( R ) is also regular.
18. Show that (r* )* =r* for a regular expression r,
(r* )* =={,r,rr,.}= r*
19. What are the three methods of conversion of DFA to RE?
(i)
Regular Expression equation method
(ii)
Ardens Theorem.
(iii)
State elimination technique,
20. What are the algorithms of minimization DFA?
(i)
Myhill-Nerode Theorem
(ii)
Construction of final from .

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:

6. What is the language generated by the grammar G=(V,T,P,S) where


P={S->aSb, S->ab}?
S=> aSb=>aaSbb=>..=>an bn
Thus the language L(G)={ an bn | n>=1}.The language has strings with equal number of as
and bs.
7. What is :(a) derivation (b)derivation/parse tree (c) subtree
(a) Let G=(V,T,P,S) be the context free grammar. If A-> is a production of P and
and are any strings in (VUT)* then A =>
(b) A tree is a parse \ derivation tree for G if:
(i) Every vertex has a label which is a symbol of VU TU{_}.
http://francisxavier.ac.in

Page 8

(ii) The label of the root is S.


(iii) If a vertex is interior and has a label A, then A must be in V.
(iv) If n has a label A and vertices n1,n2,.. nk are the sons of the vertex n in order
from left with labels X1,X2,..Xk respectively then A X1X2..Xk must be in
P.
(v) If vertex n has label _ ,then n is a leaf and is the only son of its father.
(c ) A subtree of a derivation tree is a particular vertex of the tree together with all its
descendants ,the edges connecting them and their labels.The label of the root may not be the
start symbol of the grammar.
8.

If S->aSb | aAb , A->bAa , A->ba .Find out the CFL


soln. S->aAb=>abab
S->aSb=>a aAb b =>a a ba b b(sub S->aAb)
S->aSb =>a aSb b =>a a aAb b b=>a a a ba b bb
Thus L={an bm ambn , where n,m>=1}

9. What is a ambiguous grammar?


A grammar is said to be ambiguous if it has more than one derivation trees for a
sentence or in other words if it has more than one leftmost derivation or more than one
rightmost derivation.
10. Find CFG with no useless symbols equivalent to : SAB | CA ,
BBC | AB, Aa , CaB | b.
S-> AB
S->CA
B->BC
B->AB
A->a
C->aB
C->b are the given productions.
A symbol X is useful if S => X => w
The variable B cannot generate terminals as B->BC and B->AB.
Hence B is useless symbol and remove B from all productions.
Hence useful
productions are: S->CA , A->a , C->b
11. Construct CFG without production from : S a | Ab | aBa , A b | ,

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

Hence S->aBa becomes S->aa .


Thus S-> a | Ab | b | aBa | aa
A->b
B->b
Finally the productions are: S-> a | Ab | b | aBa | aa
A->b
B->b

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.

Find the grammar for the language L={a 2n bc ,where n>1 }


let G=( {S,A,B}, {a,b,c} ,P , {S} ) where P:
S->Abc
A->aaA |

15. .Find the language generated by :S->0S1 | 0A


| 0 |1B | 1
A->0A | 0 , B->1B | 1
The minimum string is S-> 0 | 1
S->0S1=>001
S->0S1=>011
S->0S1=>00S11=>000S111=>0000A111=>00000111 Thus L={ 0 n 1
m
| m not equal to n, and n,m >=1}
16. Construct the grammar for the language L={ an b an | n>=1}.
The grammar has the production P as:
S->aAa
A->aAa | b
The grammar is thus : G=( {S,A} ,{a,b} ,P,S)
17. . Construct a grammar for the language L which has all the strings which are all palindrome
over ={a, b}.
G=({S}, {a,b} , P, S )
P:{ S -> aSa ,
S-> b S b,
S-> a,
S->b,
S-> } which is in palindrome.
18. Differentiate sentences Vs sentential forms
A sentence is a string of terminal symbols.
http://francisxavier.ac.in

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.

19. .Define Pushdown Automata.


A pushdown Automata M is a system (Q, , , ,q0 , Z0 ,F) here
finite set of states.
is an alphabet called the input alphabet.
is an alphabet called stack alphabet.
q0 in Q is called initial state.
Zo in is start symbol in stack.
F is the set of final states.
is a mapping from Q X ( U {} ) X to finite subsets of
Q X *.

Q is a

20. 3.Specify the two types of moves in PDA.


The move dependent on the input symbol(a) scanned is:
(q,a,Z) = { ( p1, 1 ), ( p2,2 ),..( pm,m ) }
where q qnd p are states , a is in ,Z is a stack symbol and
i is in *. PDA is in state q , with input symbol a and Z the top symbol on state enter state p
iReplace symbol Z by string i
The move independent on input symbol is (-move):
(q,,Z)= { ( p1,1 ), ( p2,2 ),( pm,m ) }.
Is that PDA is in state q ,
independent of input symbol being scanned and with Z the top symbol on the stack enter a state
p i and replace Z by i.
21. What are the different types of language acceptances by a PDA and define them.
For a PDA M=(Q, , , ,q0 ,Z0 ,F ) we define :
(i) Language accepted by final state L(M) as:
* { w | (q0 , w , Z0 ) |-- ( p, , ) for some p in F and in * }.
(ii) Language accepted by empty / null stack N(M) is:
{ w | (q0,w ,Z0) |----( p, , ) for some p in Q}.
22. Is it true that the language accepted by a PDA by empty stack and final states are different
languages.
No, because the languages accepted by PDA s by final state are exactly the
languages accepted by PDAs by empty stack.

23. Define Deterministic PDA.


A PDA M =( Q, , , ,q0 ,Z0 ,F ) is deterministic if:
For each q in Q and Z in , whenever (q,,Z) is nonempty then (q,a,Z) is
empty for all a in .
For no q in Q , Z in , and a in U { } does (q,a,Z) contains more than one
element. (Eg): The PDA accepting {wcw R | w in ( 0+1 ) * }.
http://francisxavier.ac.in

Page 11

24. Define Instantaneous description(ID) in PDA.


ID describe the configuration of a PDA at a given instant.ID is a triple such as (q, w , ) ,
where q is a state , w is a string of input symbols and
is a string of stack symbols.
If M =( Q, , , ,q0 ,Z0 ,F ) is a PDA we say that
(q,aw,Z) |-----( p, , ) if (q,a,Z) contains (p, ).
M
a may be or an input symbol. Example: (q1, BG) is in (q1, 0 , ) ells that (q1,
011, GGR )|---- ( q1, 11,BGGR).
25. .What is the significance of PDA?
Finite Automata is used to model regular expression and cannot be used to represent non
regular languages. Thus to model a context free language, a Pushdown Automata is used.
26. When is a string accepted by a PDA?
The input string is accepted by the PDA if:
o The final state is reached .
o The stack is empty.
27. . Give examples of languages handled by PDA.
(1) L={ a n bn | n>=0 },here n is unbounded , hence counting cannot be done by finite memory.
So we require a PDA ,a machine that can count without limit.
(2) L= { wwR | w {a,b}* } , to handle this language we need unlimited counting
capability .

28. Is NPDA (Nondeterministic PDA) and DPDA (Deterministic PDA)equivalent?


The languages accepted by NPDA and DPDA are not equivalent. For example: wwR
is accepted by NPDA and not by any DPDA.
29. State the equivalence of acceptance by final state and empty stack.
If L = L(M2) for some PDA M2 , then L = N(M1) for some PDA M1.
If L = N(M1) for some PDA M1 ,then L = L(M2 ) for some PDA M2
where L(M) = language accepted by PDA by reaching a final state.
N(M) = language accepted by PDA by empty stack.

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.

Let G= ( {S,C} ,{a,b},P,S) where P consists of S->aCa , C->aCa |b. FindL(G).


S-> aCa => aba
S->aCa=> a aCa a=>aabaa
S->aCa=> a aCa a=> a a aCa a a =>aaabaaa
Thus L(G)= { an ban ,where n>=1 }

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.

What are the closure properties of CFL?


CFL are closed under union, concatenation and Kleene closure.
CFL are closed under substitution , homomorphism. CFL are not closed under intersection ,
complementation. Closure properties of CFLs are used to prove that certain languages are not
context free.
7.

State the pumping lemma for CFLs.


Let L be any CFL. Then there is a constant n, depending only on L, such that if z is in
L and |z| >=n, then z=uvwxy such that :
(i) |vx| >=1
(ii) |vwx| <=n and
(iii) for all i>=0 uviwxiy is in L.

8.

What is the main application of pumping lemma in CFLs?


The pumping lemma can be used to prove a variety of languages are not context free .
Some examples are:
L1 ={ aibici | i>=1} is not a CFL.

http://francisxavier.ac.in

Page 13

L2= { aibjcidj | i>=1 and J>=1 } is not a CFL.


9. What is Ogdens lemma?
Let L be a CFL. Then there is a constant n such that if z is any word in L, and we mark any
n or more positions of z distinguished then we can write z=uvwxy suchthat:
(1) v and x together have atleast one distinguished position.
(2) vwx has at most n distinguished positions and
(3) for all i>=0 uviwxiy is in L.
10. Give an example of Deterministic CFL.
The language L={anbn : n>=0} is a deterministic CFL
11. What are the properties of CFL?
Let G=(V,T,P,S) be a CFG
The fanout of G , _(G) is largest number of symbols on the RHS of any rule
in R.
The height of the parse tree is the length of the longest path from the root to
some leaf.

12.

What is a turing machine?


Turing machine is a simple mathematical model of a computer. TM has unlimited
and unrestricted memory and is a much more accurate model of a general purpose computer. The
turing machine is a FA with a R/W Head. It has an infinite tape divided into cells ,each cell
holding one symbol.
13.

What are the special features of TM?


In one move ,TM depending upon the symbol scanned by the tape head and
state of the finite control:
Changes state.
Prints a symbol on the tape cell scanned, replacing what was written there.
Moves the R/w head left or right one cell.

14.

Define Turing machine.


A Turing machine is denoted as M=(Q,, , ,q0, B,F)
Q s a finite set of states.
is set of i/p symbols ,not including B.
is the finite set of tape symbols.
q0 in Q is called start state.
B in is blank symbol.
F is the set of final states.
is a mapping from Q X to Q X X {L,R}.
15.

Define Instantaneous description of TM.


The ID of a TM M is denoted as 1q 2 . Here q is the current state of M s in Q; 1 2 is
the string in * that is the contents of the tape up to the rightmost nonblank symbol or the symbol
to the left of the head, whichever is the rightmost.
http://francisxavier.ac.in

Page 14

16.

What are the applications of TM?


TM can be used as:
Recognizers of languages.
Computers of functions on non negative integers.
Generating devices.

17.

What is the basic difference between 2-way FA and TM?


Turing machine can change symbols on its tape , whereas the FA cannot change
symbols on tape. Also TM has a tape head that moves both left and right side ,whereas the FA
doesnt have such a tape head.
18.

What is (a)total recursive function and (b)partial recursive function


If f(i1,i2,ik) is defined for all i1,..ik then we say f is a total recursive function.
They are similar to recursive languages as they are computed by TM that always halt.
A function f(i1,ik) computed by a Turing machine is called a partial recursive function.
They are similar to r.e languages as they are computed by TM that may or may not halt on a given
input.

19.

Define a move in TM.


Let X1 X2X i-1 q XiXn be an ID.
The left move is: if _ (q, Xi )= (p, Y,L) ,if i>1 then X1 X2X i-1 q XiXn |---X1X2 X i-2 p X i-1 Y X i+1Xn. M The right move is if _ (q, Xi )= (p, Y,R) ,if i>1 then
X1 X2X i-1 q XiXn |---- X1X2 X i-1Y p X i+1Xn. M

20.

What is the language accepted by TM?


The language accepted by M is L(M) , is the set of words in _ * that cause M to enter
a final state when placed ,justified at the left on the tape of M, with M at qo and the tape
head of M at the leftmost cell. The language accepted by M is: { w | w in _ * and q0w |--- _1
p _2 for some p in F and _1 ,_2 in _ * }.

21.

Give examples of total recursive functions.


All common arithmetic functions on integers such as multiplication , n!, [log2n] and
22n are total recursive functions.

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

the techniques for Turing machine construction?


Storage in finite control.
Multiple tracks.
Checking off symbols.
Shifting over
Subroutines.

5. What is the storage in FC?


The finite control(FC) stores a limited amount of information. The state of the Finite control
represents the state and the second element represent a symbol scanned.
6.When is checking off symbols used in TM?
Checking off symbols is useful method when a TM recognizes a language with
repeated strings and also to compare the length of substrings.
(eg) : { ww | w _ _ * } or {aibi | i>=1}. This is implemented by using an extra track on the tape with
symbols Blank or .

7.When is shifting over Used ?


A Turing machine can make space on its tape by shifting all nonblank
symbols a finite number of cells to the right. The tape head moves to the right , repeatedly storing
the symbols in the FC and replacing the symbols read from the cells to the left. The TM can then
return to the vacated cells and prints symbols.

http://francisxavier.ac.in

Page 16

8. What is a multihead TM?


A k-head TM has some k heads. The heads are numbered 1 through k, and
move of the TM depends on the state and on the symbol scanned by each head. In one move, the
heads may each move independently left or right or remain stationary.
9.What is a 2-way infinite tape TM?
In 2-way infinite tape TM, the tape is infinite in both directions. The leftmost square
is not distinguished. Any computation that can be done by 2-way infinite tape can also be done by
standard TM.
10.

How can a TM used as a transducer?


A TM can be used as a transducer. The most obvious way to do this is to treat the
entire nonblank portion of the initial tape as input , and to treat the entire blank portion of the tape
when the machine halts as output. Or a TM defines a function y=f(x) for strings x ,y _ _* if: q0X | -- qfY, where qf is the final state.
11. What is a multi-tape Turing machine?
. A multi- tape Turing machine consists of a finite control with k-tape heads and ktapes ; each tape is
infinite in both directions. On a single move depending on the state of finite control and symbol
scanned by each of tape heads ,the machine can change state print a new symbol on each cells
scanned by tape head, move each of its tape head independently one cell to the left or right or
remain stationary.
12.

.What is a multidimensional TM?


The device has a finite control , but the tape consists of a k-dimensional array of cells infinite
in all 2k directions, for some fixed k. Depending on the state and symbol scanned , the device
changes state , prints a new symbol and moves its tapehead in one of the 2k directions, either
positively or negatively ,along one of the k-axes.
13. When a recursively enumerable language is said to be recursive ? Is it true that the language
accepted by a non-deterministic Turing machine is different from recursively enumerable language?
A language L is recursively enumerable if there is a TM that accepts L and
recursive if there is a TM that recognizes L. Thus r.e language is Turing acceptable and recursive
language is Turing decidable languages. No , the language accepted by non-deterministic Turing
machine is same as recursively enumerable language.
13. What is Churchs Hypothesis?
The notion of computable function can be identified with the class of partial recursive
functions is known as Church- hypothesis or Church-Turing thesis. The Turing machine is equivalent
in computing power to the digital computer.

14. When we say a problem is decidable? Give an example of undecidable


problem?
A problem whose language is recursive is said to be decidable.
Otherwise the problem is said to be undecidable. Decidable problems have an
algorithm that takes as input an instance of the problem and determines whether
http://francisxavier.ac.in

Page 17

the answer to that instance is yes or no.


(eg) of undecidable problems are
(1)Halting problem of the TM.
15. Give examples of decidable problems.
1. Given a DFSM M and string w, does M accept w?
2. Given a DFSM M is L(M) = _ ?
3. Given two DFSMs M1 and M2 is L(M1)= L(M2) ?
4. Given a regular expression _ and a string w ,does _ generate w?
5. Given a NFSM M and string w ,does M accept w?
16. Give examples of recursive languages?
i. The language L defined as L= { M ,w : M is a DFSM that
accepts w} is recursive.
ii. L defined as { M1 U M2 : DFSMs M1 and M2 and L(M1)
=L(M2) } is recursive.
17. What are UTMs or Universal Turing machines?
Universal TMs are TMs that can be programmed to solve any problem, that can be solved by
any Turing machine. A specific Universal Turing machine U is:
Input to U: The encoding M of a Tm M and encoding w of a string w.
Behavior : U halts on input M w if and only if M halts on input w.
18. What is the crucial assumptions for encoding a TM?
There are no transitions from any of the halt states of any given TM .
Apart from the halt state , a given TM is total.
19. What properties of recursive enumerable seta are not decidable?
o Emptiness
o Finiteness
o Regularity
o Context-freedom.
20. Define L .When is a trivial property?
L is defined as the set { <M> | L(M) is in . } is a trivial property if is empty or it consists of
all r.e languages.
21.What is a universal language Lu?
The universal language consists of a set of binary strings in the form of
pairs (M,w) where M is TM encoded in binary and w is the binary input string.
Lu = { < M,w> | M accepts w }.
22.What is a Diagonalization language Ld?
The diagonalization language consists of all strings w such that the TM M
whose code is w doesnot accept when w is given as input.
23. What properties of r.e sets are recursively enumerable?
o L
o L contains at least 10 members.
http://francisxavier.ac.in

Page 18

o w is in L for some fixed w.


o L Lu

24. What properties of r.e sets are not r.e?


L=
L = *.
L is recursive
L is not recursive.
L is singleton.
L is a regular set.
L - Lu
25. What are the conditions for L to be r.e?
L is recursively enumerable iff satisfies the following properties:
i. If L is in and L is a subset of L_ ,then L_ is in (containment property)
ii. If L is an infinite language in ,then there is a finite subset of L in .
iii. The set of finite languages in is enumaerable.
26. What is canonical ordering?
Let * be an input set. The canonical order for *as follows . List words in
order of size, with words of the same size in numerical order. That is let _ ={
x0,x1,x t-1 } and xi is the digit i in base t.
(e.g) If _ ={ a,b } the canonical order is * , a ,b , aa, ab ,..
27. How can a TM acts as a generating device?
In a multi- tape TM ,one tape acts as an output tape, on which a symbol, once written can
never be changed and whose tape head never moves left. On that output tape , M writes strings over
some alphabet _ , separated by a marker symbol # , G(M) ( where G(M) is the set w in * * such
that w is finally printed between a pair of #s on the output device ).
28. What are the different types of grammars/languages?
o Unrestricted or Phase structure grammar.(Type 0 grammar).(for TMs)
o Context sensitive grammar or context dependent grammar (Type1)(for
Linear Bounded Automata )
o Context free grammar (Type 2) (for PDA)
o Regular grammar (Type 3) ( for Finite Automata).
This hierarchy is called as Chomsky Hierarchy.

29. Show that AMBIGUITY problem is un-decidable.


Consider the ambiguity problem for CFGs. Use the yes-no version of AMB. An algorithm
for FIND is used to solve AMB. FIND requires producing a word with two or more parses if one
exists and answers no otherwise. By the reduction of AMB to FIND we conclude there is no
algorithm for FIND and hence no algorithm for AMB.
30.State the halting problem of TMs.
http://francisxavier.ac.in

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

1. Discuss about the four ways of theore m proving with an example.


(i)

Deductive

(ii)

If and only if

(iii)

Induction

(iv)

Proof by contradiction

2. Prove by mathe matical induction, for n1,

Using Basis Step

Using Inductive step

= n(n+1)(n+2) / 6.

[8 marks]

3. Explain in detail about the conve rsion of NFA to DFA.


Draw the NFAs transition table
Take the initial state of NFA be the initial state of DFA.
Transit the initial state for all the input symbols.
If new state appears transit it again and again to make all state as old state.
All the new states are the states of the required DFA
Draw the transition table for DFA
Draw the DFA from the transition table.

4. Conve rt the following NFA to its equivalent DFA.

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

5. Construct DFA equivalent to the following NFA


0,1

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

length less tha n or equa l to n.

Induc tive ste p

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

Other ele me nts of N' and N

We can show that

i.e. N' and N are equivale nt.

We nee d to prove that

i.e.

We will show som ething m ore, that is,


http://francisxavier.ac.in

Page 24

W e will show s omething m ore, that is,

Basis :

, the n

But

by definition of

Induc tion hypothes is Let the state m e nt hold for all

with

By de finition of exte nsion of


By inductions hypothesis.
Ass um ing that

By de finition of

Since

T o com ple te the proof we cons ider the case

Whe n

i.e.

then

8. Discuss about the Conversion of DFA into regular expression.


Ardens theorem is used to find regular expression from the DFA.
Using this theorem if the equation is of the form R=Q+RP,we
can write this as R=QP*.
Write the equations for all the states.
Apply Ardens theorem and eliminate all the states.
Theory of Computation 22
Find the equation of the final state with only the input symbols.
http://francisxavier.ac.in

Page 25

Made the simplifications if possible


The equation obtained is the required regular expression.

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)

Kleen closure L(M)=[L(M)]*

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.

Quotient of languages L1 and L2 is given as L1/L2 which is defined as

L1/L2={x| there exit y in L2 such that xy in L1}


Example
L1=0*01*
L2=01*
L1/L2=0*
Proof:
Let R be a regular set then there exist DFA ,
M={Q,,,q0,F}
Now we can define DFA for R/L and that can be defined as
M={Q,,,q0,F}
The string xy accepted by DFA M
i.

(q0,xy)

=F

ii.

(q0,y)

=F

iii.

(q0,xy/y)

=F

Hence a regular set is closed under Quotient of arbitrary languages.

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. Show that L={0 | n=i,I is an integer i>=1} is not regular.


1. Let, L={0 | n=i,I is an integer i>=1}is regular.

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:

u v^k w=uv v^(k-1) w


=0^n (0^j)^k-1
5. To Find an integer,
For k=0
u v^k w is not equal to (0)
for k=1
u v^k w is equal to (0)
for k=2
u v^k w is not equal to (0)
for k=0,2,. u v^k w is false.
So, L={0 | n=i,I is an integer i>=1}is not regular.

Hence proved.

3. Explain the algorithm for Minimization of DFA.

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

4. Show that L={ab|n>=1} is not regular.


1.Let, L={ab|n>=1}is regular.

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

u v^k w=uv v^(k-1) w


= ab .(a^j)^k-1
5. To Find an integer,
For k=0
u v^k w is not equal to ab
for k=1
u v^k w is equal to ab
for k=2
u v^k w is not equal to ab
for k=0,2,. u v^k w is false.
So, L={ ab|n>=1}is not regular.

Hence proved.

5. Write short note on Pumping Lemma for regular languages.

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

Transition Diagram is,

(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

Application of pumping Lemma:


It is used for proving the given language is not regular.

How will you prove the given language is not regular using pumping lemma:

1.Assume given language is regular.

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.

6. Explain Myhill-Nerode theore m with an example in detail.

In this theorem the following three states are equivalent,


1. The regular set L which is contained in * is accepted by DFA M,
M= (Q, , , q0, F)
2. L is the union of some of the equivalence classes of the right invariant equivalence
relation with finite index.
3. x Rm y iff for each Z in * xz Rm yz

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.

L is the union of some of equivalence classes:


L is the union of String x such that (q0,x) is in F (ie) x is accepted by DFA.
(ie) L is the unio of string which is accepted by DFA.
X Rm y iff for each Z in * xz Rm yz
If, x Rm y iff,
(q0,x)= (q0,y)
For each string Z in *,
(q0,xz)= ((q0,x),z)) = ((q0,y),z)
(q0,xz)= (q0,yz)

Hence, xz Rm yz is an equivalence relation Rm.


Hence, Myhill-Nerode theorem is proved.

Example for Myhill-Nerode Theorem:

(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

Refinement of Ca and Cb:


Ca=(00)*
Cb=(00)*0
Which is refined as 0* (ie) C1=0*
Refinement of Cc,Cd and Ce:
Cc=(00)*1
Cd=(00)*01
Ce=(0)*10(0)*
http://francisxavier.ac.in

Page 37

which is refined as 0*10* (ie) C2=0*10*


Cf=0*10*(0+1)*
Which is given as C3=0*10*(0+1)*
Now, the states of DFA are minimized to 3 State C1,C2,C3.
Transition function:
([x],a)=[xa]
1. ([C1],0)=0*0=0*=C1
2. ([C1],1)=0*1=0*10*=C2
3. ([C2],0)=0*10*0=0*10*=C2
4. ([C2],1)=0*10*1=0*10)(0+1)*=C3
5. ([C3],0)=0*10*(0+1)*0=C3
6. ([C3],1)=0*10*(0+1)*1=C3

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,,)

Therefore the string w=0110 is accepted by the PDA.

Check the string w=001100 is accepted by the PDA:


(q1,001100,R) (q1,01100,BR)
(q1,1100,BBR)

(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)*}.

2. Construct a CFG gene rating N(M), where, M is given by,


M({q0,q1},{0,1},{X,Zo},,qo,Zo,)
(qo,0,Zo)={(qo,XZo)}
(qo,0,X)={(qo,XX)}
(qo,1,X)={(q1,)}
(q1,1,X)={(q1,)}
(q1,,X)={(q1,)}
(q1,,Zo)={(q1,)}

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]

For the two variables,


[q1,Zo,qo]
[q1,X,qo]
There is no production. So, we cannot find the string.
We have to delete the production which contains these two variables in both the RHS (or) LHS.
[qo,Zo,qo]0[qo,X,q1][q1,Zo,qo]
[qo,X,qo]0[qo,X,q1][q1,X,qo]
S[qo,Zo,qo]
Production are deleted.
So, the set of productions are,
S[q0,Z0,q1]
[qo,Zo,q1]0[qo,X,q1][q1,Zo,q1]
[qo,X,q1]0[qo,X,q1][q1,X,q1]
[qo,X,q1]1
[q1,X,q1]1
[q1,X,q1]
[q1,Zo,q1]

3. Generate the PDA for the following grammar


E-> E+E | E*E| E-E| I
I-> a| b | Ia | Ib | I0 | I1

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, )

4. Find the language generated by


S->XaaX
X-> aX|bX|
Derive abbaaba from the given Grammar

(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

New variable is B3,


A3bA3A2
A3bA3A2B3
A3a
A3aB3
B3A1A3A2
B3A1A3A2B3
The resultant productions after Step-2:
1) A1A2A3
2) A2A3A1
3) A2b
4) A3bA3A2
5) A3bA3A2B3
6) A3a
7) A3aB3
8) B3A1A3A2
9) B3A1A3A2B3
Step-3:
A3 production are converted to GNF forms since, it starts with terminal.
Apply Lemma-1
1)A1A2A3
A1A3A1A3
A1bA3

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

The Resultant productions after step-3:


1) A3a
2) A1bA3
3) A1bA3A2A1A3
4) A1aA1A3
5) A1aB3A1A3
6) A1bA3A2B3A1A3
7) A2bA3A2A1
8) A2bA3A2B3A1
9) A2aA1
10) A2aB3A1
11) A2b
12) B3bA3A2A1A3A3A2
13) B3bA3A2B3A1A3A3A2
14) B3aA1A3A3A2
15) B3aB3A1A3A3A2
http://francisxavier.ac.in

Page 47

16) B3bA3A3A2
17) B3bA3A3A2B3
18) B3bA3A2A1A3A3A2B3
19) B3bA3A2B3A1A3A3A2B3
20) B3aA1A3A3A2B3
21) B3aB3A1A3A3A2B3
22) A3bA3A2
23) A3bA3A2B3
24) A3aB3

2. Explain Computable Languages and Functions with an Example.


The language accepted (or) computed by turing machine is recursively enumerable.
Enumerablenumber of languages may be listed by turing machine.
Recursively enumerable includes CFL.
Computable functions of TM:
This Tm can be viewed as a Computer of functions from integers to integers.
.
Eg: String=0 for i > 0
Can be stored in the input tape of turing machine as,
0^i1 1 0^i2 1 0^i3 1 1 0^ik
It is a function of k integer arguments ,
f(i1,i2,i3,ik)
If the turing machine halts for any 0^m then, the String 0^m is Accepted
Then the function with k arguments is defined as,
f(i1,i2,i3,ik)=m
It is not in need to define k number of arguments since it accepts only m number of 0s.
In the function f(i1,i2,i3,ik) if all the k arguments are defined then it is said to be Total
Recursive Function.
The arguments which are computed by the TM is said to be Partial Recursive Function.
3. Design a TM for prope r Subtraction (ie)m_ n= m-n if,mn
0
http://francisxavier.ac.in

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)

Verify for the string w=0100


m=1
n=2
Here,m<n
So, there must be zero number of 0s.
qo 0100 B q1 100B1 q2 00B q3 110q3 B110B q0 110BB q5 10BBB q5 0
BBBB q5 BBBBBB q6
http://francisxavier.ac.in

Page 49

Here, there is no Zero is present.Hence, our design of turing machine is correct.


*
qo 0100 BBBBB q6
M

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.

Language accepted by TM:


Language accepted by TM is a string w, such that ,w * and
*
qo w 1 p 2 for some p in F.
M
*
L={w| w * and qo w 1 p 2 , for some p in F}
M

Eg: For Turing Machine:


The TM, M is given by,
M=({qo,q1,q2,q3,q4},{0,1,x,y},{0,1,x,y,B}, ,qo,B,{q4})
is defined as,
(qo,0)=(q1,x,R)
(q1,0)=(q1,0,R)
(q2,0)=(q2,0,L)
(q1,1)=(q2,y,L)
(q2,x)=(qo,x,R)
(qo,y)=(q3,y,R)
(q1,y)=(q1,y,R)
(q2,y)=(q2,y,L)
(q3,y)=(q3,y,R)
(q3,B)=(q4,B,R)
To verify the string w=0011 is accepted by TM.
qo 0011 x q1 011 xo q1 11 x q2 0y1 q2 xoy1 x qo 0y1 xx q1 y1 xxy q1 1
xx q2 yy x q2 xyy xx qo yy xxy q3 y xxyy q3 B xxyyBq4
The string w=0011 is accepted by the TM. Since, q4 is a final state and there is no transition for
(q4,B).

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

5. (ii) Discuss about the programming techniques for turing machines.


Solution :

Storage in finite control

Multiple tracks

Checking of symbols

Subroutines

6. (i) Show that the language L={WCWR W={0,1}} is not CFL.


Solution:
U=0n
Vwx=1n
Vx=1n-m
Y=c1n0n
6. (ii) Find a gramme r in CNF equivalent to the following production
SaAbB
AaAa ,

BbBavv

Solution:
Sc3c4
Ac1A|a
Bc2B|b
C1a
C2b
C3c1A
C4c2B
http://francisxavier.ac.in

Page 52

7. Explain in detail about closure properties of CFL?


THEOREM-1:
CFLS are closed under Union, Concatenation, Kleen closure.
1. CFLS are closed under union
Let L1 be a context free language. So we can define a context free grammar G1 which derives L1
G1= {V1, T1, P1, S1}
Let L2 be a context free language. So we can define a context free grammar G2 which derives L2
G2= {V2, T2, P2, S2}
V1 and V2 are disjoint and independent.
Assume: S3, S4, S5 not in V1 and V2
Now we can prove L1L2 is a context free language. So we can define context free grammar G3
which derives L1L2
G3= {V3, T3, P3, S3}
Where,
V3=V1V2S
T3=T1 T2
P3=P1 P2 S3 S1|S2
S3 is the new start symbol.
If W is the string in L1 and W can be define from the grammar G1 in any number of steps
*
S1 W
G1
If W is the string in L2 and W can be define from the grammar G2 in any number of steps.
*
S2 W
G2
If W is the string in L1L2 and W may be in L1 and L2 then W is derived from S3 from the
grammar G3 in any number of steps.
*
http://francisxavier.ac.in

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.

2. CFLS are closed under concatenation


Let L1 be a context free language. So we can define a context free Grammar G1 which derives L1.
G1= {V1, T1, P1, S1}
Let L2 be a context free language. So we can define a context free grammar G2 which derives L2
G2= {V2, T2, P2, S2}
Now we can define L1|L2 is a context free language
G4= {V4, T4, P4, S4}
Where
V4= V1 V2 S4
T4= T1 T2
P4=P1P2S4S1S2
If W is L1 we can define S1
*
S1 W
G1
If W is L2 we can define S2
*
S2 W
G2
If W is L1|L2 then W is from S4 in any number of steps
*
S4 W
G4
S4 S1S2 W
So we can conclude that the concatenation of two CFLS is also a Context free language
3. CFLS are closed under Kleen closure
http://francisxavier.ac.in

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

Now we can prove


h-1(a)CFL
M` is constructed as ,
Simulate M` to M
Now we can define
M`= {Q`,,,`,{q0,},Z0,F`}

Q`set of state of PDA M`


Q` in the form of [q, x]
Where
.q is a state in Q
.X is a suffix of h(a)
set of input symbols
set of stack symbols
` Transition function mapping from
QQ
{q0,}initial state of M, initial Buffer content.
Z0initial stack symbol.
F`Final state.
` defined as,
1.`([q, x], , z)=([p, x],)
Iff
` (q, , z) = (p, )
2.`([q, ax], , z)=([p ,x],)
Iff
` (q, a, z) = (p, )
3.

` ([q, x], a, z) = ([p, h(a), )


Iff

` (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`.

We can conclude that RL is CFL.


THEOREM 5:
http://francisxavier.ac.in

Page 58

CFL`S are not closed intersection and comple mentation.


1.CFLS are not closed under intersection.

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:

Ist tape input tape

2nd tape simulate the tape of m

3rd tape holds the state of m


Not recursive:

Calculate the value of I such that w=wi

2. Explain Post Correspondence Problem with an example in Detail.

Definition

Instance of PCP

Modified PCP

Reducing mPCP to PCP

Undecidability of PCP

3. Discuss about P class and NP class proble m.

P class Definition

P class problem with example

NP class Definition

NP class problem with example

4. (i) Prove that if L is recursive, So complement of L is also recursive.


(ii) L if L and comple ment of L are recursively enumerable.
(iii) Lu is recursively enumerable but not recursive.

http://francisxavier.ac.in

Page 60

http://francisxavier.ac.in

Page 61

5. Discuss about Diagonalization language Ld.

This table represents language acceptable by Turing machine

Proof that Ld is not recursively enumerable:

Recurs ive Languages:

You might also like