Theory of Computation
Theory of Computation
Theory of Computation
THEORY OF COMPUTATION(CS1303)
Third Year CSE( S5 CSE )
2 marks Questions and Answers
Є
q0 q1
Є-closure(q0)={q0,q1}
14.Construct a r.e for the language which accepts all strings with atleast two c’s over
the set Σ={c,b}
(b+c)* c (b+c)* c (b+c)*
15.Construct a r.e for the language over the set Σ={a,b} in which total number of
a’s are divisible by 3
( b* a b* a b* a b*)*
(0+1)+= {0,1,01,10,1000,0101,………………………………….}
(iv)Set of all strings that end with ‘1’and 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
19. 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.
20.Reg exp for the language that accepts all strings in which ‘a’ appears tripled over
the set Σ ={a}
reg exp=(aaa)*
23.Reg exp for the language such that every string will have atleast one ‘a’ followed
by atleast one ‘b’.
R=a+b+
Theory of Computation 5
24.Write the exp for the language starting with and has no consecutive b’s
reg exp=(a+ab)*
Regular
Expression
(a)
11. Find CFG with no useless symbols equivalent to : S→AB | CA , B→BC | AB, A→a ,
C→aB | 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
S->a
S->Ab
S->aBa
A->b A->Є B->b B->A are the given set of production.
Theory of Computation 8
13. What are the three ways to simplify a context free grammar?
By removing the useless symbols from the set of productions.
By eliminating the empty productions.
By eliminating the unit productions.
15. Find the grammar for the language L={a2n bc ,where n>1 }
let G=( {S,A,B}, {a,b,c} ,P , {S} ) where P:
S->Abc
A->aaA | Є
18. 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,
Theory of Computation 9
S-> a,
S->b,
S->Є } which is in palindrome.
21. (a)CFL are not closed under intersection and complementation –True.
(b)A regular grammar generates an empty string –True.
(c) A regular language is also context free but not reverse–True.
(d)A regular language can be generated by two or more different grammar –True.
(e) Finite State machine(FSM) can recognize only regular grammar-True.
23. Let G= ( {S,C} ,{a,b},P,S) where P consists of S->aCa , C->aCa |b. Find L(G).
S-> aCa => aba
S->aCa=> a aCa a=>aabaa
S->aCa=> a aCa a=> a a aCa a a =>aaabaaa
25.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.
Theory of Computation 10
4.What are the different types of language acceptances by a PDA and define them.
For a PDA M=(Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) we define :
Language accepted by final state L(M) as:
*
{ w | (q0 , w , Z0 ) |--- ( p, Є , γ ) for some p in F and γ in Ґ * }.
Language accepted by empty / null stack N(M) is:
*
{ w | (q0,w ,Z0) |----( p, Є, Є ) for some p in Q}.
5.Is it true that the language accepted by a PDA by empty stack and final states are
different languages.
Theory of Computation 11
No, because the languages accepted by PDA ‘s by final state are exactly the
languages accepted by PDA’s by empty stack.
12. 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.
13. State the equivalence of PDA and CFL.
Theory of Computation 12
NPDA DPDA
Theory of Computation 13
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.
This is implemented by using an extra track on the tape with symbols Blank or √.
PDA TM
1. PDA uses a stack for 1. TM uses a tape that is infinite .
storage.
2.The language accepted by 2. Tm recognizes recursively
PDA is CFL. enumerable languages.
24. 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.
UNIT V Undecidability
L is a regular set.
L - Lu ≠ Φ
18. State a single tape TM started on blank tape scans any cell four or more
times is decidable?
If the TM never scans any cell four or more times , then every crossing
sequence is of length at most three. There is a finite number of distinct crossing
sequence of length 3 or less. Thus either TM stays within a fixed bounded number
of tape cells or some crossing sequence repeats.
on input B “?
Given a TM M means given enough information to trace the processing of
a fixed string for a certain fixed number of moves. So the given problem is
decidable.
16 marks
1.Prove that ,if L is accepted by an NFA with є-transitions, then L is accepted by an NFA
without є-transitions.
Refer page no:26,Theorem 2.2
2.Prove that for every regular expression there exist an NFA with є-transitions.
Refer page no:30,Theorem 2.3
3.Construct the NFA with є-transitions from the given regular expression.
If the regular expression is in the form of ab then NFA is
a b
є a є
є b є
є a є
Find the equation of the final state with only the input symbols.
Made the simplifications if possible
The equation obtained is the required regular expression.
12. Prove that if L is L(M2) for some PDA M2,then L is N(M1) for some PDA M1.
Refer page no:114,Theorem 5.1
13.If L is a context-free language, then prove that there exists a PDA M such that
L=N(M).
Refer page no: 116,Theorem 5.3
20. Explain how a TM can be used to determine the given number is prime or not?
It takes a binary input greater than 2,written on the first track, and determines
whether it is a prime. The input is surrounded by the symbol $ on the first track.
Theory of Computation 24
To test if the input is a prime, the TM first writes the number 2 in binary on the
second track and copies the first track on to the third. Then the second track is subtracted
as many times as possible, from the third track effectively dividing the third track by the
second and leaving the remainder.
If the remainder is zero, the number on the first track is not a prime.If the
remainder is non zero,the number on the second track is increased by one.If the second
track equals the first,the number on the first track is the prime.If the second is less than
first,the whole operation is repeated for the new number on the second track.
24.Prove that if a language L and its complement are both recursively enumerable, then L
is recursive.
Refer page no: 180,Theorem 8.3
.
BOOK REFERED
1.Introduction to automata theory,languages,and computation