You are on page 1of 21

Assignment : 1 Topic Given On : 05/10/2016

DIFFERENT AUTOMATA & LANGUAGE PROBLEMS


Overview of Course

Name of Students & Register No

1.Aishwarya Roy JYAOECS008

2.Aneeja Martin JYAOECS016

3.Edwin Lingson JYAOECS035

4.-------------------------------------------------
Submission Date : 18/10/2016, 11.59 PM
Course : Theory Of Computation Faculty : Mr. Dany Varghese(AP,CSE)
Remarks

Mark:

Assignment Topic

1. Regular Languages
2. DFA or NFA
3. Context Free Grammars
4. Push-Down Automata
5. Turing Machine

Objective
Student will get an idea about different type of languages problems and abstract machines.

Reference

• Text Book : Theory of Computation Author : Rajesh K Shukla


• Text Book : Theory of Computation Author : O G Kakde
• Text Book : Theory of Computation: A Problem Solving Approach Author : Kavi Mahesh
• Text Book : Introduction to Theory of Computation Author : Micheal Sipser
• Text Book : Introduction to Automata Theory, Formal languages and Computation Author :
Shyamalendhu Kandar

Instructions
• Should include the definition of each problems.
• It is more better to include the figures with caption and title.
• If the document is in "Latex" it is more better.
• Please note the rubric given to get the full marks for document submission.

Regular Expressions
Regular expressions is set of strings in a particular language which can
be accepted using finite automata.

Binary numbers that are twice as odd number


Ans):

Binary strings containing the sequence 011

Ans):(0+1)*+(011)*

Binary strings containing at least one 00 and at least one 11

Ans)(0*(00)*(11)*1*)*

Binary strings with at least two consecutive 1”s , the two occurrences
not being adjacent
Ans)(0*(11)*0*)*

Strings over{a,b,c} in which the fourth symbol from the beginning is ac


Ans):

Binary strings in which every 0 is followed by 11


Ans): 1*(011*)*1*

Convert the NFA shown below into NFA without Ɛ moves?

Ans:
Ɛ closure q0 = { q0}
Ɛ closure q1 = {q1,q2}
Ɛ closure q2 = {q2}
Ɛ closure q3 = {q0,q3}
̂𝛿 (q0,0) :- Ɛ( ̂𝛿 ( ̂𝛿 (q0,Ɛ),0))
:- Ɛ( ̂𝛿 (q0,0))
:-Ɛ(q1,q0)
:-{q0,q1,q2}
̂𝛿 (q0,1) :- Ɛ( ̂𝛿 ( ̂𝛿 (q0,Ɛ),1))
:- Ɛ( ̂𝛿 (q0,1))
̂𝛿 (q1,0) :- Ɛ( ̂𝛿 ( ̂𝛿 (q1,Ɛ),0))
:- Ɛ( ̂𝛿 (q1,q2),0)
̂𝛿 (q1,0) :- Ɛ( ̂𝛿 ( ̂𝛿 (q1,Ɛ),1))
:- Ɛ( ̂𝛿 (q1,q2),1)
:-Ɛ(q3)
:- { q3,q0 }
̂𝛿 (q2,0) :- Ɛ( ̂𝛿 ( ̂𝛿 (q2,Ɛ),0))
:- Ɛ( ̂𝛿 (q2,0))
̂𝛿 (q2,1) :- Ɛ( ̂𝛿 ( ̂𝛿 (q2,Ɛ),1))
:- Ɛ( ̂𝛿 (q2,1))
:-Ɛ(q2)
:- { q3,q0 }
̂𝛿 (q3,0) :- Ɛ( ̂𝛿 ( ̂𝛿 (q3,Ɛ),0))
:- Ɛ( ̂𝛿 (q3,q0),0)
:-Ɛ(q0, q1)
:- { q0,q1,q2 }
̂𝛿 (q3,1) :- Ɛ( ̂𝛿 ( ̂𝛿 (q3,Ɛ),1))
:- Ɛ( ̂𝛿 (q3,q0),1)
:-Ɛ(q3)
:-Ɛ(q3 q0,)

