Professional Documents
Culture Documents
Regular Expression
aba bab
( a)b
(a ba bb)?
? a ? b ? a ?
Belongs
aba, bab
b, ab
a, ba, bb
aabaa, aba
Q4. Draw the state diagram for the following transition table:
q1
q2
?q3
q4
q5
u
q1
q1
q2
q3
q4
Page 1 of 4
d
q2
q3
q4
q5
q5
u
u
q2
d
d
q3
start
q1
d
d
q4
q5
u
Q5. Construct DFAs for the following languages defined on the binary alphabet {0, 1}:
(a) L = {w|w does not contain 110}
0,1
0
start
1
1
DEAD
0
(b) L = {w|w contains at least two 0s and at most one 1}
The following two DFAs accepts strings with at least two 0s and at most one 1 respectively.
Then we can combine them to construct a new DFA that accepts L.
1
start
start
0,1
0,1
0
1
Combining the two DFAs, we get the following transition table for a new DFA that accepts
strings with at least two 0s and at most one 1.
AD
AE
AF
BD
BE
BF
? CD
? CE
CF
0
BD
BE
BF
CD
CE
CF
CD
CE
CF
Page 2 of 4
1
AE
AF
AF
BE
BF
BF
CE
CF
CF
CD
0
1
0
BD
CE
0
start
AD
0,1
BE
CF
AE
0
BF
0
1
AF
1
Notice that AF and BF are redundant dead states because once we have seen more than one 1,
we do not need to keep track of the number of 0s seen. We can directly have arrows labeled 1
going from AE and BE to CF. Which is the DFA we get from the idea I discussed in class. This
DFA as shown below is smaller with only 7 states.
State
AD
AE
BD
BE
CD
CE
CF
Num of 0s seen
0
0
1
1
2+
2+
Dont care
Num of 1s seen
0
1
0
1
0
1
2
CD
0
1
0
BD
CE
0
start
AD
0,1
1
BE
CF
1
AE
Q6. Construct -NFAs for the following languages defined over the binary alphabet {0, 1}:
Page 3 of 4
(a) L1 L2 where L1 is the language of all strings that contain 0101 as a substring, and L2 is the
language of all strings that do not contain 110.
0+1
0+1
0
start
0+1
1
H
0
(b) L1 L2 where L1 is the language of all strings with at least three 1s, and L2 is the language of
all strings of length at most three.
0
start
0
1
0+1
0
1
0+1
0+1
0+1
(c) L?1 where L1 is the language of all strings with 1 at every odd position.
0+1+
start
C
0
0+1
Page 4 of 4
0+1
0+1