# Theory of Automata - Solved Assignments - Semester Spring 2010

date post

10-Apr-2015Category

## Documents

view

6.362download

36

Embed Size (px)

description

### Transcript of Theory of Automata - Solved Assignments - Semester Spring 2010

Theory of Automata Solved Assignments Semester Spring 2010Assignment 1

Question No.1

Marks: 4

a) Give regular expressions of the following languages over ={0,1}: 1. All strings having no pair of consecutive zeros. 2. All strings having exactly two 1s or three 1s not more than it. b) Show that the Regular expression ^ + 0(0+1)*+(0+1)*00(0+1)* is equivalent to ((0*1)*01*)* Solution: a) 1. RE for the language having all strings having no pair of consecutive zeros. (1 + 01)*(0 + 1*) Other possibilities might be (1 + 01)*(0 + ) + 1* or (1 + 01)* + (1 + 01)*0 + 1*

2. RE for the language having all strings having exactly two 1s or three 1s not more than it.

0*10*10* + 0*10*10*10*

b) After generating the string from both regular expressions : ^ + 0(0+1)*+(0+1)*00(0+1)*= ^, 0, 00, 01,001,010,100,011,000,0011,1100 ((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. Question No. 2 Marks: 4

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 Step2: if x is in ODD, then x+2 and x-2 are also in ODD Step3: No Strings except those constructed above, are allowed to be in ODD b) Step1: a and b are in PALINDROME. Step2: if x is in PALINDROM then axa and bxb are also in PALINDROME Step3: No Strings except those constructed above, are allowed to be in PALINDROME

Question No. 3

Marks: 6

Three Finite Automata (FAs) have been given below:

FA1

FA2

FA3

Match the following Regular Expressions (REs) with corresponding Finite Automata (FAs) given above. Also describe their languages (in English).

Regular Expression a(aa)*(^+a)b+b aa*b(aa*b)*

Finite Automaton (FA)

Language Description

(a+b)*a(a+b)*b(a+b)*

Solution:

Regular Expression a(aa)*(^+a)b+b

Finite Automaton (FA) FA3

Language Description All strings in which b occurs only one time and that is only at the end of the string.

aa*b(aa*b)*

FA1

All strings which begins with a and ends at b and not containing the substring bb.

(a+b)*a(a+b)*b(a+b)*

FA2

All strings having substring ab.

Question No. 4

Marks: 6

Build an FA over ={a, b} that accepts only those words that do not contain the substring ba. Also make transition table for that FA.

Solution: FA

Transition table corresponding to above FA

New States Old States q0q1+ q2 q3+ After Reading a q3 q2 q2 q3 After Reading b q1 q1 q2 q1

Assignment 2

Question No.1

Find the Regular Expression corresponding to the given FA. Show all steps. [Hint: FA to GTG a GTG to RE.]

Mark: 5

Solution:

Step1:

Step2: Eliminating loop from q1

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

Hence the Required RE is

((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 accepts the language a*

Question No. 3

Determine RE corresponding to the following TG. Show all steps. [Hint: TG to GTG a GTG to RE.]

Mark: 10

Solution:

Step 1: By eliminating states 7,8,10,11

Step 2: By eliminating states 6

Step 3: By eliminating states 9 and 12

Step 4: By combining loops at state 3

Step 5: By eliminating states 2

Step 6:

By eliminating states 4

Step 7: By eliminating states 3

Hence the Required RE is ba(abba+aabb)*(b+)ab

Assignment 3

Question No 1: Let r1= (a+b)*ab(a+b)*

Marks: 12

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

Using the FAs corresponding to r1 and r2, Build an FA corresponding to

a) r1+ r2 (Union of r1 and r2). b) r1r2 (Concatenation of r1 and r2). c) r1* (Closure of r1).

Note :You have to specify transition table and transition diagram for each part(a)(b)(c)

Solution: a) Transition table corresponding to required FA

Old States

New states after reading a b

z1 ( x1 , y1 ) z2 ( x2 , y1 ) z3 + ( x1 , y2 ) z4 + ( x3 , y2 ) z5 ( x1 , y3 ) z6 + ( x3 , y3 ) z7 + ( x3 , y1 ) z8 ( x2 , y3 )

( x2 , y1 ) z2 ( x2 , y1 ) z2 ( x2 , y1 ) z2 ( x3 , y1 ) z7 ( x2 , y3 ) z8 ( x3 , y3 ) z6 ( x3 , y1 ) z7 ( x2 , y3 ) z8

( x1 , y2 ) z3 ( x3 , y2 ) z4 ( x1 , y3 ) z5 ( x3 , y3 ) z6 ( x1 , y3 ) z5 ( x3 , y3 ) z6 ( x3 , y2 ) z4 ( x3 , y3 ) z6