Draw a finite state machine that accepts the compliment of the language
accepted by the non-deterministic machine given below.
Ans:
Construct the minimized DFA for the NFA given below.

Ans: Ɛ. Closure (q0) :- { q1,q5}


Ɛ. Closure (q1) :- { q1,q2}
Ɛ. Closure (q2) :- { q2}
Ɛ. Closure (q3) :- { q2,q3,q4}
Ɛ. Closure (q4) :- { q4,q9}
Ɛ. Closure (q5) :- { q5,q6}
Ɛ. Closure (q6) :- { q6,q7}
Ɛ. Closure (q7) :- { q6,q7,q8}
Ɛ. Closure (q8) :- { q8,q9}
Ɛ. Closure (q9) :- {q9}

𝛿̂ (q0,0) :- (𝛿̂ (q0, Ɛ),0)


:- (𝛿̂ (q1, q5),0)
𝛿̂ (q0,1) :- (𝛿̂ (q0, Ɛ),1)
:- (𝛿̂ (q1, q5),1)
𝛿̂ (q1,0) :- (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̂ (q8, Ɛ),1)
:- (𝛿̂ (q8,q9),1)
𝛿̂ (q9,0) :- (𝛿̂ (q9, Ɛ),0)
:- (𝛿̂ (q9,0))
𝛿̂ (q9,1) :- (𝛿̂ (q9, Ɛ),1)
:- (𝛿̂ (q9,1))

Construct the minimized DFA for the NFA given below.


Ans:
ɛ closure (q1) :- { q1,q2,q4}
ɛ closure (q2) :- { q2 }
ɛ closure(q3) :- { q2 q3 q4}
ɛ closure(q4) :- { q4 }

δ(q1,0):- (δ(q1, ɛ),0)


:- (δ(q1, q2, q4 ),0)
= ɛ closure(q3)
= { q2 q3 q4}

δ(q2,0):- (δ(q2, ɛ),0)


:- (δ( q2 ),0)
= ɛ closure(q3)
= { q2 q 3 q 4 }

δ(q3,0):- (δ(q3, ɛ),0)


:- (δ( q2 ,q4 ),0)
= ɛ closure(q3)
= { q2 q3 q4}

δ(q4,0):- (δ(q4, ɛ),0)


:- (δ( q4 ),0)
Construct the DFA for a language that accepts all strings in which every
fourth symbol is the same as the first symbol.
Ans:

CONTEXT FREE GRAMMER (CFG)


CFG can be dened as G=(V,T,P,S)
where V is a set of non terminals,
T is a set of terminals,
P is a set of productions
S is a set of Symbols.
In CFG the LHS of each rules there is only one non-terminal that is no
context is added with it. That's why this type of grammer is known as
Context Free Grammer.

To generate a string of terminal symbols from a CFG, we:


Begin with a string consisting of the start symbol;
Apply one of the productions with the start symbol on the left hand size, replacing the start symbol with
the right hand side of the production;
Repeat the process of selecting nonterminal symbols in the string, and replacing them with the right hand
side of some corresponding production, until all nonterminals have been replaced by terminal symbols.

EXAMPLES
A.
(a) Find the parse tree for generating the string abaabaa from the grammer given below.
S→aAS=a
A→bS
(b) Find the parse tree for generating the string aabbaa from the grammer given below.
S→aAS/a
A→SbA/SS/ba

B. Show that the following grammers are ambiguous.


(a) S→abSb/aAb/a
A→ bS/aAAb
(b) E→ E + E/E * E/id
(c) S→ aB/bA
A→ aS/bAA/a
B→ bS/aBB/b

C. Remove the useless productions from the following grammers


(a) S→AB/a
A→b
(b) S→AB/AC
A→0A1/1A0/0
B→11A/00B/AB
C→01C0/0D1
D→1D/0C

Answers:-

A.
(a)

