TOC - Question Answer
TOC - Question Answer
Characteristics
i. Input: At each discrete instants of time t1, t2, … , input values I1,I2, …, each of which can take a
finite number of fixed values from the input alphabet ∑, are applied to the input side of model.
ii. Output: O1, O2, … , Oq are the outputs of the model, each of which can take finite numbers of
fixed values from an output O.
iii. States: At any instant of time the automaton can be in one of the states q1, q2, …, qn.
iv. State relation: The next state of an automaton at any instant of time is determined by present
state and present input.
v. Output relation: Output is related to either state only or to both the input and the state. At
any instant of time the automaton is in some state. On reading an input symbol, the
automaton moves to next state which is given by state relation.
2. What is finite automata and transition graph? What is use of transition graph?
Solution:
Finite Automata: A finite automaton can be represented by 5 tuple ( Q, ∑ , δ , q0, F ) where
i. Q is a finite nonempty set of states.
ii. ∑ is a +inite nonempty set of inputs called input alphabets.
iii. δ is a function which maps Q x ∑ → Q.
iv. q0 ∈ Q is the initial state.
v. F ⊆ Q is the set of final states.
Block diagram of finite automata is shown below:
Page | 1
Finite automata consists of input tape, reading head and finite control which are described below:
i. Input tape: The input tape is divided into squares, each square containing a single symbol from
input alphabet ∑. The end squares of the tape contain end markers ¢ at left end and $ at right
end. Absence of end markers indicates that the tape is of infinite length.
The left to right sequence of symbols between end markers is the input string to be processed.
ii. Reading head: The head examines only one square at a time and can move one square either to
the left or right.
iii. Finite control: The input to finite control is usually symbol under R head, say a, or present
state of machine say q, to give the following outputs:
A motion of R head along the tape to the next square.
The next state of the finite state machine given by δ(q, a).
In some null move, R head remaining to the same square is permitted.
Transition System: It is also known as transition graph. It is a finite directed labeled graph in
which each vertex (node) represents a state and the directed edges indicate the transition of a
state and the edges are labeled with input/ output. A transition system is shown below:
An initial state is represented by a circle with an arrow pointing towards it (q0). Final state is
represented by two concentric circles (q1). Other states are represented by just a circle. The edges
are labeled by input/ output.
Definition: A transition system is a 5 tuple ( Q, ∑, δ, Q0, F ) where
Q is finite nonempty set of states
∑ is +inite nonempty set of input alphabets
F is finite nonempty set of final states
Q0 ⊆ Q and Q0 is nonempty
δ is a finite subset of Q x ∑* x Q.
If ( q1, w, q2 ) is in δ, it means : the graph starts at vertex q1, goes along a set of edges, and
reaches the vertex q2. Concatenation of label of all the edges encountered is w.
Consider a transition system given below:
Page | 2
Here Q = {q0, q1}, ∑ = {0, 1}, F = {q1}, Q0 = q0,
The system is in state q0. When input 1 is applied, the system moves to state q1 as there is a directed
edge from q0 to q1 with label 1. And on applying input 0 system remains in same state i.e. q0. When
system is in state q1, on applying 0 system moves to state q0, while on input 1 system remains in
state q1.
Transition system is used to show the behavior of finite automata. We say a transition system
accepts a string w in ∑* if
a) there exist a path which originates from some initial state, goes along the arrows, and terminates
at some final state, and
b) the path value obtained by concatenation of all edge labels of the path is equal to w.
3. Give the formal definition of NFA and differentiate between NFA and DFA.
Solution: Consider the transition diagram
If the automaton is in state {q0} and input symbol is 0, then
next state will be either {q0} or {q1}. Thus some moves of the
machine cannot be determined uniquely by the input symbol and
present state. Such machines are called nondeterministic automata.
A nondeterministic finite automaton (NDFA) is a 5 tuple ( Q, ∑, δ, q0, F ) where
Q is finite nonempty set of states
∑ is +inite nonempty set of input alphabets
δ is a transition function mapping from Q x ∑ into 2Q, power set of Q (set of all subsets of Q)
q0 ∈ Q is initial state
F ⊆ Q is set of final states
A string w ∈ ∑* is accepted by NDFA M if δ(q0, w) contains some final state.
A deterministic finite automaton (DFA) can be represented by 5 tuple ( Q, ∑ , δ , q0, F ) where
Q is a finite nonempty set of states.
∑ is a +inite nonempty set of inputs called input alphabets.
δ is a function which maps Q x ∑ → Q.
q0 ∈ Q is the initial state.
F ⊆ Q is the set of final states.
The difference between a DFA and NFA is only in transition function. In DFA, transition function
maps on at most one state and in NFA transition function maps on at least state for an input symbol.
4. Prove that for any transition function δ and for any two input strings x and y
δ(q, xy) = δ( δ(q, x), y)
Solution:
We will use property transition function as: for all strings w and input symbol a,
Page | 3
δ(q, aw) = δ( δ(q, a), w )
δ(q, wa) = δ( δ(q, w), a )
Basis: When |y| = 1, y = a∈∑
δ(q, xy) = δ( δ(q, x), y) …..given in question …….equation 1
LHS of equation 1 = δ(q, xy) … put y=a
δ(q, xa) = δ( δ(q, x), a) …. By property
= RHS of equation 1
Assume the result i.e. equation 1 for all strings x and strings y with |y| = n. let y be a string of length
n+1.
Write y = y1a where |y1| = n.
LHS of equation 1 = δ(q, xy1a) = δ(q, x1a) ….. put x1 = xy1
= δ( δ(q, x1), a ) …. By property
= δ( δ(q, xy1), a )
= δ( δ( δ(q, x), y1), a ) …. By induction hypothesis
RHS of equation 1 = δ( δ(q, x), y1a )
= δ( δ( δ(q, x), y1), a ) …. By property 2
Hence LHS = RHS. This proves equation 1 for any string y of length n+1. By the principle of
induction, equation 1 is true for all strings.
Solution:
We construct transition table as follows
Page | 5
Step 1 Construction of Π0:
Since there is only one final state Q10 = {q3}.
Q20 = Q - Q10, Q20 = {q0, q1, q2, q4, q5, q6, q7}.
Hence Π0 = { {q3}, {q0, q1, q2, q4, q5, q6, q7} }
Step 2 Construction of Π1:
• q3 cannot be partitioned further, so Q11 = {q3}
• Consider q0 & q1 ∈ Q20.
• The entries under a column, corresponding to q0
and q1 are q1 & q0; they lie in Q20.
• The entries under b column are q0 & q2; they also lie in Q20.
• So q0 and q1 are 1 equivalent.
• Consider q0 & q2 ∈ Q20.
• The entries under a column, corresponding to q0 and q2 are q1 & q3; q1 ∈ Q20, q3 ∈ Q10.
• So q0 and q2 are not 1 equivalent.
• Consider q0 & q4 ∈ Q20.
• The entries under a column, corresponding to q0
and q4 are q1 & q3; q1 ∈ Q20, q3 ∈ Q10.
• So q0 and q4 are not 1 equivalent.
• Consider q0 & q5 ∈ Q20.
• The entries under a column, corresponding to q0
and q5 are q1 & q6; they lie in Q20.
• So q0 and q5 are 1 equivalent.
• Consider q0 & q6 ∈ Q20.
• The entries under a & b column, corresponding to q0 and q6 are q1 & q5 and q0 & q6; they lie
in Q20.
• So q0 and q6 are 1 equivalent.
• Consider q0 & q7 ∈ Q20.
• The entries under a column, corresponding to
Page | 6
q1 and q7 are q1 and q6; they lie in Q20.
• But entries under b column are q0 and q3, so they are not 1 equivalent.
• It is clear from table that q2 and q4 are 1 equivalent
• And q2 and q7 are not 1 equivalent
Hence Q11 = {q3}, Q21 = {q0, q1, q5, q6}, Q31 = {q2, q4}, Q41 = {q7}
Π1 = { {q3}, {q0, q1, q5, q6}, {q2, q4}, {q7} }
Construction of Π2:
• q3 cannot be partitioned further, so Q12 = {q3}
• q7 cannot be partitioned further, so Q22 = {q7}
• Consider q2 & q4 ∈ Q31.
• The entries under a column, corresponding to
q2 and q4 are q3; they lie in Q11.
• The entries under b column are q1 & q5; they also lie in Q21.
• So q2 and q4 are 2 equivalents.
• Consider q0 & q1 ∈ Q21.
• The entries under a column, corresponding to
q0 and q1 are q1 and q0; they lie in Q21.
• The entries under b column are q0 & q2; they lie in different sets, q0 ∈ Q21, while q2 ∈ Q31.
• So q0 and q1 are not 2 equivalents.
• Consider q0 & q5 ∈ Q21.
• The entries under a column, are q1 and q6;
they lie in Q21.
• The entries under b column are q0 & q4; they lie in different sets, q0 ∈ Q21, while q4 ∈ Q31.
• So q0 and q5 are not 2 equivalents.
• Consider q0 & q6 ∈ Q21.
• The entries under a column, are q1 and q5;
they lie in Q21.
• The entries under b column are q0 & q6; they also lie in Q21.
• So q0 and q6 are 2 equivalents.
• Consider q1 & q5 ∈ Q21.
• The entries under a column, are q0 and q6;
they lie in Q21.
• The entries under b column are q2 & q4; they also lie in Q31.
• So q1 and q5 are 2 equivalents.
• Q12 = {q3}, Q22 = {q7}, Q32 = {q2, q4}, Q42 = {q0, q6}, Q52 = {q1, q5}
Hence Π2 = { {q3}, {q0, q6}, {q1, q5}, {q2, q4}, {q7} }.
Page | 7
Construction of Π3:
• {q3}, {q7} cannot be partitioned further.
• Consider q1 & q5 ∈ Q52.
• The entries under a column, are q0 and q6;
they lie in Q42.
• The entries under b column are q2 & q4; they also lie in Q32.
• So q1 and q5 are 3 equivalents.
• Consider q2 & q4 ∈ Q32.
• The entries under a column, are q3 and q3.
• The entries under b column are q1 & q5; they
also lie in Q52.
• So q2 and q4 are 3 equivalents.
• Consider q0 & q6 ∈ Q42.
• The entries under a column, are q1 and q5; lie in
Q52.
• The entries under b column are q0 & q6; they also lie in Q42.
• So q0 and q6 are 3 equivalents.
• Q13 = {q3}, Q23 = {q7}, Q33 = {q2, q4}, Q43 = {q0, q6}, Q53 = {q1, q5}
• Hence Π3 = { {q3}, {q0, q6}, {q1, q5}, {q2, q4}, {q7} }.
• As Π2 = Π3, Π2 gives the equivalence classes, the minimum state automaton is
M’ = ( Q’, {a, b}, δ’, q0’, F’ ) where
Q’ = { [q3], [q0, q6], [q1, q5], [q2, q4], [q7] }.
q0‘ = [q0, q6]
F’ = [q3], and δ’ is given by
Page | 8
Transform it into Moore machine.
Solution:
We know that λ (output function) for Mealy machine maps ∑ x Q into Δ whereas output function for
Moore machine maps Q into Δ.
We proceed by splitting states qi into several states, the number of such states being equal to
number of different outputs associated with qi.
Here q1 is associated with output 1 at each place.
q2 is associated with two different outputs 0 and 1.
So split q2 into q20 and q21 for output 0 and 1 respectively.
q3 is associated with output 0.
Split q4 into q40 and q41.
The pair of states and outputs in next state column can be rearranged as
Page | 9
The table gives Moore machine.
Observe that initial state is q1 is associated with output 1.
Means with input Λ we get an output 1.
Thus, this Moore machine accepts null sequence, which is not accepted by Mealy machine.
So, we must add a new starting state q0 with output 0 and transitions identical with q1.
For every input symbol we form pair consisting of next state and corresponding output.
Page | 10
State q3 and q1 in next state column should be associated with outputs 0 and 1 respectively,
and 0 for both q2 and q0.
Now reconstruct the table as below
We can reduce the number of states in any model by considering states with identical
transitions.
If two states have identical transitions, then we can delete one of them.
Page | 11
9. Explain two way finite automata.
Solution:
In finite automata head movement is restricted from left to right direction. If we remove such
restriction and allowing head to move in both direction left to right and right to left but in one
direction at a time. This enhancement in finite automata results a new model called two – way
finite automata. This model does not increase power of finite automata.
Page | 12
The head is under input symbol ai.
Present state is q1.
After reading this symbol, 2DFA moves in state s
and head movement is right, then
a1 a2 ….. (q1) ai ai+1 ….. an | a1 a2 ….. ai (s) ai+1 ….. an
This representation of ∑* Q ∑* is known as ID, which indicates read symbols, present state and
remaining symbols of input string.
Let ID1 = a1 a2 ….. (q1) ai ai+1 ….. an and
ID2 = a1 a2 ….. ai (s) ai+1 ….. an
Then ID1 | ID2
Similarly ID1, ID2 , ID3, …. IDn at time instants t1, t2, …tn then
ID1 | ID2 | ID3 | IDn
10. Explain My-hill Nerode’s theorem with example and discuss its properties.
Solution: A given language L is a regular language if and only if set of equivalence classes of L is
finite. Or
1. Language L can be divided into set of all possible strings into separate (mutually exclusive)
classes.
2. If L is a regular language then number of classes created is finite.
3. If number of classes that L has, is finite then L is regular language.
Properties:
Classes are Mutually Exclusive:
Let z be a string and DFA M = (Q, ∑, δ, q0, F) and M accepts L then δ(q0, z) = Φ (if rejected by M and z
∉ L). or
δ(q0, z) = qn, for some qn ∈ F (since M is DFA and hence only one reachable state and z ∈ L).
For all possible strings z, either z belongs to a unique class, say Cn contains it or it is rejected.
Hence classes are mutually exclusive.
If L is a regular language then the number of classes created is finite:
L is a regular language so some DFA M recognizes it. We know that DFA has finite number of states.
So, number of societies it creates is finite. It may be there, some societies may be equivalent and so
Page | 13
if we combine these equivalent societies into one end we can have minimum state DFA and then
societies are disjoint. These disjoint societies are called classes of language L. Hence if L is regular
language then number of classes, it has, is finite.
If number of classes is finite, then L is a regular language:
Let classes be C0, C1, C2, …, Cn for some fixed value of n. We can suppose these classes as states of
DFA such that:
a) The class containing ε (null string) is initial state.
b) For all wi ∈ L the class having wi is the final state.
c) There is a transition (edge) from the state Ci to Cj with label a if x ∈ Ci and xa ∈ Cj.
Hence if number of classes is finite, then L is a regular language.
Example:
Show that L = {anbn : n ≥ 1} is not regular.
Solution:
o In the given language number of a’s is equal to number of b’s.
o So L = {ab, aabb, aaabbb, aaaabbbb…..}
o Depending on the value of n, classes are C1, C2, C3,…., Cn.
o So, if value of n is finite then number of classes are finite.
o Consider n=3 then, C1 = {ab}, C2 = {aabb}, C3 = {aaabbb}
o If value of n is very large (say tends toward infinite), then number of classes are infinite and it
does not satisfy Myhill Nerode theorem.
o So, L is not regular.
11. Design a finite automata that reads strings made up of letters in the word “HOUSE” & recognizes
those strings that contain the word “USE” at anywhere.
Solution: There are 5 symbols in word “HOUSE”. We have to recognize the strings containing the
word “USE” at anywhere. So, our aim is to design a DFA in which symbol ‘U’, ‘S’, and ‘E’ present
contiguous. The word “USE” may be preceded and followed by any combination of symbols ‘H’, ‘O’,
‘U’, ‘S’, and ‘E’ and any number of times.
Page | 14
The automata shown above is nondeterministic as on applying input ‘U’ the system can move to
state q0 or q1. So, convert this NFA
to DFA.
The transition table can be given
as:
Here q0 is initial state while [q0, qf], [q0, q1, qf] and [q0, q2, qf] are final states. As final state qf of
NFA is associated with these states.
The equivalent transition system can be given as:
Page | 15
12. Consider the transition system and prove that the string recognized by it is
(a + a ( b +aa )* b )* a ( b + aa )* a
Solution:
There are three states so, make three equations for q1, q2 and q3 as follows:
q1 = q1a + q2b + Λ (incoming edges to q1, Λ is added as q1 is initial state)
q2 = q1a + q2b + q3a (incoming edges to q2)
q3 = q2a (incoming edges to q3)
Substitute q3 in q2 equation… we get
q2 = q1a + q2b + q2aa
q2 = q1a + q2 ( b+aa)
q2 = q1a ( b + aa )* by Arden’s rule R = Q + RP R = QP*
Substitute q2 in q1
q1 = q1a + q1a (b+aa)*b + Λ
q1 = q1 (a + a ( b+aa)* b) + Λ
q1 = Λ (a + a (b + aa)* b)* by Arden’s rule R = Q + RP R = QP*
Put q1 for q2
q2 = (a + a (b + aa)* b)* a(b + aa)*
Put q2 for q3
q3 = (a + a (b + aa)* b)* a (b + aa)* a
Since q3 is final state, set of strings recognized by graph is
(a + a (b + aa)* b)* a (b + aa)* a
Page | 16
3) Kleene Closure
4) Complementation
5) Transpose
6) Intersection
Union: Class of two regular sets S and T are closed under union operation. If S and T are two
regular sets then union of these denoted by S + T or S ∪ T is also a regular set.
Concatenation: Class of two sets S and T are closed under concatenation operation. If S and T are
two regular sets then union of these denoted by S T is also a regular set.
Kleene Closure: Class of regular set S is closed under Kleene closure operation. If S is a regular set,
then Kleene closure of this denoted by S* is also a regular set.
Page | 17
Transpose: If S is a regular set then transpose of S is denoted by SR, is also a regular set. Let regular
set S is represented as below:
Intersection: Classes of two sets S and T are closed under intersection operation. If S and T are two
regular sets over ∑, then intersection of these denoted by S ∩ T is also a regular set.
14. Explain Pumping lemma for a regular set and also explain application of Pumping lemma.
Solution:
Pumping lemma shows that specific given languages are not regular.
Statement:
If A is a regular language, then there is a number m (the pumping length) where, if s is any string in
A of length at least m, then s may be divided into three pieces, s = xyz, satisfying the following
conditions:
1. for each i ≥ 0, xyiz ∈ A,
2. |y| > 0, and
3. |xy| ≤ m.
Details of Proof
Consider L - any infinite regular language.
1. L regular → there is a DFA M with L(M) = L.
2. Let DFA have m states (say).
3. Let w in L be of length more than m.
4. δ*(s,w) = f (some final state) must be
δ*(s, w = xyz) = δ*(q,yz) = δ*(q,z) = f
5. So xynz in L for n = 0, 1, 2, 3, ....
Since δ*(s, xynz) = δ*(q, ynz) = δ*(q, y{n-1}z) = ... = δ*(q,z) = f.
Describing
Page | 18
Take an infinite regular language L
DFA that accepts L having m states
Take strings w with w∈ L
There is walk label: w
Write w = xyz
Observation:
Length |xy| ≤ m
Length |y| ≥ 1
The string xz is accepted.
The string xyyz, xyyyz is accepted.
The string xyiz is accepted where i = 0, 1, 2, 3, ….
Application of Pumping lemma
Used to check that certain sets are regular or not.
The following languages are not regular.
1. {anbn | n ≥ 0 }.
2. {w = wR | w in {a,b}* } (language of palindromes).
3. {wwR | w in {a,b}*}.
4. {a{n2} | n ≥ 0}.
15. Using Pumping lemma show that language {anbn : n>0} is not regular.
Solution:
In the language number of a’s is equal to number of b’s. This is the clue to find the contradiction.
Step 1: let L is regular and accepted by DFA M with n states.
Step 2: string w ∈ L such that |w| ≥ n and w = xyiz ∈ L for i ≥0, y ∉ ε, and |xy| ≤ n.
Step 3: selecting substring y (y ≠ ε)
Page | 19
Let w = xyiz for i = 0, that is w = xz
Case 1: when y = ap, then w =an-p bn
number of a’s = n-p and number of b’s = n
number of a’s = number of b’s iff p=0
And number of a’s and b’s is not equal when p > 0
Since y ≠ ε for p>0, so w = xyiz ∉ L.
Case 2: when y = bq, then w =an bn-q
number of a’s = n and number of b’s = n-q
number of a’s = number of b’s only if q=0
And number of a’s and b’s is not equal when q > 0
Since y ≠ ε for q>0, so w = xyiz ∉ L.
Case 3: when y = ap bq, then w =an-p bn-q
xyz = an-p ap bq bn-q,
let i = 2, xy2z = an-p ap bq ap bq bn-q .
xy2z is not in an bn format, hence xy2z ∉ L.
Hence L is not regular.
( 0 + 1 )* ( 00 + 11 ) ( 0 + 1 )*
Page | 20
Eliminate concatenation
Eliminate * operation
19. Find a reduced grammar equivalent to the grammar S → aAa, A → bBB, B → ab, C → aB.
Solution:
Step 1: Construct grammar G1 equivalent to G so that every variable in G derives some terminal
string.
Construction of VN
W1 = {B}………{as B → ab is the only production in with a terminal string on the RHS
W2 = W1 ∪ { X ∈ VN | X → α where α ∈ ( ∑ ∪ W1 )* }
W2 = {B} ∪ {C, A} …..{as A → bBB, C → aB
W2 = {A, B, C}
Similarly
W3 = {A, B, C} ∪ {S} ……{as S → aAa
W3 = {S, A, B, C}
W4 = {S, A, B, C} ∪ {∅}
W3 = W4
VN = W3 = {S, A, B, C}
Construction of P’
P’ = { X → α | X, α ∈ (V’N ∪ ∑)* }
Hence, P’ consists of
S → aAa, A → bBB, B → ab, C → aB
Step 2: Construct grammar G2 equivalent to G such that every symbol in G1 appears in some
sentential form.
Construction of Wi for i ≥ 1
W1 = {S} …{S is start symbol
W2 = W1 ∪ {X ∈ VN ∪ ∑ | there exist a production A → α with A ∈ Wi and α containing the symbol X}
W2 = {S} ∪ {a, A} ….{as S → aAa
W2 = {S, A, a}
W3 = {S, A, a} ∪ {b, B}….{as A → bBB
Page | 22
W3 = {S, A, B, a, b}
W4 = {S, A, B, a, b} ∪ {∅}
W4 = {S, A, B, a, b}
W3 = W4
Construction of V’N, ∑’ and P’
V’N = VN ∩ W3
V’N = {S, A, B, C} ∩ {S, A, B, a, b}
V’N = {S, A, B}
∑’ = ∑ ∩ W3
∑’ = {a, b} ∩ {S, A, B, a, b}
∑’ = {a, b}
P’ = { X → α | X ∈ W3 }
P’ = { S → aAa, A → bBB, B → ab }
G’ = ( { S, A, B}, {a, b}, P’, S )
We can see that symbol C is eliminated completely.
Hence, G’ is the reduced grammar.
20. Using Pumping lemma show that L = {anbncn : n≥0} is not context free language.
Solution:
Pumping lemma
1) |vx| ≥ 1
2) |vwx| ≤ n
3) uviwxiy is in L for all i ≥ 0
Assume that L is context free .
L = {abc, aabbcc, aaabbbccc, ….}
Let w = aabbcc
By Pumping lemma, we know that
w = uviwxiy
let u → Λ
y→Λ
w = viwy
w = (aa)i bbcc
for i = 1 w = aabbcc which is in L
for i = 2 w = aaaabbcc which is not in L
Therefore the language is not context free language.
S ⇒ SbS
⇒ abS …{ apply S → a
⇒ abSbS …{ apply S → SbS
⇒ abSbSbS …{ apply S → SbS
⇒ ababSbS …{ apply S → a
⇒ abababS …{ apply S → a
⇒ abababa …{ apply S → a
S ⇒ SbS
⇒ SbSbS …{ apply S → SbS
⇒ SbSbSbS …{ apply S → SbS
⇒ abSbSbS …{ apply S → a
⇒ ababSbS …{ apply S → a
⇒ abababS …{ apply S → a
⇒ abababa …{ apply S → a
As we can see that for string abababa we have two leftmost derivations. So the given grammar is
ambiguous.
22. Write short notes on left linear grammar, right linear grammar, context free grammar.
Solution:
General production form of CFG
(V ∪ T)+ → (V ∪ T)* where V is variable (nonterminal), T is terminal
Page | 24
P is a set of productions or substitution rules of the form A → α where A is a variable and α is a
string with variables and terminals
S is a variable called the start variable
A grammar is called type 2 or context free if it contains only type 2 productions.
A type 2 production is of the form
A → α, where A ∈ VN, α ∈ ( VN ∪ ∑ )*
LHS has no left and right context.
Example: S → Aa, A → B, B → b, B → Λ, A → abc
23. Explain Chomsky Normal Form and Greibach Normal Form with example.
Solution:
Chomsky Normal Form (CNF)
A context free grammar is in Chomsky normal form (CNF) if every production is of the form A → α,
or A → BC, and S → Λ is in G if Λ ∈ L(G). If Λ is in L(G), we assume that S does not appear on RHS of
any production.
Example:
If productions in G are S → AB | Λ, A → a, B → b, then G is in Chomsky Normal Form (CNF).
Page | 26
Reduction into GNF:
Step 1:
The grammar has no null production and is in CNF.
Nonterminal S and A are renamed as A1 and A2 respectively.
So productions are A1 → A2 A2 | a, A2 → A1 A1 | b
Step 2:
A1 productions are in required form (not in GNF).
They are A1 → A2 A2 | a.
A2 → b is in required form.
A2 → A1 A1 is not in required form.
So apply lemma 1, and resulting productions are A2 → A2A2A1, A2 → aA1
Till now the productions are
A1 → A2A2 | a
A2 → b
A2 → A2A2A1 | aA1
Step 3:
Apply lemma 2 to A2 → A2A2A1 (An → Anγ form)
Let Z2 be new variable.
Resulting productions are
A2 → aA1, A2 → b
A2 → aA1Z2, A2 → bZ2
Z2 → A2A1, Z2 → A2A1Z2
Till now the productions are
A1 → A2A2 | a
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → A2A1 | A2A1Z2
Step 4:
Among A1 productions we retain A1 → a and eliminate A1 → A2A2 using lemma 1.
Resulting productions are A1 → aA1A2 | bA2 | aA1Z2A2 | bZ2A2
Till now the productions are
A1 → a | aA1A2 | bA2 | aA1Z2A2 | bZ2A2
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → A2A1 | A2A1Z2
Step 5:
Z2 productions to be modified are
Z2 → A2A1, Z2 → A2A1Z2 Apply lemma 1.
Z2 → bA1 | aA1A1 | aA1Z2A1 | bZ2A1
Z2 → bA1Z2 | aA1A1Z2 | aA1Z2A1Z2 | bZ2A1Z2
Hence the equivalent grammar is
Page | 27
G’ = ( {A1, A2, Z2}, {a, b}, P1, A1) where P1 consists of
A1 → a | aA1A2 | bA2 | aA1Z2A2 | bZ2A2
A2 → b | aA1 | aA1Z2 | bZ2
Z2 → bA1 | aA1A1 | aA1Z2A1 | bZ2A1
Z2 → bA1Z2 | aA1A1Z2 | aA1Z2A1Z2 | bZ2A1Z2
This is the required grammar in GNF.
Page | 29
28. Define Pushdown automata and Turing Machine.
Solution:
Pushdown Automata:
Pushdown automatons are nondeterministic devices. It recognizes context free languages. A finite
automaton cannot accept language L (strings of the form anbn). Why? Because it has to remember
number of a’s in string and hence require infinite number of states. PDAs are enhanced version of
Finite Automata. A finite automata with stack memory can be viewed as PDA. This stack is read/
write memory. Stack memory is infinite and its operation is based on LIFO. Stack memory is known
as pushdown store (PDS).
Description
PDA consists of Finite tape, Reading head (which reads from the tape), Stack memory (pushdown
store, which is read/ write and operated in LIFO fashion). There are two alphabets for input
symbols to be read: One for input tape another for stack. Stack alphabet is denoted by Γ. Input
alphabet is denoted by ∑ . PDA reads from both alphabets (one input from tape and one from top of
stack). After reading both inputs, PDA moves in next state and writes zero or more symbols on the
stack. After writing on the stack, pointer to top of stack is auto adjusted, and points to top of stack.
Same operation is carried out for entire inputs on tape. At end of operation, content of stack
memory is considered as output produced by pda.
Mathematical Description
PDA is described by 7 tuples: ( Q, ∑, Γ, δ, q0, Z0, F )
Q is finite nonempty set of states
∑ is input alphabet
Γ is finite nonempty set of pushdown symbols
δ is transition function, maps from Q x (∑ ∪ {Λ}) x Γ to Q x Γ*
q0 ∈ Q, is initial state
Z0 ∈ Γ is starting stack symbol
F ⊆ Q, set of final states
Page | 30
Turing Machine:
It is simple mathematical model of general purpose computer. It models the computing power of a
computer. It is capable of performing any calculation which can be performed by any computing
machine.
Model:
It can be thought as a finite automaton connected to R/W head. It has a tape, divided into a number
of cells. Each cell can store only one symbol.
The head of Turing machine is capable of reading as well as writing on tape. It can move left or right
or remain static. In one move, the machine examines present symbol under R/W head on tape and
present state of automaton to determine:
o A new symbol to be written on tape in cell under R/W head.
o A motion of R/W head along the tape; either head moves one cell left (L), or one cell right (R).
o The next state of automaton.
o Whether to halt or not.
Definition:
A Turing machine M is a 7 tuple (Q, ∑, Γ, δ, q0, b, F), where
Q is finite nonempty set of states
Γ is finite nonempty set of tape symbols
b ∈ Γ is the blank
∑ is nonempty set of input symbols (subset of Γ) and b∉∑.
δ is transition function mapping states of finite automaton and tape symbols to states, tape
symbol and movement of head. Q x Γ → Q x Γ x {L, R}
q0 ∈ Q is the initial state
F ⊆ Q is set of final states
29. Construct context free grammar G which accepts N(A), where A=( {q0, q1}, {a, b}, {Z0, Z}, δ, q0, Z0, Φ )
and δ is given by
δ (q0, b, Z0) = {(q0, ZZ0)}
δ (q0, Λ, Z0) = {(q0, Λ)}
Page | 31
δ (q0, b, Z) = {(q0, ZZ)}
δ (q0, a, Z) = {(q1, Z)}
δ (q1, b, Z) = {(q1, Λ)}
δ (q1, a, Z0) = {(q0, Z0)}
Solution:
Rule: Let G = (VN, {a, b}, P, S) where VN consists VN = {S} ∪ { [q, Z, q’] | q, q’ ∈ Q, Z ∈ Γ }
So, VN is given by
S, [q0, Z0, q0], [q0, Z0, q1], [q0, Z, q0], [q0, Z, q1], [q1, Z0, q0], [q1, Z0, q1], [q1, Z, q0], [q1, Z, q1],
Rule: S productions are given by S → [q0, Z0, q] for every q in Q.
So, the S productions are
P1: S → [q0, Z0, q0]
P2: S → [q0, Z0, q1]
Rule: Each move not erasing a pushdown symbol given by (q1, Z1Z2…Zm) ∈ δ(q, a, Z) induces many
productions of form
[q, Z, q’] → a[q1, Z1, q2] [q2, Z2, q3] … [qm, Zm, q’] where each states q’, q2 … qm can be any state in Q.
So,
P3: [q0, Z0, q0] → b[q0, Z, q0][q0, Z0, q0]
P4: [q0, Z0, q0] → b[q0, Z, q1][q1, Z0, q0]
P5: [q0, Z0, q1] → b[q0, Z, q0][q0, Z0, q1]
P6: [q0, Z0, q1] → b[q0, Z, q1][q1, Z0, q1]
Rule: Each move erasing a pushdown symbol given by
(q’, Λ) ∈ δ(q, a, Z) induces the production [q, Z, q’] → a.
δ (q0, Λ, Z0) = {(q0, Λ)} gives
P7: [q0, Z0, q0] → Λ
Similarly, other moves induces following productions
δ (q0, b, Z) = {(q0, ZZ)} gives
P8: [q0, Z, q0] → b[q0, Z, q0][q0, Z, q0]
P9: [q0, Z, q0] → b[q0, Z, q1][q1, Z, q0]
P10: [q0, Z, q1] → b[q0, Z, q0][q0, Z, q1]
P11: [q0, Z, q1] → b[q0, Z, q1][q1, Z, q1]
δ (q0, a, Z) = {(q1, Z)} yields
P12: [q0, Z, q0] → a[q1, Z, q0]
P13: [q0, Z, q1] → a[q1, Z, q1]
δ (q1, b, Z) = {(q1, Λ)} gives
P14: [q1, Z, q1] → b
δ (q1, a, Z0) = {(q0, Z0)} gives
P15: [q1, Z0, q0] → a[q0, Z0, q0]
P16: [q1, Z0, q1] → a[q0, Z0, q1]
P1 to P16 gives the productions in P.
Page | 32
30. Design a PDA for the language L = { wcwR | w ∈ (a, b)* }.
Solution:
Note: wR means Reverse order of w i.e. if w=abb then wR = bba.
Therefore w = {Λ, a, b, aa, bb, ab, ba, ………}
As we know that a PDA = (Q, Σ, τ, δ, q0, P0, F) then,
PDA = ( {q0, q1, qf},{a,b,c}, {a,b,P0}, δ, {q0,P0}, {qf} )
δ can be defined as:
1. δ (q0, a, P0) = (q0, aP0)
2. δ (q0, b, P0) = (q0, bP0)
3. δ (q0, a, a) = (q0, aa)
4. δ (q0, b, b) = (q0, bb)
5. δ (q0, a, b) = (q0, ab)
6. δ (q0, b, a) = (q0, ba)
7. δ (q0, c, a) = (q1, a)
8. δ (q0, c, b) = (q1, b)
9. δ (q1, a, a) = (q1, Λ)
10. δ (q1, b, b) = (q1, Λ)
11. δ (q1, Λ, P0) = (qf, P0)
Let w = abb then wR = bba.
Hence, L= abb c bba
δ (q0, abb c bba,P0) ├ (q0, bb c bba, aP0)
├ (q0, b c bba, baP0)
├ (q0, c bba, bbaP0)
├ (q1, bba, bbaP0)
├ (q1, ba, baP0)
├ (q1, a, aP0)
├ (q1, Λ, P0)
├ (qf, Λ, P0)
PDA reaches the final state and all input symbols are processed.
Therefore this is the required PDA for L = { wcwR | w ∈ (a, b)* }.
As PDA reached the empty stack and all input symbols are processed, therefore this is the required
PDA for language L = { anb2n | n > 0 }.
32. What are Multitape Turing Machine, Universal Turing Machine, Post Correspondence Problem.
Solution:
Universal Turing Machine (UTM)
General purpose Turing machine is called universal Turing machine. It is powerful enough to
simulate the behavior of any computer, including any Turing machine itself. Universal Turing
machine can simulate the behavior of an arbitrary Turing machine over any ∑. A UTM takes as
input the description of a Turing machine along with initial tape contents and simulates the input
on that Turing machine.
Multi Tape Turing Machine
Multi tape Turing machine has multiple tapes. It can have separate tape head for each of its multiple
tapes. On each move, the machine reads symbols under all the tape heads simultaneously, changes
state according to combination of symbols read and writes new symbols to each of scanned cells
independently. The head movements on the each tape are independent; either one cell right or left
and some time stationary also.
Post Correspondence Problem (PCP)
Definition:
A correspondence system P is a finite set of ordered pairs of nonempty strings over some
alphabet.
Let ∑ be an alphabet, the P is finite subset of ∑+ x ∑+.
A match or solution of P is any string w ∈ ∑ such that pairs (u1, v1), (u2, v2), ……, (un, vn) ∈ P and
w = u1 u2 …. un = v1 v2 …. vn for some n>0.
The selected pairs (u1, v1), (u2, v2), ……, (un, vn) are not necessarily distinct.
Let strings u1, u2, …., um are in set U and strings v1, v2,…., vm are in set V, then
Page | 34
U = { u1, u2, …., um } and V = { v1, v2,…., vm } for some m>0.
PCP is to determine whether there is any match or not for a given correspondence problem.
Example:
Consider a corresponding system P = { (b, ca), (a, ab), (ca, a), (abc, c) }. Find match if any.
Solution: we represent P as following:
u1 = b, u2 = a, u3 = abc, v1 = ca, v2 = ab, v3 = c.
We have a solution:
w = u3u2 = v2v1 = abca
Application of PCP:
PCP has very important role in formal languages and also in general life.
It is used to prove certain problems are undecidable.
Page | 36
36. Define primitive recursive function.
Solution:
A function is primitive recursive if
1. It is an initial function or
2. It is obtained from recursion or composition of initial functions.
Example:
Show that concatenation of two strings over {a, b} is primitive recursive.
Proof:
We define concatenation as:
f(ε, w2) = w2
f(a1a2…an, w2) = a1f(a2a3…an, w2), where w1, w2 ∈ ∑*.
We define function f using initial functions as:
f(ε, w1) ≡ CONCATE ε (w1) = w1 and
f(a1a2…an, w2) ≡ CONCATE a1( f(a2a3…an, w2) )
consider: f(ab, cd)
f(ab, cd) = CONCATE a ( f(b, cd) )
= a f(b, cd)
= a CONCATE b ( f(ε, cd) )
= ab f(ε, cd)
= abcd (since f(ε, w) = w)
Hence, concatenation is primitive recursive function.
37. Prove that addition and mn of two integers are primitive recursive.
Solution:
Addition function:
We can define function f using initial functions as:
f(m, 0) = m ≡ P11(m) and
f(m, n+1) = f(m, n) + 1 ≡ S( f(m, n) )
Consider f(5, 2)
f(5, 2) = S( f(5, 1) )
Page | 37
= f(5, 1) + 1
= S( f(5, 0) ) + 1
= f(5, 0) + 1 + 1
=5+1+1
=7
Hence, f is a primitive recursive function.
Function (m, n) = mn:
We define f(m, n) by using initial functions as following:
f(m, 0) = m0 = 1 ≡ S( Z(m) )
f(0, n) = 0 ≡ Z(n) and
f(m, n+1) = m * f(m, n) ≡ P11 (m * f(m, n) )
Hence, f(m, n) is primitive recursive function.
38. Compute A(1, 1), A(2, 1), A(1, 2), A(2, 2) by using recursive function.
Solution:
Ackermann’s Function
It is defined by
A(0, y) = y+1
A(x+1, 0) = A(x, 1)
A(x+1, y+1) = A( x, A(x+1, y) )
A(1, 1)
A(1, 1) can be written as A(0+1, 0+1) ….{to do comparison
A(0+1, 0+1) ⇒⇒⇒ A(x+1, y+1) …here x=0 and y=0
We have A(x+1, y+1) = A( x, A(x+1, y) )
So, A(0+1, 0+1) = A(0, A(0+1, 0) )
A(0, A(0+1, 0) ) ⇒⇒⇒ A(0, A(x+1, 0) ) …here x=0
We have A(x+1, 0) = A(x, 1)
So, A(0, A(0+1, 0) ) = A(0, A(0, 1) )
We have A(0, y) = y+1
So, A(0, 1) = 1+1 = 2
Hence, A(0, A(0, 1) ) = A(0, 2)
Finally =3 ….{ A(0,2) = 2+1 = 3
Summary:
A(1, 1) = A(0+1, 0+1)
= A(0, A(1, 0) )
= A(0, A(0, 1) )
= A(0, 2)
= 3
A(1, 2) = A(0+1, 1+1)
= A(0, A(0+1, 1) )
Page | 38
= A(0, A(1, 1) )
= A(0, 3) … {A(1, 1) = 3 previously calculated
= 4
A(2, 1) = A(1+1, 0+1)
= A(1, A(1+1, 0) )
= A(1, A(1, 1) )
= A(1, 3)
= A(0+1, 2+1)
= A(0, A(0+1, 2) ) = A(0, A(1, 2) )
= A(0, 4) … {A(1, 2) = 4 previously calculated
= 5
A(2, 2) = A(1+1, 1+1)
= A(1, A(1+1, 1) )
= A(1, A(2, 1) )
= A(1, 5) … {A(2, 1) = 5 previously calculated
= A(0+1, 4+1)
= A(0, A(0+1, 4) ) = A(0, A(1, 4) )
= A(0, A(0+1, 3+1) ) = 1 + A(0+1, 3+1)
= 1 + A(0, A(0+1, 3) )
= 1 + A(0, A(1, 3) )
= 1 + 1 + A(1, 3) = 1 + 1 + A(0+1, 2+1)
= 1 + 1 + A(0, A(0+1, 2) ) = 1 + 1 + 1 + A(1, 2)
= 1 + 1 + 1 + 4 … {A(1, 2) = 4
= 7
Page | 39
M has k two-way infinite tapes, one of these tapes contains the input and all tapes including input
tape can be written. Time complexity is defined as:
If for every input of length n (n≥0), M makes at most T(n) moves before halting then M is said to be
a T(n) time bounded Turing machine (or of time complexity T(n)).
The language recognized or function computed by M is said to be of time complexity T(n).
Space complexity:
Consider an off-line Turing machine M of k tapes.
M has a read only tape and k-1 one way infinite tapes. Space complexity is defined as:
If for every input stream of length n (n≥0), Turing machine M scans at most S(n) cells on any tape
then M is said to be a S(n) space bound Turing machine or space complexity of S(n) and the
language recognized or function computed by M is said to be of space complexity S(n).
Generally, S(n) is of linear growth. But in some case there may be the different growth rate. If head
writes on the tape then the length of written is included in calculation of space complexity.
Page | 40
3. Never halts (fall into loop) or
4. Crash
Language recognized by Turing machine is known as recursively enumerable (r. e.) and set of
recursive languages is subset of recursively enumerable set.
Set of recursively enumerable languages are those languages that can be listed (enumerated) by
Turing machine. If a Turing machine can generate all strings in a language, another Turing machine
can accept all the strings. But, we don’t know about rejection of strings that are not in given
language. Strings that are not in given language may be rejected or may cause the Turing machine
to go into an infinite loop. A language is recursive if there exist a Turing machine that accepts every
string of the language and rejects every string that is not in the language.
Page | 41