Sei sulla pagina 1di 12

Assignment 1

Theory of Automata
CSE273

To: Dr. Sifat Momen(SFM1)

Name: Ajay Ghosh


ID: 1331205642
Sec: 2
P
1.(a). Strings over = {0, 1} that end with only one 1 are accepted. For
example, the string 011011 is not accepted because the string ends with two
1’s but the string 0110101 is accepted because it ends with one 1.
P
(b). Strings over = {a, b, c} that contain the substring ab are accepted.
For example, abbcba is not accepted as the string does not contain the sub-
string ab but the string abbaba is accepted as the string contains the sub-
string ab.

2.(a). DFA for all strings over {a, b} that contains even number of a’s:

b b
a

start q0 q1

Figure 1: DFA of strings that contains even number of a’s

(b). DFA for all strings over {a, b} that contain an even number of a’s and
odd number of b’s:

start q0 q1

a
b b b b
a
q2 q3

Figure 2: DFA of strings that contain an even number of a’s and odd number
of b’s

1
(c). DFA for strings over {a, b} that start with aa and end with bb:

q0 a q1 a q2
start

b a
b a b

q5 q4 b q3

a, b b

Figure 3: DFA of strings that start with aa and end with bb

3. Corresponding Regular Expression(RE) for DFA of strings that contains


even number of a’s [2(a)]:

q0 =  + q0 b + q1 a
q1 = q0 a + q1 b
= q0 ab∗

q0 =  + q0 b + q1 a
=  + q0 b + q0 ab∗ a
=  + q0 (b + ab∗ a)
= (b + ab∗ a)∗
= (b + ab∗ a)∗
∴ RE = (b + ab∗ a)∗

2
Corresponding RE for DFA of strings that contain an even number of a’s and
odd number of b’s [2(b)]:

q0 =  + q 1 a + q2 b
q1 = q0 a + q3 b
q2 = q0 b + q 3 a
q3 = q1 b + q 2 a

q1 = q0 a + q3 b
= ( + q1 a + q2 b)a + q3 b
= a + q1 aa + q2 ab + q3 b
= a + q1 aa + q2 ab + q1 bb + q2 ab
= a + q2 ab + q2 ab + q1 aa + q1 bb
= a + q2 ab + q2 ab + q1 (aa + bb)
= (a + q2 ab + q2 ab)(aa + bb)∗
= a(aa + bb)∗ + q2 ab(aa + bb)∗ + q2 ab(aa + bb)∗

q0 =  + q1 a + q2 b
=  + a(aa + bb)∗ a + q2 ab(aa + bb)∗ a + q2 ab(aa + bb)∗ a + q2 b

q3 = a(aa + bb)∗ b + q2 ab(aa + bb)∗ b + q2 ab(aa + bb)∗ b + q2 a