(b)
B.
(a)
S→abSb
→abaAbb
→abaaAAbbb
→abaabSAbbb
→abaabaAbbb
→abaababSbbb
→abaabababbb

S→abSb
→abaAbb
→abaaAAbbb
→abaaAbSbbb
→abaaAbabbb
→abaabSbabbb
→abaabababbb
These grammers are ambiguous.

(b)
E→E+E
→E*E+E
→id*E+E
→id*id+E
→id*id+E*E
→id*id+id*E
→id*id+id*id

E→E+E
→E+E*E
→E+E*id
→E+id*id
→E*E+id*id
→E*id+id*id
→id*id+id*id
These grammers are ambiguous.

(c)
S→aB
→aaBB
→aabSB
→aabbAB
→aabbaSB
→aabbaaBB
→aabbaaaBBB
→aabbaaabBB
→aabbaaabbB
→aabbaaabbb

S→aB
→aaBB
→aaBb
→aabSb
→aabbAb
→aabbaSb
→aabbaaBb
→aabbaaaBBb
→aabbaaaBbb
→aabbaaabbb

C.
(a)

(b)
S→AB
A→0A1/1A0/0
B→11A/00B/AB

3.PUSHDOWN AUTOMATA (PDA)


In computer science, a pushdown automaton (PDA) is a type of
automaton that employs a stack.
Pushdown automata are used in theories about what can be computed by
machines. They are more capable than finite-state machines but less
capable than Turing machines. Deterministic pushdown automata can
recognize all deterministic context-free languages while
nondeterministic ones can recognize all context-free languages, with the
former often used in parser design.
Given a CFG, specifying the language L, we can obtain a PDA
accepting as follows:
Let L be a context-free language, therefore, there exists a context-
free grammar G = (V, T, P, S) generating L. We assume that G is in
Greibach normal form, (i.e., we are assuming that L does not contain e.
The construction given below can be modified suitably to handle the
case of L containing E.
Construct a PDA M = ((q), T, V, 8, q, S, 4), where 8 (q, a, A) contain
(q, a) for each production rule A  αa of G. Certainly M simulates the
leftmost derivation of the input string w. M accepts its input w, if and
only if w is in L (G). Hence M is a PDA accepting L (G) = L.
Therefore, we conclude that for every NDPDA M accepting by empty
stack, there exists an equivalent single state NDPDA M 1 accepting by
empty stack. The reason is since M is NDPDA, there exists a CFG G,
such that L (G) = L (M) and since for every CFG, there exists a single
state NDPA M1 as explained above accepting L (G). L (M) = L (M 1).
But this is not the case for a PDA accepting by final state, that means
PDA accepting by final state cannot always be equivalent to single
state NDPDA, because it requires a final and a non-final state.

26.For all strings ‘S’ over the alphabet {0,1},construct a PDA to accept
‘S’ where S =Reverse(S)
This use two stacks which is not possible in PDA.
27. Construct the PDA for the following set L= {abncdn /n>=1}
Ans:
δ^(q0,a,z0) :-(q1 ,z0)
δ^(q1,b,z0) :-(q2 ,bz0)
δ^(q2,b,b) :-(q2 ,bb)
δ^(q2,c,bb) :-(q3 ,cb)
δ^(q3,d,b) :-(q3 ,ɛ)
δ^(q3,ɛ,z0) :-(qf)
28)Construct the PDA for following CFG
SaB /bA
Aa/aS/bAA
Bb/bS/aBB
Here the given CFG is in GNF .So no need to reduce it to GNF
δ(q0,ε,z0):- (q1,S)
δ(q1,a,S):- (q2,B)
δ(q1,b,S):- (q3,A)
δ(q3,a,A):- (qf, ε)
δ(q3,a,A):- (q1,S)
δ(q3,b,A):- (q3,AA)
δ(q2,b,B):- (qf, ε)
δ(q2,b,B):- (q1,S)
δ(q2,a,B):- (q2,BB)

