CS1303 Theory of Computation
CS1303 Theory of Computation
CS1303 Theory of Computation
SUBJECT CODE:CS1303
THEORY OF COMPUTATION
QUESTIONS-ANSWERS
Prepared by
S.GANAPATHY
Lecturer,
Department of Computer Science and Engineering,
Theory of computation 2
UNIT I
AUTOMATA
PART - A
q0 q1
Є-closure(q0)={q0,q1}
3.
9.What is a : (a) String (b) Regular language W
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 at
symbols of x leads from the start state to accepting state. is
The language accepted by M is L(M) is the set {x | δ(q0,x) is in F}. A language A
is regular if it is accepted by some finite automaton. de
’s
10.Define Induction principle.
T
• Basis step:
P(1) is true. eo
• Assume p(k) is true. em
• P(K+1) is shown to be true. ?
UNIT II
REGULAR EXPRESSIONS AND LANGUAGES
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
example:0+={0,00,000,……………………………………..}
4
Arden’s theorem helps in checking the equivalence of two regular expressions.
Let P and Q be the two regular expressions over the input alphabet Σ. The regular
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 0’s and 1’s)
=(00+11)(0+1)*
L2=(any no of 0’s and 1’s)(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 which accepts all strings with atleast two c’s over
the set Σ={c,b}
(b+c)* c (b+c)* c (b+c)*
6.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,………………………………….}
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 over
the set Σ ={a}
reg exp=(aaa)*
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 b’s
reg exp=(a+ab)*
Regular
Expression
Deterministic
NFA with Є-
Finite moves
Automata
NFA without
Є -moves
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
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
Theory of computation 9
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
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 | Є
S->0S1=>00S11=>000S111=>0000A111=>00000111
Thus L={ 0n 1m | m not equal to n, and n,m >=1}
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,
S-> a,
S->b,
S->Є } which is in palindrome.
22. 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
24.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.
28.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:
*
Theory of computation 12
29.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 PDA’s by empty stack.
36. 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.
NPDA DPDA
1. NPDA is the standard PDA 1. The standard PDA in
used in automata theory. practical situation is DPDA.
2. Every PDA is NPDA unless 2. The PDA is deterministic in
otherwise specified. the sense ,that at most one
move is possible from any ID.
B in Ґ is blank symbol.
F is the set of final states.
δ is a mapping from Q X Ґ to Q X Ґ X {L,R}.
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.
UNIT V Undecidability
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.
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.If L is accepted by an NFA with ∑-transition then show that L is accepted by an NFA
without ∑-transition
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 є
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.
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
26. Prove that a language L is accepted by some ε-NFA if and only if L is accepted by
some DFA.
s | i 0 1
p {p,q} p
q r r
r s -
s s s
28. Consider the following ε-NFA.Compute the ε-closure of each state and find it’s
equivalent DFA
s| i ε a b c
p {q} {p} ф ф
q {r} ф {q} ф
r ф ф ф {r}
29. Prove that a language L is accepted by some DFA iff L is accepted by some NFA.
Theory of computation 25
30. Prove that if L=N(PN) for some PDA PN=(Q, Σ,Γ,δN,q0,Z0),then there is a PDA PF
such that L=L(PF).
BOOK REFERED
1.Introduction to automata theory,languages,and computation