q2 = q0 a + q 3 b
=  + a(aa + bb)∗ aa + q2 ab(aa + bb)∗ aa
+ q2 ab(aa + bb)∗ aa + q2 ab + a(aa + bb)∗ bb
+ q2 ab(aa + bb)∗ bb + q2 ab(aa + bb)∗ bb + q2 ab
=  + q2 (a(aa + bb)∗ aa
+ ab(aa + bb)∗ aa + ab(aa + bb)∗ aa
+ ab + a(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab)

3
= (a(aa + bb)∗ aa
+ ab(aa + bb)∗ aa + ab(aa + bb)∗ aa
+ ab + a(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab)∗

= (a(aa + bb)∗ aa + ab(aa + bb)∗ aa


+ ab(aa + bb)∗ aa + ab + a(aa + bb)∗ bb
+ ab(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab)∗

∴ RE = (a(aa + bb)∗ aa + ab(aa + bb)∗ aa


+ ab(aa + bb)∗ aa + ab + a(aa + bb)∗ bb
+ ab(aa + bb)∗ bb + ab(aa + bb)∗ bb + ab)∗

4
Corresponding RE for DFA of strings that start with aa and end with bb
[2(c)]:

q0 = 
q 1 = q0 a
=
=a
q 2 = q1 a + q2 a + q3 a + q4 a
q 3 = q2 b
q 4 = q3 b + q4 b
= q3 bb∗

∴ q2 = aa + q2 a + q3 a + q4 a
= aa + q2 a + q2 ba + q3 bb∗
= aa + q2 a + qa b + q2 bbb∗
= aa + q2 (a + ab + bbb∗ )
= aa(a + ab + bbb∗ )∗

∴ q4 = q3 bb∗
= q2 bbb∗
= aa(a + ab + bbb∗ )∗ bbb∗
∴ RE = aa(a + ab + bbb∗ )∗ bbb∗

5
4.(a) NFA of strings over {a, b} that have an a as one of the last 3
characters:

b
a, b

a a, b a, b
start q0 q1 q2 q3

Figure 4: NFA of strings that have an a as one of the last 3 characters

(b). NFA of All strings over {E, G, L, O, X}that contain the regular
expression GO∗ GLE:

E, G, L, O, X O

q0 G q1 O q2 G q3
start

q5 E q4

E, G, L, O, X

Figure 5: NFA for all strings that contain the regular expression GO∗ GLE

6
5. State transition table corresponding to the NFA designed in 4(a):

a b
A φ φ
B  {q0 } {q0 , q1 } {q0 }
*C {q1 } {q2 } {q2 }
*D {q2 } {q3 } {q3 }
*E {q3 } {q1 } {q0 }
*F {q0 , q1 } {q0 , q1 , q2 } {q0 , q2 }
*G {q0 , q2 } {q0 , q1 , q3 } {q0 , q3 }
*H {q0 , q3 } {q0 , q1 } {q0 }
*I {q1 , q2 } {q2 , q3 } {q2 , q3 }
*J {q1 , q3 } {q1 , q2 } {q0 , q2 }
*K {q2 , q3 } {q1 , q3 } {q0 , q3 }
*L {q0 , q1 , q2 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }
*M {q0 , q2 , q3 } {q0 , q1 , q3 } {q0 , q3 }
*N {q0 , q1 , q3 } {q0 , q1 , q2 } {q0 , q2 }
*O {q2 , q2 , q3 } {q1 , q2 , q3 } {q0 , q2 , q3 }
*P {q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }

Table 1: State transition table for Figure 4

7
Now, DFA from state transition table:

b a

a a a
start B F L P

a b
b b a b
a
b a
H G N M
b
b

Ö
ÖX
F

ÖXX
L

ÖÖÖÖ
P

ÖÖÖÖÖ
H

ÖXXXÖÖ
G

ÖÖÖÖÖXÖ
N
M
B F L P H G N

Minimized DFA for [4.(a)]:

a
b

a
start {B} {F, L, P, N }

a b
b
a
b
{H} {G, M }

8
5. State transition table corresponding to the NFA designed in 4(b):

E G L O X
1 φ φ φ φ φ
2  {q0 } {q0 } {q0 , q1 } {q0 } {q0 } {q0 }
3 {q1 } {φ} {φ} {φ} {q2 } {φ}
4 {q2 } {φ} {q3 } {φ} {q2 } {φ}
5 {q3 } {φ} {φ} {q4 } {q2 } {φ}
6 {q4 } {q5 } {φ} {φ} {φ} {φ}
*7 {q5 } {q5 } {q5 } {q5 } {q5 } {q5 }
8 {q0 , q1 } {q0 } {q0 , q1 } {q0 } {q0 , q2 } {q0 }
9 {q0 , q2 } {q0 } {q0 , q1 , q3 } {q0 } {q0 , q2 } {q0 }
10 {q0 , q3 } {q0 } {q0 , q1 } {q0 , q4 } {q0 } {q0 }
11 {q0 , q4 } {q0 , q5 } {q0 , q1 } {q0 } {q0 } {q0 }
*12 {q0 , q5 } {q0 , q5 } {q0 , q1 , q5 } {q0 , q5 } {q0 , q5 } {q0 , q5 }
13 {q1 , q2 } {φ} {q3 } {φ} {q2 } {φ}
14 {q1 , q3 } {φ} {φ} {q4 } {q2 } {φ}
15 {q1 , q4 } {q5 } {φ} {φ} {q2 } {φ}
24 {q0 , q1 , q3 } {q0 } {q0 , q1 } {q0 , q4 } {q0 , q2 } {q0 }
*26 {q0 , q1 , q5 } {q0 , q5 } {q0 , q1 , q5 } {q0 , q5 } {q0 , q2 , q5 } {q0 , q5 }
*29 {q0 , q2 , q5 } {q0 , q5 } {q0 , q1 , q3 , q5 } {q0 , q5 } {q0 , q5 } {q0 , q5 }
*32 {q0 , q4 , q5 } {q0 , q5 } {q0 , q1 , q5 } {q0 , q5 } {q0 , q5 } {q0 , q5 }
*47 {q0 , q1 , q3 , q5 } {q0 , q5 } {q0 , q1 , q5 } {q0 , q4 , q5 } {q0 , q2 , q5 } {q0 , q5 }

Table 2: State transition table for Figure 5

(Note: There are 64 rows in the state transition table out of which 20
rows are shown. The rest are not shown as they are not necessary for DFA
minimization)

The DFA designed from state transition table is shown in the next page.

9
E, L, X

G O
E, L, O, X G
O
start 2 8 9
E, L ,X
G

L, O, X G
G O
E, X

L
11 24

E, L, O, X
E, L, O, X
32 12
G

L
G E, L, O, X
E, X
O
E, L, X

26 47 29
G G

G
O

Figure 6: DFA designed from Table 2


10
Ö
ÖÖ
8

ÖÖÖ
9

ÖÖÖÖ
11

ÖÖÖÖÖ
24

ÖÖÖÖÖX
32

ÖÖÖÖÖXX
12

ÖÖÖÖÖXXX
26

ÖÖÖÖÖXXXX
47
29
2 8 9 11 24 32 12 26 47

E, L, X

G O
E, L, O, X G
O
start {2} {8} {9}
E, L ,X
G

L, O, X G
G
E, X O
E, G, L, O, X
L
{11} {24} {12, 26, 29, 32, 47}

Figure 7: Minimized DFA for [4(b)]

11

Potrebbero piacerti anche