FA corresponding to r1+ r2

b) Transition table corresponding to required FA

Old States

New states after reading a b

z1 x1 z2 x2 z3 ( x3 , y1 ) z4 + ( x3 , y1 , y2 ) z5 + ( x3 , y1 , y2 , y3 ) z6 ( x3 , y1 , y3 )

x2 z2 x2 z2 ( x3 , y1 ) z3 ( x3 , y1 ) = z3 ( x3 , y1 , y3 ) z6 ( x3 , y1 , y3 ) z6

x1 z1 ( x3 , y1 ) z3 ( x3 , y1 , y2 ) = z4 ( x3 , y1 , y2 , y3 ) z5 ( x3 , y1 , y2 , y3 ) z5 ( x3 , y1 , y2 , y3 ) z5

FA corresponding to r1r2

c) Transition table corresponding to required FA

Old States

New states after reading a b

Final z1 x1 Non-final z2 x1

x2 z3 x2 z3 x2 z3 ( x3 , x1 , x2 ) z5 ( x3 , x1 , x2 ) z5

x1 z2 x1 z2 ( x3 , x1 ) z4 ( x3 , x1 ) = z4 ( x3 , x1 ) = z4

z3 x2 z4 + ( x3 , x1 ) z5 + ( x3 , x1 , x2 )

FA corresponding to r1*

Question No 2:

Marks: 4

Convert the following NFA into FA.

Solution: Transition table corresponding to required FA

Old States

New states after reading a b

z1 = 0 z2 + (1, 2) z3 + (1, 2,3) z4 + (1,3)

(1, 2) z2 (1, 2,3) z3 (1, 2,3) z3 (1, 2,3) z3

(1,3) z4 (1,3) z4

FA corresponding to given NFA

Question No 3:

Marks: 4

Build an NFA equivalent to the FA* where

FA

Solution: NFA equivalent to the FA* where

Assignment 4

Question No 1:

Marks: 5

Let L be the language of strings defined over = {0, 1} having odd no. of 1s.Now Find Distinguishable and Indistinguishable strings by taking z as 1 belonging to *.

Solution:

x 11000 00000 10010 10011 00111

y 10000 11111 00110 10000 10111

Distinguishable/Indistinguishable Distinguishable Distinguishable Indistinguishable Indistinguishable Distinguishable

Question No 2: Marks:10 Convert the following Moore machine to an equivalent Mealy machine:

a) Construct transition table for Mealy machine. b) Run the string babaaba on both machines and find the output. Solution: Mealy machine corresponding to Moore machine

a) Transition table for Mealy machine. input States Output q0 1 a Next State q2 Output 0 b Next State q1

q1 q2 q3

1 0 0

q2 q3 q3

0 1 0

q3 q2 q3

b) Run the string babaaba on both machines and find the output. Input States Mealy Moore 1 q0 b q1 0 0 a q2 1 1 b q2 1 1 a q3 0 0 a q3 0 0 b q3 0 0 a q3 0 0

Question No 3: Marks:5 Using De-Morgans law determine an FA corresponding to FA1FA2

FA1:

FA2:

Solution:

FA1c:

FA2c:

Transition table for FA1c U FA2c

New States After Reading Old states a b

z1 (x0,y0) z2 + (x1,y0) z3+ (x1,y1) z4+ (x0, y1) z5 (x0,y2) z6+ (x1,y2)

z2 (x1,y0) z1 (x0,y0) z5 (x0,y2) z6 (x1,y2) z6 (x1,y2) z5 (x0,y2)

z3 (x1,y1) z4 (x0,y1) z4 (x0,y1) z3 (x1,y1) z6 (x1,y2) z5 (x0,y2)

FA corresponding to FA1c U FA2c

FA corresponding to ( FA1c U FA2c)c = FA1 FA2

Assignment 5

Question No 1:

Marks: 5

Find the prefixes of Q in R where Q and R are languages give below:

Q={ ababa , aabbbbbbb,baabba , babbaaaaaa }

R={ aababa , bbaabba , bbaababa, aaaabbbbbbb, abbabbaaaaaa}

Solution:

Pref(Q in R)={a,b,aa,ab,bba, }

Question No. 2

Marks: 5

By marking the states, decide whether the following FA accepts any word or not?

Note: Show all steps

Solution:

Marking and processing state q0

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.

Question No. 3

Marks: 5

Describe the language (in English) generated by the following CFG:

S XY X aX | bX | Y baa | bab | bba | bbb

Solution:

The given CFG generates the language L = {w {a, b}*: length(w) 3 and third letter of w, from right is b.

Question No. 4

Marks: 5

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

Recommended

*View more*