Академический Документы
Профессиональный Документы
Культура Документы
THEORY OF COMPUTATION(CS2303)
Third Year CSE( Sem:V)
2 marks Questions and Answers
UNIT I
1.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
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.
/
k
.t
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
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
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.
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
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
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.
/
k
.t
e
b
tu
e
s
/c
14. .Reg exp for the language such that every string will have atleast one a
followed by atleast one b.
R=a+b+
/
:
tp
ht
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.
http://csetube.weebly.com/
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.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
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 ->
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
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
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.
http://csetube.weebly.com/
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.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
UNIT IV
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
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?
http://csetube.weebly.com/
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.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
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}.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
UNIT V
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
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 nondeterministic 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
the answer to that instance is yes or no.
(eg) of undecidable problems are
(1)Halting problem of the TM.
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/
UNIT-I AUTOMATA
Part B
1. a) If L is accepted by an NFA with -transition then show that L is accepted by an
NFA without -transition.
b) Construct a DFA equivalent to the NFA.
M=({p,q,r},{0,1}, ,p,{q,s})
Where is defined in the following table.
p
q
r
s
0
{q,s}
{r}
{s}
n
1
{q}
{q,r}
{p}
{p}
2. a)Show that the set L={a b /n>=1} is not a regular. (6) b)Construct a DFA equivalent
to the NFA given below: (10)
0
1
p
{p,q}
P
q
r
R
r
s
s
s
S
/
k
.t
e
b
tu
e
s
/c
n
3. a)Check whether the language L=(0 1 /n>=1) is regular or not? Justify your answer.
b) Let L be a set accepted by a NFA then show that there exists aDFA that accepts L.
4. Define NFA with -transition. Prove that if L is accepted by an NFA with transition then L is also accepted by a NFA without -transition.
/
:
tp
ht
http://csetube.weebly.com/
8.a) Prove that a language L is accepted by some NFA if and only if L is accepted
by some DFA. (8)
b) Consider the following NFA.Compute the closure of each state and find its
equivalent DFA. (8)
A
b
C
p
{q}
{p}
{r}
{q}
*r
{r}
9.a) Prove that a language L is accepted by some DFA if L is accepted by some NFA.
b) Convert the following NFA to its equivalent DFA
0
1
p
{p,q}
{p}
q
{r}
{r}
r
{s}
*s
/
k
.t
e
b
tu
{s}
{s}
10.a) Explain the construction of NFA with transition from any given regular
expression.
b) Let A=(Q,, , q0 ,{qf ) be a DFA and suppose that for all a in wehave (q0, a)=
e
s
/c
/
:
p
(qf ,a). Show that if x is a non empty string in L(A),then for all k>0,x is also in
L(A).
t
t
h
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
p
7.
a)Define a Regular set using pumping lemma Show that the language L={0i / i is
an integer,i>=1} is not regular
b)Construct an NFA equivalent to the regular expression 10+(0+11)0*1
8.
t
t
h
n2/n
((10)+(0+1) 01. (10) 9.a)Prove that if L=L(A) for some DFA A,then there
is a regular expression R such that L=L(R).
p
m n+m
(ii) L={0 1 2
k
,n,m>=1}
2
11.a) Find the regular expression for the set of all strings denoted by R 13 from the
deterministic finite automata given below:
http://csetube.weebly.com/
b)Verify whether the finite automata M1 and M2 given below are equivalent over
{a,b}.
12.a)Construct transition diagram of a finite automaton corresponding to the
* *
/
k
.t
e
b
tu
b)Find the regular expression for the set of all strings denoted by R 23 from the
deterministic finite automata given below.
e
s
/c
/
:
tp
ht
14.a) Find whether the languages {ww,w is in (1+0)*} and {1 | k=n , n>=1} are
regular or not.
b) Show that the regular languages are closed under intersectionand reversal.
http://csetube.weebly.com/
6.
/
k
.t
e
b
tu
e
s
/c
b)Find the left most and right most derivation corresponding to the tree.
/
:
tp
ht
http://csetube.weebly.com/
j k
/
k
.t
e
b
tu
e
s
/c
/
:
tp
n n 2
2.a)Show that the language {0 1 2 /n>=1} is not a Context free language. (6)
b)Convert the grammar S->AB, A->BS/b, B->SA/a into Greibach NormalForm. (10)
3.a)Construct a equivalent grammar G in CNF for the grammar G1 where G1
=({S,A,B},{a,b},{S->bA/aB,A->bAA/aS/a, B->aBB/bS/b},S) (12)
b)Obtain the Chomsky Normal Form equivalent to the grammarS->bA/aB, A>bAA/aS/a, B->aBB/bS/b. (4)
4.a)Begin with the grammar
S->0A0/1B1/BBA->CB->S/AC->S/
and simplify using the safe order Eliminate -Productions Eliminate unit production
Eliminate useless symbols Put the (resultant) grammar in Chomsky Normal
Form (10)
b)Let G=(V,T,P,S) be a CFG. Show that if S=, then there is a derivation tree in a
grammar G with yield . (6)
5.a)Let G be the grammar S->aS/aSbS/ . Prove that L(G)={x/each prefix of x has atleast
as many a's as b's} (6)
b)Explain the Construction of an equivalent grammar in CNF for thegrammar
G=({S,A,B}{a,b},P,S)
where P={S->bA|aB, A->bAA|aS|a, B->aBB|bS|b} (10)
6.a)Find a Context free grammar with no useless symbol equivalent to
S->AB/CA, B->BC/ABA->a, C->aB/b. (6)
ht
http://csetube.weebly.com/
n n
8.a)Is L={a b c /n>=1} a context free language? Justify Your answer. (8)
b)Prove that for every context free language L without there exists an equivalent
grammar in Greibach Normal Form. (8)
9.State and Prove pumping lemma for Context free languages. (16)
n
n n
10.a)State Pumping Lemma for context free language. Show that (0 1 2 /n>=1}
is not a Context free language. (6)
i
j i j
b)State Pumping lemma for context free language show that language {a b c d /i>=1,
and j>=1} is not context-free. (6)
11.a)Design a Turing Machine M to implement the function multiplication using
the subroutine copy. (12)
b)Explain how a Turing Machine with the multiple tracks of the tape can be used to
determine the given number is prime or not. (4)
12.a)Design a Turing Machine to compute f(m+n)=m+n, V m,n>=0 and simulate their
action on the input 0100. (10)
b)Describe the following Turing machine and their working. Are they more
powerful than the Basic Turing Machine? Multi-tape Turing Machine Multi-Dimensional
Turing Machine
(3) Non-Deterministic Turing Machine. (6)
13.a) Define Turing machine for computing f(m,n)=m-n ( proper subtraction).
(10)
b)Explain how the multiple tracks in a Turing Machine can be used for testing given
positive integer is a prime or not. (6)
14.a)Explain in detail: The Turing Machine as a Computer of integer functions. (8)
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
(12)
16.Prove that the language L is recognized by a Turing Machine with a two way infinite
tape if and only if it is recognized by a Turing Machine with a one way infinite tape.
(16)
17.For each of the following Context free languages L, find the smallest pumping length
that will satisfy the statement of the Context free pumping lemma. In each case, Your
answer should include a number(the minimum pumping length), a detailed
explanation of why that the number is indeed a valid pumping length for the given
language L, and a detailed explanation of why no smaller number qualifies as a valid
pumping length for that particular language L.
n
http://csetube.weebly.com/
18.Design a Turing Machine M that decides A={0 /n>0 and k=2 } the language
consisting of all strings of 0s whose length is a power of 2. (16)
19.a)Give a High level implementation description with a neat sketch of a Turing
Machine M that performs the following computation.M=on input w: writes a copy
of w on the tape immediately after w,leaving the string w#w on the tape.Assume
that the input string initially appears at the left most end of the tape and that the
input alphabet does not contain the blank character : The end of the input string is
therefore determined by the location of the first blank cell on the input tape. The
symbol # is assumed to be in the tape alphabet,and the input alphabet is {a,b}.
(12)
b)Demonstrate the working of your TM with an example. (4)
n
n n
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
(16)
(16)
http://csetube.weebly.com/
11.a)Show that the following language is not decidable. L={<M>| M is a TM that accepts
the string aaab}. (8)
b)Discuss the properties of Recursive and Recursive enumerable languages. (8)
12.a)Define Post correspondence problem with an example. (8)
n
b)Prove that the function f(n)=2 does not grow at a polynomial rate, in other words, it
p
15.a)Does PCP with two lists x=(b,b ab ,ba) and y=(b ,ba , a)have a solution?. (6)
b)Show that the characteristic function of the set of all even numbers is recursive.
(6) c)Let ={0,1}.Let A and B be the lists of three strings each,defined as List A
List B
i Wi Xi1 1 1112 10111 10310 0
Does this PCP have a solution? (4)
16.a)Show that it is undecidable for arbitrary CFGs G1 and G2 whether L(G1)L(G2)Is
a CFL. (8)
b)Show that finding whether the given CFG is ambiguous or not is undecidable by
reduction technique. (8)
17.Find whether the following languages are recursive or recursively
enumerable.
(i) Union of two recursive languages. (4)
(ii) Union of two recursively enumerable languages. (4)
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
(qi, 0)
(qi, 1)
(qi, B)
Q1
(q2,1,R)
(q2, 0,L)
(q2, 1,L)
q2
q3
(q3, 0,L)
(q1, 0,R)
(q2, 0,R)
http://csetube.weebly.com/
/
k
.t
e
b
tu
e
s
/c
/
:
tp
ht
http://csetube.weebly.com/