Theory of Automata - Solved Assignments - Semester Spring 2010
Theory of Automata - Solved Assignments - Semester Spring 2010
Solved Assignments
Semester Spring 2010
Assignment 1
a)
1. RE for the language having all strings having no pair of consecutive zeros.
(1 + 01)*(0 + 1*)
2. RE for the language having all strings having exactly two 1’s or three 1’s not more than it.
0*10*10* + 0*10*10*10*
((0*1)*01*)* = ^,0,00,01,10,010,100,011,101,110,000,……………..
We can see that first RE cannot generate the string ‘10’ while this string can be generated by second RE. So they are
not expressing the same language. Hence it is concluded that given Regular expressions are NOT equivalent.
a) Give recursive definition for the language ODD, of strings defined over ∑={-,0,1,2,3,4,5,6,7,8,9},
b) Give recursive definition for the language of palindromes having odd length
Solution:
a)
Step1: 1 is in ODD
b)
Step1: a and b are in PALINDROME.
FA1
FA2
FA3
Match the following Regular Expressions (RE’s) with corresponding Finite Automata (FA’s) given above. Also
describe their languages (in English).
a(aa)*(^+a)b+b
aa*b(aa*b)*
(a+b)*a(a+b)*b(a+b)*
Solution:
Build an FA over Σ={a, b} that accepts only those words that do not contain the substring “ba”.
Solution:
FA
Transition table corresponding to above FA
New States
q0- q3 q1
q1+ q2 q1
q2 q2 q2
q3+ q3 q1
Assignment 2
Question No.1
Find the Regular Expression corresponding to the given FA. Show all steps. Mark: 5
Solution:
Step1:
Step2:
Step3:
Eliminating state q1
Step4:
To connect the initial state to the final state by single transition edge, the above TG can be reduced to the following
((0+1)0*11*0 )* . (0+1)0*11*
Question No.2 Mark: 5
A student walks into a classroom and sees on the blackboard a diagram of a TG with two states that accepts only the
string Λ. The student reverses the direction of exactly one edge, leaving all other edges and all labels and all final
states (+’s) and start state (-) the same. The new TG accepts the language a*. What was the original TG?
Solution:
Original TG
accepts only Λ
New TG
Question No. 3
Determine RE corresponding to the following TG. Show all steps. Mark: 10
Solution:
Step 1:
By eliminating states 6
Step 3:
Step 4:
Step 5:
By eliminating states 2
Step 6:
By eliminating states 4
Step 7:
By eliminating states 3
Question No 1: Marks: 12
Let
r1= (a+b)*ab(a+b)*
r2= (a*ba)*a*b (The RE given in assignment was incorrect so it has been corrected now
According to the requirement of the question you had to work with FAs so mistake in RE will not effect your
solution)
FA1 corresponding to r1
FA2 corresponding to r2
Solution:
a)
a b
z1 − ≡ ( x1 , y1 ) ( x2 , y1 ) ≡ z2 ( x1 , y2 ) ≡ z3
z2 ≡ ( x2 , y1 ) ( x2 , y1 ) ≡ z2 ( x3 , y2 ) ≡ z4
z3 + ≡ ( x1 , y2 ) ( x2 , y1 ) ≡ z2 ( x1 , y3 ) ≡ z5
z4 + ≡ ( x3 , y2 ) ( x3 , y1 ) ≡ z7 ( x3 , y3 ) ≡ z6
z5 ≡ ( x1 , y3 ) ( x2 , y3 ) ≡ z8 ( x1 , y3 ) ≡ z5
z6 + ≡ ( x3 , y3 ) ( x3 , y3 ) ≡ z6 ( x3 , y3 ) ≡ z6
z7 + ≡ ( x3 , y1 ) ( x3 , y1 ) ≡ z7 ( x3 , y2 ) ≡ z4
z8 ≡ ( x2 , y3 ) ( x2 , y3 ) ≡ z8 ( x3 , y3 ) ≡ z6
FA corresponding to r1+ r2
b)
a b
z1 − ≡ x1 x2 ≡ z2 x1 ≡ z1
z2 ≡ x2 x2 ≡ z2 ( x3 , y1 ) ≡ z3
z3 ≡ ( x3 , y1 ) ( x3 , y1 ) ≡ z3 ( x3 , y1 , y2 ) = z4
z4 + ≡ ( x3 , y1 , y2 ) ( x3 , y1 ) = z3 ( x3 , y1 , y2 , y3 ) ≡ z5
z5 + ≡ ( x3 , y1 , y2 , y3 ) ( x3 , y1 , y3 ) ≡ z6 ( x3 , y1 , y2 , y3 ) ≡ z5
z6 ≡ ( x3 , y1 , y3 ) ( x3 , y1 , y3 ) ≡ z6 ( x3 , y1 , y2 , y3 ) ≡ z5
FA corresponding to r1r2
c)
a b
Final z1 ± ≡ x1 x2 ≡ z3 x1 ≡ z2
Non-final z2 ≡ x1 x2 ≡ z3 x1 ≡ z2
z3 ≡ x2 x2 ≡ z3 ( x3 , x1 ) ≡ z4
z4 + ≡ ( x3 , x1 ) ( x3 , x1 , x2 ) ≡ z5 ( x3 , x1 ) = z4
z5 + ≡ ( x3 , x1 , x2 ) ( x3 , x1 , x2 ) ≡ z5 ( x3 , x1 ) = z4
FA corresponding to r1*
Question No 2: Marks: 4
a b
z1 ± = 0 (1, 2) ≡ z2 Φ
Question No 3: Marks: 4
Solution:
Question No 1: Marks: 5
Let L be the language of strings defined over Σ= {0, 1} having odd no. of 1’s.Now Find Distinguishable and
Indistinguishable strings by taking z as “1” belonging to Σ*.
Solution:
x y Distinguishable/Indistinguishable
Question No 2:
Marks:10
Solution:
input
States a b
q0 1 q2 0 q1
q1 1 q2 0 q3
q2 0 q3 1 q2
q3 0 q3 0 q3
b) Run the string “babaaba” on both machines and find the output.
Input b a b a a b a
States q0 q1 q2 q2 q3 q3 q3 q3
Mealy 0 1 1 0 0 0 0
Moore 1 0 1 1 0 0 0 0
Question No 3:
Marks:5
FA1:
FA2:
Solution:
FA1c:
FA2c:
Old states a b
z1 ± ≡ (x0,y0) z2 ≡ (x1,y0) z3 ≡ (x1,y1)
Question No 1: Marks: 5
Solution:
Pref(Q in R)={a,b,aa,ab,bba, }
By marking the states, decide whether the following FA accepts any word or not?
Processing state q1
Processing state q3
Processing state q2
Since no new state is marked and the final state q4 is unmarked therefore, the given FA does not accept any word.
S → XY
X → aX | bX | Λ
Solution:
The given CFG generates the language L = {w ∈ {a, b}*: length(w) ≥ 3 and third letter of w, from right is b.
Construct the CFG that generates the language L = {w ∈ {a, b}*: length(w) ≥ 2 and w begins with b and ends in aa or
bb}.
Solution:
S → bXY|bb
X → aX | bX | Λ
Y → aa | bb
Assignment 6
Question: Mark:5+5+5+5
S → aY | Ybb | Y
X→Λ|a
Y → aXY | bb | XXa
Solution :
a) The CFG is said to be ambiguous if there exists atleast one word of it’s language that can be generated by
the different production trees.
The word abb can be generated by the following three different trees
S ⇒ aY S ⇒ Ybb S⇒Y
S ⇒ Xabb S ⇒ aY
S ⇒ abb S ⇒ abb
Hence it has been concluded that the given CFG is ambiguous.
Remove the null production X →Λ.The new CFG, without null productions, is:
S → aY | Ybb | Y
X →a
Y →aXY | aY | bb | XXa | Xa | a
The only unit production is S → Y, where the Y can be replaced with all Y’s non-unit productions (i.e. all of them).
X →a
Y →aXY | aY | bb | XXa | Xa | a
A →a
B →b
The new CFG, consisting of only solid non-terminals or one terminal is:
X→a
Y → AXY | AY | BB | XXA | XA | a
A→a
B→b
Shorten the strings of non-terminals to length 2.Create new, intermediate non-terminals to accomplish this.
C → BB
D → XY
E → XA
The new CFG, in CNF is:
S → AY | YC | AD | AY | BB | XE | XA | a
X→a
Y → AD | AY | BB | XE | XA | a
A→a
B→b
C → BB
D → XY
E → XA