Flat 10 PDF
Flat 10 PDF
Flat 10 PDF
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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?
Є- losu e de otes a set of all e ti es p su h that the e is a path f o to p la eled Є.
Example :
Є
q0 q1
Є-closure(q0)={q0,q1}
9.What is a : (a) String (b) Regular language
A st i g is a epted a Fi ite Auto ato M= Q,Σ, . ,F if , =p, fo so e p i 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 { | , is i F}. A la guage is egula if it is
accepted by some finite automaton.
10.Define Induction principle.
• Basis step:
P(1) is true.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
• Assu e p k is t ue.
• P K+ is sho to e t ue.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
The .e o sists of t o pa ts: L = + a o of s a d s
=(00+11)(0+1)*
L =a o of s a d s +
=(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 whi h a epts all st i gs ith atleast t o s o e the
set Σ={c,b}
(b+c)* c (b+c)* c (b+c)*
6.Construct a r.e for the language over the set Σ={a, } i hi h total u e of a s a e di isi le
by 3
( b* a b* a b* a b*)*
7.what is: (i) (0+1)* (ii)(01)* (iii)(0+1) (iv)(0+1)+
+ *= { Є , , , , , , , ,…………………}
A o i atio s of s a d s.
*={Є , , , ,…………………………………..}
All combinations with the pattern 01. (0+1)= 0 or 1,No other possibilities.
(0+1)+= { , , , , , ,………………………………….}
8.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)*
9.Reg exp for:
(i)All strings over {0,1} with the su st i g
ii All st i gs egi i g ith a d e di g ith a
iii Set of all st i gs o e {a, } ith o se uti e s.
i Set of all st i gs that e d ith a d has o su st i g
(i)(0+1)* 0101(0+1)* (ii)11(1+a+b)* ab
(iii)(a+b)* bbb (a+b)* (iv)(1+01)* (10+11)* 1
10. What are the applications of Regular expressions and Finite automata
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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
ide tifie .The lette is{A,B,C,………..Z,a, , ….z} a d digit is
{ , ,…9}.Thus eg e p ide tifies toke i a la guage.
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 te t edito s a eg e p is o e ted to a NFA ith Є –transitions, this NFA can be then
simulated directly.
11.Reg exp for the language that a epts all st i gs i hi h a appea s t ipled o e the
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 o sta t .
(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.
You a hie e a o t adi tio to pu pi g le a that the e e ists a i
Such that uviw 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.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
.Reg e p fo the la guage su h that e e st i g ill ha e atleast o e a follo ed atleast
o e .
R=a+b+
.W ite the e p fo the la guage sta ti g ith a d has o o se uti e s
reg exp=(a+ab)*
16.What is the relationship between FA and regular expression.
Regular
Expression
Deterministic
Finite
NFA ith Є-
NFA without
Є -moves
UNIT III CONTEXT FREE GRAMMAR AND LANGUAGES 2 MARKS QUESTION AND ANSWERS
1. What are the applications of Context free languages?
Context free languages are used in:
Defining programming languages.
Formalizing the notion of parsing. Translation of programming languages. String processing
applications.
2. What are the uses of Context free grammars?
Construction of compilers.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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 finite set of
productions each is of the form A->α he e A is a a ia le a d α is a st i g of s ols f o VU
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 st i g of te i als a d a ia les α is alled a se te tial fo if:
*
S => α , he e S is the sta t s ol of the g a a.
6. What is the language generated by the grammar G=(V,T,P,S) where
P={S->aSb, S->ab}?
S=> aS =>aaS =>…………………………..=>a
Thus the la guage L G ={a | >= }.The la guage has st i gs ith e ual u e of a s a d
s.
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 p odu tio of P a d
αa d a ea st i gs i VUT * the α A => αβ .
G
(b) A tree is a parse \ derivation tree for G if:
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
i E e e te has a la el hi h is a s ol of VU TU{Є}.
(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.
i If has a la el A a d e ti es , ,….. k a e the so s of the e te i o de f o left
ith la els X ,X ,………..Xk espe ti el the A→ X X …..Xk ust e i P. If e te has la el
Є ,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={anbmambn, 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.Consider the grammarP={S->aS | aSbS | Є } is ambiguous by constructing: (a) two parse trees
(b) two leftmost derivation (c) rightmost derivation
(a)
Consider a string aab :
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
=>aab =>aab
( c )(i)S=>aS (ii) S=>aSbS
=>aaSbS =>aSb
=>aaSb =>aaSbS
=>aab =>aaSb
=>aab
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.
**
As ol X is useful if S => αXβ =>
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
12. Construct CFG without Є production from : S →a | Ab | aBa , A →b | Є , B →b | A.
S->a
S->Ab
S->aBa
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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.
14. 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
There are no productions of the form A->B where A and B are variables.
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 | Є
16.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={ 0n 1 m | m not equal to n, and n,m >=1}
17.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)
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->Є } hi h is i pali d o e.
19. Differentiate sentences Vs sentential forms
A sentence is a string of terminal symbols.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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.
20. 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)
21.What is Backus-Naur Form(BNF)?
Computer scientists describes the programming languages by a notation called
Backus- Naur Form. This is a context free grammar notation with minor changes in
format and some shorthand.
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
Thus L(G)= { anban ,where n>=1 }
23.Find L(G) where G= ( {S} ,{0,1}, {S->0S1 ,S->Є },S )
S->Є , Є is i L G
S-> S => Є =>
S->0S1=>0 0S11=>0011
Thus L(G)= { 0n1n | n>=0}
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.
25.Define Pushdown Automata.
A pushdo Auto ata M is a s ste Q, Σ, Ґ , , , Z ,F he e
Q is a finite set of states.
Σ is a alpha et alled the i put alpha et.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
Ґ is a alpha et alled sta k alpha et. i Q is alled i itial state.
Zo i Ґ is sta t s ol i stack. F is the set of final states.
is a appi g f o Q X Σ U {Є} X Ґ to fi ite su sets of Q X Ґ *.
26.Compare NFA and PDA.
NFA PDA
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
*
{ w | (q0,w ,Z0) |---- p, Є, Є fo so e p i Q}.
29.Is it true that the language accepted by a PDA by empty stack and final states are different
languages.
No, e ause the la guages a epted PDA s fi al state a e e a tl the la guages a epted
PDA s e pt sta k.
30. Define Deterministic PDA.
A PDA M = Q, Σ ,Ґ , , ,Z ,F is dete ministic if:
Fo ea h i Q a d Z i Ґ , he e e ,Є,Z is o e pt ,the
,a,Z is e pt fo all a i Σ.
Fo o i Q , Z i Ґ , a d a i Σ U { Є} does ,a,Z o tai s o e tha o e ele e t.
(Eg): The PDA accepting {wcwR | w in ( 0+1 ) * }.
31.Define Instantaneous description(ID) in PDA.
ID des i e the o figu atio of a PDA at a gi e i sta t.ID is a t iple su h as , , , he e
is a state , is a st i g of i put s ols a d is a st i g of sta k
s ols. If M = Q, Σ ,Ґ , , ,Z ,F ) is a PDA we say that
,a ,Zα |----- p, , βα if ,a,Z o tai s p, β .
M
a a e Є o a i put s ol.
E a ple: , BG is i , , G tells that , , GGR |---- ( q1, 11,BGGR).
32.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.
33.When is a string accepted by a PDA?
The input string is accepted by the PDA if: The final state is reached .
The stack is empty.
34. Give examples of languages handled by PDA.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
(1) L={ anbn | 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, }* } , to ha dle this la guage e eed u li ited ou ti g apa ilit .
35.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.
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.
UNIT IV PROPERTIES OF CONTEXT FREE LANGUAGES AND PUSH DOWN AUOTOMATA 2 MARKS
QUESTION AND ANSWERS
1. State the equivalence of PDA and CFL.
If L is a context free language, then there exists a PDA M such that
L=N(M).
If L is N(M) for some PDA m, then L is a context free language.
2. 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.
Closu e p ope ties of CFL s a e used to p o e that e tai la guages a e ot o te t f ee.
3. 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.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
4. 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.
L2= { aibjcidj | i>=1 and J>=1 } is not a CFL.
5. Give an example of Deterministic CFL.
The language L={anbn : n>=0} is a deterministic CFL
6. What are the properties of CFL?
Let G=(V,T,P,S) be a CFG
The fa out of G , Φ G is la gest u e of s ols o 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.
7. Compare NPDA and DPDA.
NPDA DPDA
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
11.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.
12.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.
13. Define Turing machine.
A Tu i g a hi e is de oted as M= Q, Σ, Ґ , , , B,F Q is a fi ite set of states.
Σ is set of i/p s ols , ot i ludi g B.
Ґ is the fi ite set of tape s ols. i Q is alled sta t state.
B in Ґ is la k s ol.
F is the set of final states.
is a appi g f o Q X Ґ to Q X Ґ X {L,R}.
14.Define Instantaneous description of TM.
The ID of a TM M is de oted as α α . He e is the u e t state of M is i Q;
α α is the st i g i Ґ * 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.
15. What are the applications of TM?
TM can be used as:
Recognizers of languages.
Computers of functions on non negative integers. Generating devices.
16.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
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
the FA does t have such a tape head.
17.Define a move in TM.
Let X X …X i- Xi…X e a ID.
The left o e is: if , Xi = p, Y,L ,if i> the
X X …X i- Xi…X |---- X X … X i-2 p X i- Y X i+ …X .
M
The ight o e is if , Xi = p, Y,R ,if i> the
X1 X …X i- Xi…X |---- X X … X i- Y p X i+ …X .
M
18. What is the language accepted by TM?
The la guage a epted M is L M , is the set of o ds i Σ * that ause M to e te a fi al
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:
{ | i Σ*a d |--- α p α fo so e p i F a d α ,α i Ґ * }.
19. What are the various representation of TM?
We can describe TM using: Instantaneous description.
Transition table. Transition diagram.
20. 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.
21. What are the techniques for Turing machine construction?
• Sto age i fi ite o t ol.
• Multiple t a ks.
• Che ki g off s ols.
• Shifti g o e
• Su outi es.
22. What is the storage in FC?
The finite control(FC) stores a limited amount of information. The state of the
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
Finite control represents the state and the second element represent a symbol scanned.
23. 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.
24.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.
25.Differentiate PDA and TM.
PDA TM
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
UNIT V TURING MACHINE-2 MARKS QUESTION AND ANSWERS
1.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 i sta e is es o o .
(eg) of undecidable problems are (1)Halting problem of the TM.
2.Give examples of decidable problems.
1. Given a DFSM M and string w, does M accept w?
2. Gi e a DFSM M is L M = Φ ?
3. Given two DFSMs M1 and M2 is L(M1)= L(M2) ?
4. Gi e a egula e p essio α a d a st i g ,does α ge e ate ?
5. Given a NFSM M and string w ,does M accept w?
3. Give examples of recursive languages?
i. The la guage L defi ed as L= { M , : M is a DFSM that a epts } is e u si e.
ii. L defi ed as { M U M : DFSMs M and M2 and L(M1)
=L(M2) } is recursive.
4. Differentiate recursive and recursively enumerable languages.
1. A language is said to be
recursive if and only if there exists 1. A language is said to be r.e if
a membership algorithm for it. there exists a TM that accepts it.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
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:
I put to U: The e odi g M of a T M a d e odi g of a st i g . Beha io : U halts o
i put M if a d o l if M halts o i put .
6. 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.
7. What properties of recursive enumerable seta are not decidable?
Emptiness
Finiteness
Regularity
Context-freedom.
8.Define Lℓ .When is ℓ a trivial property?
Lℓ is defi ed as the set { <M> | L M is i ℓ. }
ℓ is a t i ial p ope t if ℓ is e pt o it o sists of all .e la guages.
9. 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 }.
10.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.
11. What properties of r.e sets are recursively enumerable?
L≠Φ
L contains at least 10 members.
is i L fo so e fi ed . L ∩ Lu ≠ Φ
12. What properties of r.e sets are not r.e?
L=Φ
L = Σ *.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
L is recursive
L is not recursive. L is singleton.
L is a regular set. L - Lu ≠ Φ
13.What are the conditions for Lℓ to be r.e?
Lℓ is e u si el e u e a le iff ℓ satisfies the follo i g p ope ties:
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET
does the e e ists a se ue e of i tege s i ,i ,…i su h that i i ….. i = i i … i?
24 . 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.
25. What are the concepts used in UTMs?
Stored program computers.
Interpretive Implementation of Programming languages.
Computability.
26.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 CFL s.
The recursive sets include languages accepted by at least one TM that halts on all inputs.
27. 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.
PREPARED BY M.JANARDHAN,ASSOC.PROFESSOR,GPCET