29. Convert the PDA p=({q 0,q1}.{0,1},{x,z0}, δ,q, z0) to a CFG if δ is


given by

δ(q0,0,z0):- {(q1,xz0)}
δ(q1,c,x):- (q1,C)
δ(q0,1,x):- {(q1,C)}
δ(q1,,1,x):- {(q1, C)}
δ(q0,0,x):-{(q0,xx)}
δ(q1,C, z0):- {(q1,C)}
δ(q2,b,B):- (qf, ε)
δ(q2,b,B):- (q1,S)
δ(q2,a,B):- (q2,BB
ANS:
The starting two states:
S [q0,z0,q0]
S [q0,z0,,q1 ]

From (q0,0,z0)=q0,x,z0 we get:


[q0,z0,q0] 0[q0,x,q0][q0,z0,q0]
[q0,z0,q0] 0[q0,x,q1][q1,z0,q0]
[q0,z0,q1] 0[q0,x,q0][q0,z0,q1]
[q0,z0,q1] 0[q0,x,q1][q0,z0,q1]
From (q1,C,x)=(q1,C) we get
[q1,x,q1] C
From (q0,1,x)=(q0,C) we get
[q0,x,q1] 1
From (q1,1,x)=(q1,C) we get
[q1,x,q1] 1
From (q0,0,x)=(q0,xx) we get
[q0,0,q0] 0[q0,x,q0][q0,x,q0]
[q0,0,q0] 0[q0,x,q1][q1,1,q0]
[q0,0,q1] 0[q0,x,q0][q0,x,q1]
[q0,0,q1] 0[q0,x,q1][q1,x,q1]

From (q1,C,z0)=(q1,C) we get


[q1,z0,q1] C

Renaming these values to alphabets we get:


[q0,z0,q0] A
[q0,z0,,q1 ] B
[q0,x,q0] D
[q0,z0,q0] E
[q0,x,q1] F
[q1,z0,q0] G
[q0,x,q0] H
[q0,z0,q1] I
[q0,x,q1] J
[q0,z0,q1] K
[q1,x,q0] L
[q1,x,q1] M
[q1,z0,q1] N
[q0,0,q0] P
[q0,0,q1] R
[q1,1,q0] S
After substituting our rule becomes:
S A
S B
A 0DE
A 0FG
I 0HJ
K 0JI
M C
J 1
M 1
P 0HH
P 0FS
R 0DJ
Q 0JM
N C

30.Construct a NPDA that accepts the language L={anbm /n!=m,n>=0}


Ans:
δ^(q0,a,z0) :-(q1 ,z0a)
δ^(q1,a,a) :-(q1 ,aa)
δ^(q1,b,a) :-(q2 ,ε)
δ^(q2,b,a) :-(q2 , ε)
δ^(q2,b,b) :-(q2 , ε)
δ^(q2, ε ,b) :- (qf)
δ^(q2,b,z0) : (q3 , z0b)
δ^(q3,b,b ):-(qf)
31.Construct a context-free grammar G which accepts N(A), where A =
(q0,q1,a, b, Z0,Z, d,qo,Zo,f ) and δ is given by:
(q0,b,z0)=(q0,zzo)
(q0,2,z0)=(q0,2)
(q0,a,z)=(q1,z)
(q1,b,z)=(q1,2)
(q1,a,z0)=(q0,z0)
(q0,b,z)=(qo,zz)
ANS:
The starting two states:
S ®[q0,z0,q0]
S®[q0,z0,,q1 ]

Other productions are derived from transitions like :


d(q0,b,Z0)=(q0,ZZ0) .
Each set denotes transitions from each transition rule.

[q0,Z0,q0] ®b[q0,Z,q0] [q0,Z0,q0]


[q0,Z0,q0] ®b[q0,Z,q1] [q1,Z0,q1]
[q0,Z0,q1] ® b[q0,Z,q0] [q0,Z0,q1]
[q0,Z0,q1] ® b[q0,Z,q1] [q1,Z0,q1]

[q0,Z0,q0]®A

[q0,Z,q0]®b[q0,Z,q0][q0,Z,q0]
[q0,Z,q0]®b[q0,Z,q1][q1,Z,q0]
[q0,Z,q0]®b[q0,Z,q0][q0,Z,q1]
[q0,Z,ql]®b[q0,Z,ql][q1,Z,q1]

[q0,Z,q0]®a[q-1,Z,q0]
[q0,Z,q1]®a[q-1,Z,q1]
[ql,Z,q1]®b

[q1,Z0,q0]®a[q0,Z0,q0]
[ql',Z0,ql]®a[q0,Z0,ql]
The rest of the steps are the same of Question 29 only difference is
number of contexts and grammar defined.

TURING MACHINE
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, qF)
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
qF is the set of final states
EXAMPLES:-
1. Design a Turing Machine which acts as a eraser.
2. Design a Turing Machine which replaces '0' by '1' and '1' by '0' of the
string traversed.

3. Design a Turing Machine to accept the string L = {anbmcn+m, where


n>0, m>0}
4. Design a Turing Machine to accept the string L = {a mbm+ncn, where
n>0, m>0}
ANSWERS:-
1. Example:-
δ(q0 ,x):- (q1,B,R) (q0,BxxxxB)
δ(q1 ,x):- (q0,B,R) (q1,BBxxxB)
δ(q0 ,B):- (qF,B,H) (q0,BBBxxB)
δ(q1 ,B):- (qF,B,H) (q1,BBBBxB)
(q0,BBBBBB) --------------- Hault
2. Example:-
δ(q0 ,0):- (q1,1,R) (q0,B0011101B)
δ(q0 ,1):- (q2,0,R) (q1,B1011101B)
δ(q1 ,0):- (q0,1,R) (q0,B1111101B)
δ(q1 ,1):- (q0,0,R) (q2,B1101101B)
δ(q2 ,0):- (q0,1,R) (q0,B1100101B)
δ(q2 ,1):- (q0,0,R) (q2,B1100001B)
δ(q0 ,B):- (qF,B,H) (q0,B1100011B)
δ(q1 ,B):- (qF,B,H) (q2,B1100010B) ------------ Hault
δ(q2 ,B):- (qF,B,H)

3.
δ(q0 ,a):- (q1,B,R) (q0,BabbcccB)
δ(q1 ,a):- (q1,a,R) (q1,BBbbcccB)
δ(q1 ,b):- (q1,b,R) (q1,BBbbcccB)
δ(q1 ,c):- (q1,c,R) (q1,BBbbcccB)
δ(q1 ,B):- (q2,B,L) (q1,BBbbcccB)
δ(q2 ,c):- (q3,B,L) (q1,BBbbcccB)
δ(q3 ,c):- (q3,c,L) (q1,BBbbcccB)
δ(q3 ,b):- (q3,b,L) (q2,BBbbcccB)
δ(q3 ,a):- (q3,a,L) (q3,BBbbccB)
δ(q3 ,B):- (q0,B,R) (q3,BBbbccBB)
δ(q0 ,b):- (q4,B,R) (q3,BBbbccBB)
δ(q4 ,b):- (q4,b,R) (q3,BBbbccBB)
δ(q4 ,c):- (q4,c,R) (q3,BBbbccBB)
δ(q4 ,B):- (q5,B,L) (q0,BBbbccBB)
δ(q5 ,c):- (q6,B,L)
δ(q6 ,c):- (q6,B,L) (q4,BBBbccBB)
δ(q6 ,b):- (q6,c,L) (q5,BBBbccBB)
δ(q6 ,B):- (q6,b,L) (q6,BBBbcBBB)
δ(q6 ,B):- (q0,B,R) (q0,BBBbcBBB)
δ(q0 ,B):- (qF,B,H) (q4,BBBBcBBB)
(q5,BBBBcBBB)
(q6,BBBBBBBB)
(q0,BBBBBBBB)
H

You might also like