SUB: AUTOMATA THEORY AND COMPUTABILITY
Sub Code: 17CS54
Possible Questions with Answers
Prepared by Sagarika Behera, Savitha S
Dept of CSE, CMRIT, Bangalore
MODULE 1
Q.1a. What is Automata Theory? Why is it important to study automata theory?
Ans: Automata theory is the study of abstract computing devices or machines. FAs are a useful
model for many kinds of h/w and s/w.
Applications:
1. S/W for designing and checking the behaviour of digital circuits
2. Lexical Analyzer
3. Pattern matching
4. Communication protocols
Q.1.b. Distinguish between DFA, NFA and Ɛ- NFA.
DFA NFA Ɛ- NFA
1.Only one transition on each Zero, one or more transitions Zero, one or more transitions on
same
Input on same input input
2.No Ɛ-transitions No Ɛ-transitions Ɛ-transitions is there.
3.δ:QX∑→Q δ:QX∑→2Q δ:QX∑U{Ɛ)→2Q
Q.2. For = {a, b} construct dfa’s that accepts the sets consisting of
a. all strings with exactly one a.
a,b
b b
q0 a q1 q2
a
b. all strings with at least one a.
b a, b
q0 a q1
c. all strings with no more than three a’s.
b
b b b
a,b
a a a a
q0 q1 q2 q3 q4+
d. L = {w1abw2 : w1 {a, b}*, w2 {a, b}*}
This is any string containing ab somewhere in it.
b a a,b
a b
Find dfa’s for the following languages on = {a, b}
e. L = {w : |w| mod 3 = 0}
a,b
0 1
a,b a,b
2
f. L = {w : |w| mod 5 0}
0 a,b 1 a,b
2
a,b
4 3 a,b
a,b
g. L = {w : na(w) mod 3 > 1}
b b
a
0 1
a
a
2
b
h. L = {w : na(w) mod 3 > nb(w) mod 3}
a a
00 10 20
b b a b
a a
b 01 11 21 b
b
b b a b
a a
02 12
22
Q.3. Design a DFA over the alphabet {0,1} which accepts the set of all strings beginning with a 1 when
interpreted as a binary integer is a multiple of 5.
Ans:
DFA is given in the following transition table:
0 1
Qe(Error state) Q1
→A(start state)
Q0 Q1
*Q0(Final state)
Q2 Q3
Q1
Q4 Q0
Q2
Q1 Q2
Q3
Q3 Q4
Q4
Q.4. Construct a DFA equivalent to the NFA given in Table 1
δ 0 1
p p, q p
Table no.
q r r
1
r s -
*s s s
Equivalent DFA is:
δ 0 1
{p} {p, q} {p}
p, q {p,q,r} {p,r}
{p,q,r} {p,q,r,s} {p,r}
{p,r} {p,q,s} {p}
*{p,q,r,s} {p,q,r,s} {p,r,s}
*{p,q,s} {p,q,r,s} {p,r,s}
*{p,r,s} {p,q,s} {p,s}
*{p,s} {p,q,s} {p,s}
Q.5. Consider the following ε-NFA. Convert the automata to a DFA. Give the set of all strings of length 3
or less accepted by the automaton.
ᵟ ε a b
->p {r} {q} {p,r}
q Φ {p} Φ
*r {p,q} {r} {p}
-------------Find the ECLOSE of each state.
ECLOSE(p)= {p,q,r} ECLOSE(q)= {q} ECLOSE(r)= {p,q,r}
Equivalent DFA is δ({p,q,r},a)={p,q,r} δ({p,q,r},b)={p,q,r}
Set of strings of length 3 or less are: {Ɛ,a,b,bb,ba,baa,bbb,aab…}
Q.6. Consider the below 𝜖 − 𝑁𝐹𝐴:
𝜖 a b
→p {r} {q} {p,r}
q 𝜙 {p} 𝜙
r {p,q} {r} {s}
* s {p] {p} {p}
i. Compute the 𝜖-closure of each state.
Ans:
ECLOSE(p)={p,q,r} ECLOSE(q)={q} ECLOSE(r)={p,q,r} ECLOSE(s)={p,q,r,s}
ii. Convert the above 𝜖 − 𝑁𝐹𝐴 to an equivalent DFA.
DFA Transition Table:
a b
→{p,q,r} {p,q,r} {p,q,r,s}
*{p,q,r,s} {p,q,r} {p,q,r,s}
Q.7. Define the following terms with examples.
(i)Alphabet (ii) Concatenation (iii) Languages (iv) Powers of alphabet
(v) String
MODULE-2
1. Define Regular Expression. Write the regular expression for the following languages:
Ans:
A regular expression is another medium for concise and precise specification of regular languages.
It specifies the same class of languages which can be recognized by FA.
i. L = { ambn | m≤5 and n≥2 }
r ={Ɛ+a+aa+aaa+aaaa+aaaaa}bb(b)*
ii. Strings of 0’s and 1’s having no two consecutive 1’s.
r = (0 + 10)*{Ɛ+1}
iii. Strings of a’s and b’s whose 3rd symbol from right is an ‘a’.
r = (a+b)*a(a+b)(a+b)
iv. L = { w | w is in {a,b}* and |w|mod3=0 }
r =((a+b)3)*
2. Obtain a regular expression from the following DFA using state elimination method.
Ans:
D is the error state. Remove D.
B is the intermediate state. Remove B.
Now R1 = ( 0+11)*10(1)*
Now remove C , keep only A
R2=(0+11)*
Final regular expression is R= R1+R2 = ( 0+11)*10(1)* + (0+11)* = ( 0+11)*{10(1)*+Ɛ}
Module-3
Q.1. What is context free grammar?
Ans: A context-free grammar (CFG) is a set of recursive rewriting rules (or productions)
used
to generate patterns of strings. A CFG is defined by 4-tuples G=(V,T,P,S) or G=(V,Σ,R,S)
Where V is set of Variables or Non terminals
T is a set of terminals
P is a set of productions or grammar rules
And S is the start symbol
Example: G=({S,A},{a,b},P,{S})
Where P is defined as S → aSb, S → aAb, A → bAc | bc
Q.2. What is CFL?
Ans: A context-free language (CFL) is a language generated by a context-free grammar (CFG).
The set of all strings that can be generated by a grammar G is called language of G and is denoted
by L(G).It is
defined as L(G)={w|S * w}
Where w is a string containing a set of terminals derived from start symbol “S” .
Q.3. what is derivation and derivation tree?
Ans: U derives v means, U is a non-terminal and v is a string containing
terminals.
A derivation of v is a sequence of steps that goes to v from U.
There are two types of derivation.
1. Leftmost derivation (LMD): In this derivation at each step the leftmost
variable is replaced by it’s productions.
2. Rightmost derivation (RMD): In this derivation at each step the rightmost
variable is replaced by it’s productions.
Page | 2
Derivation Tree or Parse Tree:
In a derivation tree, the root is the start variable, all internal nodes are labeled
with variables, while all leaves are labeled with terminals. The children of an
internal node are labeled from left to right with the right-hand side of the
production used.
Root vertex − Must be labeled by the start symbol.
Vertex − Labeled by a non-terminal symbol.
Leaves − Labeled by a terminal symbol or ε.
If S → x1x2 …… xn is a production rule in a CFG, then the parse tree /
derivation tree will be as follows –
s
...
X1 X2 Xn
Q.4. What do you mean by yield of a parse tree?
Ans: The derivation or the yield of a parse tree is the final string obtained by
concatenating the labels of the leaves of the tree from left to right, ignoring the
Nulls. However, if all the leaves are Null, derivation is Null.
Q.5.What is ambiguous grammar?
Ans: A CFG is said to be ambiguous if there exist a string which has more than
one LMD.
Q.6. What do you mean by Inherently ambiguous?
Ans: There exist context-free languages for which no unambiguous grammar
exists. Such languages are called as inherently ambiguous.
Example: L={aibjck:i,j,k ≥0, i=j or j=k}
Page | 3
CFG for the above language is:
S → S1 | S2
S1→ S1 c | A
A→aAb|Ɛ
S2→ aS2 | B
B→ b B c | Ɛ
Q.7. What is sentence and sentential form?
Ans: When we are deriving a string from the start symbol , the strings of intermediate
steps is a combination of terminals and nonterminals, which is known as sentential
form. The final string which contains only terminals is known as sentence.
There are two types of sentential form.
1. Left sentential form
2. Right sentential form
Example: E E+E
id+E /*Left sentential form*/
id+id /*Sentence*/
E E+E
E+id /*Right sentential form*/
id+id /*Sentence*/
Q.8. What is Chomsky Normal Form(CNF)?
Ans: A context-free grammar G is said to be in Chomsky normal form (first described by Noam
Chomsky) if all of its production rules are of the form
A → BC, or
A → a,
where A, B, and C are nonterminal symbols, a is a terminal symbol.
Page | 4
Q.9. What is Greibach Normal Form(GNF)?
Ans: A CFG G = (V,T,R,S) or G = (V,T,P,S) is said to be in GNF if every production is of
the form A → aα, where a ∈ T and α ∈ V ∗, i.e., α is a string of zero or more variables.
Q.10. What is NULL production, Unit production and Useless symbols?
Ans:
NULL production: In a CFG, a non-terminal symbol ‘A’ is a nullable variable
if there is a production A → ε or there is a derivation that starts at A and
finally ends up with
Ex: A → .......… → ε
Unit Production: Any production rule in the form A → B where A, B ∈ Nonterminal
is called unit production.
Useless Symbols:
Those symbols that do not participate in derivation of any string is called as the useless symbols.
A symbol X is useful if:
1. If X is generating, i.e., X =>* w, where w ϵ L(G) and w in Vt*, this means that the string leads to a
string of terminal symbols.
2. If X is reachable If there is a derivation S =>* αXβ =>* w, w ϵ L(G), for same α and β, then X is
said to be reachable.
Q.11. What is Push Down Automata? Explain the working principles
of a PDA with block diagram.
Ans: Basic Structure of PDA
A pushdown automaton is a way to implement a context-free grammar in a
similar way we design DFA for a regular grammar. A DFA can remember a
finite amount of information, but a PDA can remember an infinite amount of
information.
Basically a pushdown automaton is −
"Finite state machine" + "a stack"
Page | 5
A pushdown automaton has three components −
an input tape,
a control unit, and
a stack with infinite size.
The stack head scans the top symbol of the stack.
A stack does two operations −
Push − a new symbol is added at the top.
Pop − the top symbol is read and removed.
A pushdown automaton (PDA) differs from a finite state machine in two ways:
1. It can use the top of the stack to decide which transition to take.
2. It can manipulate the stack as part of performing a transition.
A PDA can be formally described as a 7-tuple (Q, Σ, Γ, δ, q0, Z0, F)
where
Q is the finite number of states
Σ is input alphabet
Γ is stack symbols
δ is the transition function: Q × (Σ ∪ {ε}) × Γ → Q × Γ *
q0 is the initial state (q0 ∈ Q)
Z0 is the initial stack top symbol (Z0 ∈ Γ)
F is a set of accepting states (F ∈ Q)
Page | 6
Q.12. What is Instantaneous Description(ID) of a PDA?
Ans: The instantaneous description (ID) of a PDA is represented by a triplet
(q, w, s) where
q is the state
w is unconsumed input
s is the stack contents
The process of transition is denoted by the turnstile symbol "⊢". Example:
(p, aw, b) ⊢ (q, w, αb)
Q.13. Define the language accepted by PDA.
Ans: There are two different ways to define PDA acceptability.
1.Final State Acceptability:
In final state acceptability, a PDA accepts a string when, after reading the entire
string, the PDA is in a final state. From the starting state, we can make moves
that end up in a final state with any stack values. The stack values are
irrelevant as long as we end up in a final state.
For a PDA (Q, Σ, Γ, δ, q0, Z0, F), the language accepted by the set of final
states F is −
L(PDA) = {w | (q0, w, Z0) ⊢* (q, ε, x), q ∈ F}
for any input stack string x.
2.Empty Stack Acceptability:
Here a PDA accepts a string when, after reading the entire string, the PDA
has emptied its stack.
For a PDA (Q, Σ, Γ, δ, q0, Z0, F), the language accepted by the empty stack
is −
L(PDA) = {w | (q0, w, Z0) ⊢* (q, ε, ε), q ∈ Q}
Page | 7
Q.14. What is Deterministic PDA(DPDA) and Nondeterministic
PDA(NPDA) ?
Ans: A PDA P= (Q, Σ, Γ, δ, q0, Z0, F) to be deterministic iff the following conditions
are met.
1. δ (q,a,X) has at most one member for any q in Q, a in Σ or a= ε and X
in Γ.
2. If δ (q,a,X) ≠ Փ, then δ (q, ε,X) =Փ
Otherwise it is nondeterministic.
Deterministic pushdown automata can recognize all deterministic context-free languages while
nondeterministic ones can recognize all context-free languages.
Module-4
Q.1. State and prove pumping lemma for Context Free Language (CFL). Show that
L= {anbncn|n≥1} is not context free. [5+5]
Ans:
If L is a context-free language, there is a pumping length p such that any string w ∈ L of length ≥ p can be
written as w = uvxyz, where vy ≠ ε, |vxy| ≤ p, and for all i ≥ 0, uvixyiz ∈ L.
Let L is context free. Then, L must satisfy pumping lemma.
At first, choose a number n of the pumping lemma. Then, take z as anbncn.
Break z into uvwxy, where
|vwx| ≤ n and vx ≠ ε.
Hence vwx cannot involve both as and cs, since the last a and the first c are at least (n+1)
positions apart. There are two cases −
Case 1 − vwx has no cs. Then vx has only as and bs. Then uwy, which would have to be in L,
has n cs, but fewer than n as or bs.
Case 2 − vwx has no as.
Here contradiction occurs.
Hence, L is not a context-free language.
Q.2. Write down the closure properties of CFL. Prove that the family of CFL’s are closed
under union, concatenation and star closure. [10]
Ans:
Context-free languages are closed under −
Union
Concatenation
Kleene Star operation
Union
Let L1 and L2 be two context free languages. Then L1 ∪ L2 is also context free.
Example
Let L1 = { anbn , n > 0}. Corresponding grammar G1 will have P: S1 → aAb|ab
Let L2 = { cmdm , m ≥ 0}. Corresponding grammar G2 will have P: S2 → cBb| ε
Union of L1 and L2, L = L1 ∪ L2 = { anbn } ∪ { cmdm }
The corresponding grammar G will have the additional production S → S1 | S2
Concatenation
If L1 and L2 are context free languages, then L1L2 is also context free.
Example
Union of the languages L1 and L2, L = L1L2 = { anbncmdm }
The corresponding grammar G will have the additional production S → S1 S2
Kleene Star
If L is a context free language, then L* is also context free.
Example
Let L = { anbn , n ≥ 0}. Corresponding grammar G will have P: S → aAb| ε
Kleene Star L1 = { anbn }*
The corresponding grammar G1 will have additional productions S1 → SS1 | ε
Context-free languages are not closed under −
Intersection − If L1 and L2 are context free languages, then L1 ∩ L2 is not necessarily
context free.
Intersection with Regular Language − If L1 is a regular language and L2 is a context
free language, then L1 ∩ L2 is a context free language.
Complement − If L1 is a context free language, then L1’ may not be context free.
3.
Module -5
Q1.Write short notes on Multitape Turing machine and Non-deterministic
Turing machine.
VARIANTS OF TURING MACHINE:
There are two new models of Turing machines:
1. MULTITAPE TURING MACHINE
2. NON-DETERMINISTIC TURING MACHINE
MULTITAPE TURING MACHINE
Multi-tape Turing Machines have multiple tapes where each tape is accessed
with a separate head. Each head can move independently of the other heads.
Initially the input is on tape 1 and others are blank. At first, the first tape is
occupied by the input and the other tapes are kept blank. Next, the machine
reads consecutive symbols under its heads and the TM prints a symbol on
each tape and moves its heads.
Finite Control
... . . .
... ...
... ...
A Multi-tape Turing machine can be formally described as a 7-tuple (Q,Σ,Г,
B, δ, q0, F) where −
Q is a finite set of states
Σ is a finite set of inputs
Г is the tape alphabet
B is the blank symbol
δ is a relation on states and symbols where
δ: Q × Гk → Q × (Г× {Left, Right, Stationary})k
where there is k number of tapes
q0 is the initial state
F is the set of final states
In each move the machine M:
(i) Enters a new state
(ii) A new symbol is written in the cell under the head on each tape
(iii) Each tape head moves either to the left or right or remains
stationary.
NON-DETERMINISTIC TURING MACHINE
In a Non-Deterministic Turing Machine, for every state and symbol, there are a group of
actions the TM can have. So, here the transitions are not deterministic. The computation of a
non-deterministic Turing Machine is a tree of configurations that can be reached from the start
configuration.
An input is accepted if there is at least one node of the tree which is an accept
configuration, otherwise it is not accepted. If all branches of the computational tree halt on all
inputs, the non-deterministic Turing Machine is called a Decider and if for some input, all
branches are rejected, the input is also rejected.
A non-deterministic Turing machine can be formally defined as a 7-tuple (Q, ∑,Г, δ, q0, B, F)
where −
Q is a finite set of states
Г is the tape alphabet
∑ is the input alphabet
δ is a transition function;
δ : Q × Г → 2(Q × Г × {Left, Right})
q0 is the initial state
B is the blank symbol
F is the set of final states
Q.2. Explain the model of Linear bounded automata with diagram.
Ans: Alinear bounded automata (LBA) is a restricted form of Turing machinewith a tape of
some bounded finite length. The computation is restricted to the constant bounded area. The
input alphabet contains two special symbols which serve as left end markers and right end
markers which mean the transitions neither move to the left of the left end marker nor to the
right of the right end marker of the tape.
A linear bounded automaton can be defined as an 8-tuple (Q, ∑,Г, q0, ML, MR, δ, F) where −
Q is a finite set of states
Г is the tape alphabet
∑ is the input alphabet
q0 is the initial state
ML is the left end marker (ex: <)
MR is the right end marker(ex: >) where MR ≠ ML
δ is a transition function which maps each pair (state, tape symbol) to (state, tape symbol,
Constant ‘c’) where c can be 0 or +1 or -1
F is the set of final states
Working space
< a b >
Left end marker Input string Right end marker
A deterministic linear bounded automaton is always context-sensitive and the linear bounded
automaton with empty language is undecidable.
The language accepted by LBA is called context-sensitive language.
Example:
L={anbncn} and L={ a n! }
It is more powerful that NPDA but less powerful that TM
Q.5. (a) Post Correspondence Problem:
The Post Correspondence Problem (PCP), introduced by Emil Post in 1946, is an undecidable
decision problem. The PCP problem over an alphabet ∑ is stated as follows −
Given the following two lists, M and N of non-empty strings over ∑ −
M = (x1, x2, x3,………, xn)
N = (y1, y2, y3,………, yn)
We can say that there is a Post Correspondence Solution, if for some i1,i2,………… ik, where 1 ≤
ij ≤ n, the condition xi1 …….xik = yi1 …….yik satisfies.
Example 1
Find whether the lists
M = (abb, aa, aaa) and N = (bba, aaa, aa)
have a Post Correspondence Solution?
Solution
x1 x2 x3
M Abb aa aaa
N Bba aaa aa
Here,
x2x1x3 = ‘aaabbaaa’
and y2y1y3 = ‘aaabbaaa’
We can see that
x2x1x3 = y2y1y3
Hence, the solution is i = 2, j = 1, and k = 3.
Example 2
Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post Correspondence
Solution?
Solution
x1 x2 x3
M ab bab bbaaa
N a ba bab
In this case, there is no solution because −
| x2x1 x3 | ≠ | y2y1y3 | (Lengths are not same)
Hence, it can be said that this Post Correspondence Problem is undecidable.
(b) Halting Problem of TM:
Input − A Turing machine and an input string w.
Problem − Does the Turing machine finish computing of the string w in a finite number of
steps? The answer must be either yes or no.
Proof − At first, we will assume that such a Turing machine exists to solve this problem and then
we will show it is contradicting itself. We will call this Turing machine as a Halting machine
that produces a ‘yes’ or ‘no’ in a finite amount of time. If the halting machine finishes in a finite
amount of time, the output comes as ‘yes’, otherwise as ‘no’. The following is the block diagram
of a Halting machine −
Now we will design an inverted halting machine (HM)’ as −
If H returns YES, then loop forever.
If H returns NO, then halt.
The following is the block diagram of an ‘Inverted halting machine’ −
Further, a machine (HM)2 which input itself is constructed as follows −
If (HM)2 halts on input, loop forever.
Else, halt.
Here, we have got a contradiction. Hence, the halting problem is undecidable.
Q.6. Define a Turing machine. Explain the working of a basic TM with a neat diagram.
Also define the language accepted by TM. [10]
Ans: A Turing Machine is an accepting device which accepts the languages (recursively
enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turing.
Definition
A Turing Machine (TM) is a mathematical model which consists of an infinite length tape
divided into cells on which input is given. It consists of a head which reads the input tape. A
state register stores the state of the Turing machine. After reading an input symbol, it is replaced
with another symbol, its internal state is changed, and it moves from one cell to the right or left.
If the TM reaches the final state, the input string is accepted, otherwise rejected.
A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −
Q is a finite set of states
X is the tape alphabet
∑ is the input alphabet
δ is a transition function; δ : Q × X → Q × X × {Left_shift, Right_shift}.
q0 is the initial state
B is the blank symbol
F is the set of final states
A TM accepts a language if it enters into a final state for any input string w. A language is
recursively enumerable (generated by Type-0 grammar) if it is accepted by a Turing machine.
A TM decides a language if it accepts it and enters into a rejecting state for any input not in the
language. A language is recursive if it is decided by a Turing machine.
There may be some cases where a TM does not stop. Such TM accepts the language, but it does
not decide it.