Professional Documents
Culture Documents
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
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.
Ans):(0+1)*+(011)*
Ans)(0*(00)*(11)*1*)*
Binary strings with at least two consecutive 1”s , the two occurrences
not being adjacent
Ans)(0*(11)*0*)*
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.
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
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
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)
δ(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 ]
[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.
δ(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