EXTRA_flta_dfa_quest..

advertisement
1. Which of the following strings 0001, 01001, 0000110 are accepted by the dfa in Figure 2.1?
0
0
1
q0
q1
q2
1
2.
0
1
For  = {a, b} construct dfa’s that accepts the sets consisting of
a. all strings with exactly one a.
As done in class:
a,b
b
b
a
q0
q1
a
q2
b. all strings with at least one a.
b
a, b
a
q0
q1
c. all strings with no more than three a’s. (notice how the states indicate # of a’s).
b
b
a
q0
b
b
a
a
q2
q1
a,b
a
q3
q4+
d. all strings with at least one a and exactly two b’s.
e. all the strings with exactly two a’s and more than two b’s.
a
q00
q10
b
q01
a
q11
a
b
q02
a
a
q02+
a
q12
q21
a
a
q22
a
q2+1
a
a
q2+2
a
b
q22+
b
a
b
b
q12+
q2+0
b
b
b
b
q20
b
b
b
b
a
a
q2+2++
a,b
Give dfa’s for the languages
a. L = {ab5wb2 : w  {a, b}*}
a
a
b
a
b
b
b
a
a
a
b
b
a
b
b
b
a
a
a,b
b. L = { abnam : n ≥ 2, m ≥ 3}
a
a
a
b
b
a
b
b
a
b
a
b
a
b
a,b
a,b
c.
L = {w1abw2 : w1  {a, b}*, w2  {a, b}*}
This is any string containing ab somewhere in it.
b
a
a,b
b
a
7. Find dfa’s for the following languages on  = {a, b}
a. L = {w : |w| mod 3 = 0}
a,b
0
1
a,b
a,b
2
b. L = {w : |w| mod 5  0}
1
0 a,b
a,b
2
a,b
4
3
a,b
a,b
c. L = {w : na(w) mod 3 > 1}
b
b
a
1
0
a
a
2
b
d. L = {w : na(w) mod 3 > nb(w) mod 3}
a
b
b
a
01
a
10
00
b
b
a
a
b
02
b
a
11
b
a
20
21
b
b
a
12
22
a
L = {w : (na(w) – nb(w)) mod 3 > 0}
L = {w : (na(w) + 2nb(w)) mod 3 < 2}
e.
f.
8. A run in a string is a substring of length at least two, as long as possible and consisting entirely of the same
symbol. Find dfa’s for the following languages over {a, b}:
a. L = {w: w contains no runs of length less than four}
a
a

aa
a
aaa
a
b
b
a
a
b
b
b
a
a
b
trap
a,b
b
a
aaaa
a
bb
b
b
bbb
b
bbbb
b. L = {w: every run of a’s has a length of either two or three}
b
a
a
b
b
a,b
a
a
b
c. L = {w : there are at most two runs of a’s of length three}
b
a
a
b
a
b
a
1
b
a
b
2+
b
b
b
a
0
a,b
a
b
b
2
a
a
a
b
a
a
b
b
a
b
a
State 0: no runs, State 1: one run, State 2: two runs, State 3: more than two runs (reject)
d. L = {w : there are exactly two runs of a’s of length three}
Same as in part c, but only state 2 and the previously accepting states after it would now be
accepting.
9. Consider the sets of strings on {0, 1} defined by the requirements below. Construct dfa’s.
a. Every 00 is followed immediately by a 1
1
0
0
0,1
0
1
1
b. all strings containing 00 but not 000
1
0,1
0
0
1
0
0
1
c. The leftmost symbol differs from the rightmost
0
1
1
0
0
0
1
0
1
1
d. Every substring of four symbols has at most two 0’s
0
0
1
e. All strings of length five or more in which the fourth symbol from the right end is different than
the leftmost symbol.
f. All strings in which the leftmost two symbols and the righmost two symbols are identical.
g. All strings of length four or greater in which the leftmost 3 symbols are the same, but different from
the rightmost symbol.
10. Construct a dfa that accepts strings on {0, 1} if and only if the value of the string, viewed as the binary
representation of a number, is equal to zero modulo 5.
1
0
0
1
0
0
1
0
1
2
1
4
3
1
0
11. Show that the language L = {vwv: v, w  {a,b}*. |v| = 2} is regular.
a.b a
a
a.b
a
b
a
a.b
b
a.b
b
a
b
a
b
a
b
b
12. Show that L = {an: n  4} is regular.
a
a
a
a
a
a
13. Show that the language L = {an: n  0, n  4} is regular.
a
a
a
a
a
a
14. Show that the language L = {an: n is either a multiple of three or a multiple of 5} is regular.
a
a
a
a
a
a
4
1
5
6
2
7
a
3
a
0
8
a
a
a
a
a
a
a
10
13
11
14
9
12
Since 15 is the least common multiple of 3 and 5, we can do modulo 15 arithmetic with the accepting states as
shown above.
15. Show that the language L = {an: n is a multiple of three but not a multiple of 5} is regular.
Download