Sie sind auf Seite 1von 19

4 Finite

Automata

Chapter 4
Finite Automata

Answer for Exercises (Page 151, Theory of Computer Science: Definitions and Examples.
3rd Ed.)

Part A Multiple Choices Questions

1. B
2. B
3. C
4. A
5. B
6. D
7. D
8. B
9. A
10. A
11. D
12. D
13. B
14. B
15. B
16. B
17. D
18. B
19. C
20. C
21. C
22. A
23. D
24. C

162 | P a g e
4 Finite
Automata

Part B Structured Questions

1. What is the meaning of error or trap state?


Non-accepting state

2. What are the characteristics of NFA compared to DFA?

Features DFA NFA


Choice of transition Single Multiple
Input label Alphabets only Alphabets or  or 
Undefined transitions No Possible

3.
a)
a, b
S O
a, b
DFA
b) [q0 , abbb] ⊢ [q1 , bbb]
⊢ [q0 , bb]
⊢ [q1 , b]
⊢ [q0 , λ]
Stop at q0 (final state) and all alphabet is traced (string is empty);
Hence, string abbb is accepted by the machine.

[q0 , bbb] ⊢ [q1 , bb]


⊢ [q0 , b]
⊢ [q1 , λ]
All alphabet is traced (string is empty) but stop at q1 (not final state) ;
Hence, string bbb is not accepted by the machine.

[q0 , baa] ⊢ [q1 , aa]


⊢ [q0 , a]
⊢ [q1 , λ]
All alphabet is traced (string is empty) but stop at q1 (not final state) ;
Hence, string baa is not accepted by the machine.

[q0 , baab] ⊢ [q1 , aab]


⊢ [q0 , ab]
⊢ [q1 , b]
⊢ [q0 , λ]
Stop at q0 (final state) and all alphabet is traced (string is empty);
Hence, string baab is accepted by the machine.

[q0 , baba] ⊢ [q1 , aba]


⊢ [q0 , ba]

163 | P a g e
4 Finite
Automata

⊢ [q1 , a]
⊢ [q0 , λ]
Stop at q0 (final state) and all alphabet is traced (string is empty);
Hence, string baba is accepted by the machine.

c) abbb, baab, and baba are accepted. bbb, baa are not accepted.
d) ((a+b) (a+b))*

4.
a) Yes, DFA.
a b a

b a
q0 q1 q2

b
b)
[q0 , abaa] ⊢ [q0 , baa]
⊢ [q1 , aa]
⊢ [q2 , a]
⊢ [q2 , λ]
Stop at q2 (final state) and all alphabet is traced (string is empty);
Hence, string abaa is accepted by the machine.

[q0 , bbbabb] ⊢ [q1 , bbabb]


⊢ [q1 , babb]
⊢ [q1 , abb]
⊢ [q2 , bb]
⊢ [q0 , b]
⊢ [q1 , λ]
All alphabet is traced (string is empty) but stop at q1 (not final state) ;
Hence, string bbbabb is not accepted by the machine.

[q0 , bababa] ⊢ [q1 , ababa]


⊢ [q2 , baba]
⊢ [q0 , aba]
⊢ [q0 , ba]
⊢ [q1 , a]
⊢ [q2 , λ]
Stop at q2 (final state) and all alphabet is traced (string is empty);
Hence, string bababa is accepted by the machine.

[q0 , bbbaa] ⊢ [q1 , bbaa]


⊢ [q1 , baa]
⊢ [q1 , aa]
⊢ [q2 , a]
⊢ [q2 , λ]
Stop at q2 (final state) and all alphabet is traced (string is empty);
Hence, string bbbaa is accepted by the machine.

164 | P a g e
4 Finite
Automata

c) abaa, bababa, and bbbaa are accepted and bbbabb is not accepted.
d) a*bb*aa*(ba*bb*aa*)* and (a*bb*aa*b)*a*bb*aa* or
a*b+a+(ba*b+a+)* and (a*b+a+b)*a*b+a+, since bb* = b+

5.
a)
b a
b
a
q0 q1 a q2
b
DFA

b) [q0 , babaab] ⊢ [q0 , abaab]


⊢ [q1 , baab]
⊢ [q2 , aab]
⊢ [q1 , ab]
⊢ [q1 , b]
⊢ [q2 , λ]
All alphabet is traced (string is empty) but stop at q2 (not final state) ;
Hence, string babaab is not accepted by the machine.

c) ( + b + (aa*(ba)*bb (b*aa*(ba)* bb)*)*)*

6.
a)
b a
b
a
q0 q1 a q2
b
DFA

b) [q0 , babaab] ⊢ [q0 , abaab]


⊢ [q1 , baab]
⊢ [q2 , aab]
⊢ [q1 , ab]
⊢ [q1 , b]
⊢ [q2 , λ]
Stop at q2 (final state) and all alphabet is traced (string is empty);
Hence, string babaab is accepted by the machine.

c) b*aa*b ((aa*b) + (bb*aa*b))*

7.
a) q0  aq1 | bq2
q1  aq0 | bq3
q2  aq3 | bq0
q3  aq2 | bq1

165 | P a g e
4 Finite
Automata

a
q0 q1
a

b b b b

a
q2 q3
a
DFA
The language consisting of all strings over {a, b} with an even number of a’s and an even
number of b’s.

b) [q0 , ab]  [q1 , b]


 [q3 , λ]
All alphabet is traced (string is empty) but stop at q3 (not final state) ;
Hence, string ab is not accepted by the machine.

[q0 , bb]  [q2 , b]


 [q0 , λ]
Stop at q0 (final state) and all alphabet is traced (string is empty);
Hence, string bb is accepted by the machine.

[q0 , aab]  [q1 , ab]


 [q0 , b]
 [q2 , λ]
All alphabet is traced (string is empty) but stop at q2 (not final state) ;
Hence, string aab is not accepted by the machine.

[q0 , baba]  [q2, aba]


 [q3, ba]
 [q1, a]
 [q0 , λ]
Stop at q0 (final state) and all alphabet is traced (string is empty);
Hence, string baba is accepted by the machine.

c) Only bb and baba.


d) (a(bb)*a + b(aa)*b)*

8.
a)
a
b
b
q0 q1 q2
b

a
b
q3

No, NFA.
b) [q0 , abbb] ⊢ [q3 , bbb]
⊢ [q3 , bb]
⊢ [q3 , b]
⊢ [q3 , λ]
Stop at q3 (final state) and all alphabet is traced (string is empty);
Hence, string abbb is accepted by the machine.

166 | P a g e
4 Finite
Automata

[q0 , bbb] ⊢ [q1 , bb]


⊢ [q2 , b]
⊢ [q1 , λ]
Stop at q1 (final state) and all alphabet is traced (string is empty);
Hence, string bbb is accepted by the machine.

[q0 , baa] ⊢ [q1 , aa]


⊢ [q1 , a]
⊢ [q1 , λ]
Stop at q1 (final state) and all alphabet is traced (string is empty);
Hence, string baa is accepted by the machine.

[q0 , baab] ⊢ [q1 , aab]


⊢ [q1 , ab]
⊢ [q1 , b]
⊢ [q2 , λ]
All alphabet is traced (string is empty) but stop at q2 (not final state) ;
Hence, string baab is not accepted by the machine.

[q0 , bbbaa] ⊢ [q1 , bbaa]


⊢ [q2 , baa]
⊢ [q1 , aa]
⊢ [q1 , a]
⊢ [q1 , λ]
Stop at q1 (final state) and all alphabet is traced (string is empty);
Hence, string bbbaa is accepted by the machine.

c) Only abbb, bbb, baa and bbbaa are accepted.


d) ab* + b (a + bb)*

9.
a)
 a b
q0 q0 q1
q1 - q1

b) abb, aab, aaaab are accepted by M


c) a*b*

10.
a) 1*01*01*
1 1 1

0 0
q0 q1 q2

b) (0 + 1)*0(0 + 1)*0(0 + 1)*

167 | P a g e
4 Finite
Automata

0, 1 0, 1 0, 1

0 0
q0 q1 q2

c) (0 + 1)*00(0 + 1)*
0, 1 0, 1

0 0
q0 q1 q2

d) abb(a + b)*
a, b

a b b
q0 q1 q2 q3

e) (a + b)*abb
a, b

a b b
q0 q1 q2 q3

f) (a + b)*abb(a + b)*
a, b a, b

a b b
q0 q1 q2 q3

11.
a)
 a b
q0 q1 q0
q1 q1 q2
q2 q0 q1

b) Only baab and abaaab are accepted by M


c) b*aa*b (ba*b + ab*aa*b)*

12.
a) b*ab*ab*
b b b a, b

a a a
q0 q1 q2 q3

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


a, b a, b a, b

a a
q0 q1 q2

c) (a + b)*(a + bb)

168 | P a g e
4 Finite
Automata

q2
a, b
b b
a
q0 q1

d) The language of all strings that begin or end with aa or bb. (aa + bb)(a + b)* + (a + b)*
(aa + bb)
e) (b + ab)*(a + )
b

a
q0 b q1
a

q2

f) (ab*a + b)*
b b
a
q0 q1
a
g)
a
q0 q1
a

b b b b

a
q2 q3
a

h) (b + ab)*aa(b + ba)*
b b

a a
q0 q2 q3

b a b a

q1 q4

i) (abb + b)*
b

a
q0 q1

b b
q2

j) (a + b)*bb(a + b)*aba(a + b)* + (a + b)*aba(a + b)*bb(a + b)*

169 | P a g e
4 Finite
Automata

a, b

a, b b a b
q1 q2 q3 q4 a, b
b a
q0 a, b q9
a b
b a b
q5 q6 q7 q8

k) (a + b)*aba(a + b)*bab(a + b)* + (a + b)*bab(a + b)*aba(a + b)*


a, b

a, b b a b a
q1 q2 q3 q4 q5 a, b
a b
q0 a, b q11
b a
a b a b
q6 q7 q8 q9 q10

13. For each of the following languages, draw an FA accepting it.


a) (a + b)*a
b) (bb + ba)*
c) (a + b)*(b + aa) (a + b)*
d) (bbb + baa)*a
e) a + ba* + ab*a
f) (a + b)*(ab + bba)
g) (b + bba)*a
h) (aba + aa)*(ba)*

14.
a) a*b*c*
The DFA
a, b, c

q3
a b a a, b
c
b c
q0 q1 q2
c

that accepts a*b*c* uses the loops in states q0, q1, and q2 to read a's, b's, and c's. Any
deviation from the prescribed order causes the computation to enter q3 and reject the
string.

b) The set of strings over {a, b} in which the substring aa occurs at least twice. (a + b)*aa(a
+ b)*aa(a + b)*
c) The set of strings over {a, b} that do not begin with the substring aaa. (b + ab + aab)(a +
b)*
d) (b  ab  aab)*(   a  aa)

170 | P a g e
4 Finite
Automata

A DFA that accepts the strings over {a, b} that do not contain the substring aaa is given
by the state diagram
b a, b
a
a a
q0 q1 q2 q3
b
b

The states are used to count the number of consecutive a's that have been processed.
When three consecutive a's are encountered, the DFA enters state q3, processes the
remainder of the input, and rejects the string.

e) The set of strings over {a, b, c} that begin with a, contain exactly two b's, and end with
cc. a(a + c)*b(a + c)*b(a + c)*cc
f) The set of strings over {a, b, c} in which every b is immediately followed by at least one c.
(a + bc + c)*
g) The set of strings over {a, b} in which the number of a’s is divisible by three.
h) The set of strings over {a, b} in which every a is either immediately preceded or
immediately followed by b, for example, baab, aba, and b. (aba + ba + ab + b)*
i) The set of strings of odd length over {a, b} that contain the substring bb.
j) The set of strings over {a, b} that have odd length or end with aaa.

k)

accepts strings of even length over {a, b, c} that contain exactly one a. A string accepted
by this machine must have exactly one a and the total number of b's and c's must be
odd. States q1 or q3 are entered upon processing a single a. The state q3 represents the
combination of the two conditions required for acceptance. Upon reading a second a,
the computation enters the nonaccepting state q4 and rejects the string.

l) The set of strings over {a, b} that have an odd number of occurrences of the substring
aa. Note that aaa has two occurrences of aa.
m) The set of strings over {a, b} that contain an even number of substrings ba.
n) The set of strings over {1, 2, 3} the sum of whose elements is divisible by six.
o) The set of strings over {a, b, c} in which the number of a’s plus the number of b's plus
twice the number of c's is divisible by six.

p) The states of the machine are used to count the number of symbols processed since an a
has been read or since the beginning of the string, whichever is smaller.

171 | P a g e
4 Finite
Automata

A computation is in state qi if the previous i elements are not a's. If an input string has a
substring of length four without an a, the computation enters q4 and rejects the string.
All other strings accepted.

q) The DFA to accept this language differs from the machine in Exercise 20 by requiring
every fourth symbol to be an a. The first a may occur at position 1, 2, 3, or 4. After
reading the first a, the computation enters state q4 and checks for a pattern consisting
of a combination of three b's or c's followed by an a. If the string varies from this
pattern, the computation enters state q8 and rejects the input.

Strings of length 3 or less are accepted, since the condition is vacuously satisfied.

15.
a)

a
q0 b q1
b
a
q2 q3

b)
a
q0 b q1
b
a
q2 q3
b

c)
a, b
a a a, b b b
q0 q1 q2 q3 q4 q5

d)

172 | P a g e
4 Finite
Automata

a a a
q0 q1 q2 a q3

b b
q4

e)

a
q0 q1
b
a

16.
IN the language NOT IN the language
c, ab, ac, aab, acc, acab, abab, a, b, bc, ca, cb, caa
abaab, cc, cab, caab, ccab, ccac,
abacab

17.
a)
a b
q0 {q0, q1} Ø
q1 Ø {q1, q2}
q2 {q0, q1} Ø

b)
[q0 , aaabb]  [q0 , aabb]
 [q0 , abb]
 [q0 , bb] No such input, string rejected

[q0 , aaabb]  [q0 , aabb]


 [q0 , abb]
 [q1 , bb]
 [q1 , b]
 [q1 , λ] Not final state, string rejected

[q0 , aaabb]  [q0 , aabb]


 [q0 , abb]
 [q1 , bb]
 [q1 , b]
 [q2 , λ] String Accepted

[q0 , aaabb]  [q0 , aabb]


 [q0 , abb]
 [q1 , bb]
 [q2 , b] No such input, string rejected

173 | P a g e
4 Finite
Automata

[q0 , aaabb]  [q0 , aabb]


 [q1 , abb] No such input, string rejected

[q0 , aaabb]  [q1 , aabb] No such input, string rejected

c) Yes
d) a*ab*b(ab*b + aa*ab*b)* or (a+b+)+.
A regular expressions for L(M) is a+b+(ab+ + a+ab+)*. Processing a+b+ leaves the computation
in state q2. After arriving at q2 there are two ways to leave and return, taking the cycle q0,
q1, q2 or the cycle q1, q2. The first path processes a string from a+ab+ and the second ab+.
This expression can be reduced to (a+b+)+.

18.
a)
a b
q0 {q0, q1} Ø
q1 Ø {q0, q2}
q2 Ø {q1, q2}

b)
[q0 , aabb]  [q0 , abb]
 [q0 , bb] String Rejected

[q0 , aabb]  [q0 , abb]


 [q1 , bb]
 [q2 , b]
 [q1 , λ] String Accepted

[q0 , aabb]  [q0 , abb]


 [q1 , bb]
 [q2 , b]
 [q2 , λ] String Accepted

[q0 , aabb]  [q0 , abb]


 [q1 , bb]
 [q0, b] String Rejected
…etc..!
c) Yes
e) a*a(ba*a + bb*b)* stop at q1
a*ab(b + bb + bba*ab)* stop at q2
Regular exp is: a*a(ba*a + bb*b)* + a*ab(b + bb + bba*ab)* or
a+(ba+ + bb+)* + a+b(b + bb + bba+b)* since a*a = a+ and b*b = b+

174 | P a g e
4 Finite
Automata

a
b
{q0,q1}
a {q0,q1,
q2}

a b
a
q0 {q0,q2} b

b b

0 a
{q1,q2}

a, b

19.
a) (a  ab  aab)*
b)
a

q1
a
a q0
a b
a
q0 q1 q2 q3
b a

c) The NFA
a

q3

a
c
q0 q2

a
b
q1

accepts the language (abc)*a*. Strings of the form (abc)* are accepted in q0. State q3
accepts (abc)*a+.

a
q0 q1
b

a a q2
a c
q4 q3

a
d)

175 | P a g e
4 Finite
Automata

a, b
q1 q3
b
b
q0
a a, b
q2 q4
a

e)
b

a b
q0 q1 q2

a a
q3

20.
a) The set of strings over {a, b} that contain either aa and bb as substrings. (a + b)*aa(a +
b)*bb(a + b)* + (a + b)*bb(a + b)*aa(a + b)*
b) The set of strings over {a, b} that contain both or neither aa and bb as substrings.
c) The set of strings over {a, b} whose third-to-the-Iast symbol is b. (a + b)*b(a + b)(a + b)
The set of strings over fa; bg whose third to the last symbol is b is accepted by the NFA

When a b is read in state q0, nondeterminism is used to choose whether to enter state q1
or remain in state q0. If q1 is entered upon processing the third to the last symbol, the
computation accepts the input. A computation that enters q1 in any other manner
terminates unsuccessfully.
d) The set of strings over {a, b} whose third and third-to-Iast symbols are both b. For
example, aababaa, abbbbbbbb, and abba are in the language. (a + b)(a + b)b(a + b)*b(a +
b)(a + b) + (a + b)(a + b)b(a + b)(a + b) + (a + b)bb(a + b) + b(a + b)b
e) The set of strings over {a, b} in which every a is followed by b or ab. (ab + aab + b)
f) The set of strings over {a, b} that have a substring of length four that begins and ends with
the same symbol. a(a + b)(a + b)a + b(a + b)(a + b)b
g) The set of strings over {a, b} that contain substrings aaa and bbb. (a + b)*aaa(a + b)*bbb(a
+ b)* + (a + b)*bbb(a + b)*aaa(a + b)*
h) The set of strings over {a, b, c} that have a substring of length three containing each of the
symbols exactly once. abc + acb + bac + bca + cba + cab
21. Construct the state diagram of a DFA that accepts the strings over {a, b} ending with the

176 | P a g e
4 Finite
Automata

substring abba. Give the state diagram of an NFA with six arcs that accepts the same
language. (a + b)*abba

22.
a)
a b

b
q0 q1

S aS  bA  
A bA  

b) q0  aq0  bq0   S  aA | bB  
A  aA  
B  bB | aS 
a b
a, b b
q1 q1
q0
a

c) q0  aq1   S  aA | 
q1  bq0 A  bB
B  aA  
a a b
q0 q1 q0 q1 q2
b a

d) q0  aq1  bq2
q1  bq0
q2  aq3
q3  
a
q0 b q1
b
a
q2 q3

e)
q0  aq1 
q1  bq1 aq0
a
q0 q1
b
a
23.
a)
a, b
S O
a, b

177 | P a g e
4 Finite
Automata

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

24.
a)
a
S B
a

b b b b

a
A C
a

b) aa, bb, abba, baab, baaaab, abab.

25.
a) RE = (a + bc + c)*
a,c

b
q0 q2
c
only q0 final, remove final in q1

b)
a a
q0 q1 q2

b b
b
q3 a, b

26.
a)

C a D
a a
b
S A b

b B

b) b(bb)*aa(aa)*

27. Design a finite automaton to accept the language defined by the regular expression
a) (ab)*(ba)*
b) aa(a+b)+bb
c) ((aa)+bb)*

178 | P a g e
4 Finite
Automata

d) aa*b + aa(ba)*
e) b*a(ab*b)* + λ

28.
a, b
a a
q0 q1 q2

a,b
a,b
a a
q3 q4 q5

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

a)
a, b
a a
q0 q1 q2
b b a
b
a a
q3 q4 q5
b
b

29.
0,1 1 1 0,1
0 q1 q2 q3 0
q0 q7

1 0 0 1
q4 q5 q6

30. ((a + b) (a + b)) (a + b)* ((a + b) (a + b))

31. 32. Table 1. Table 2.


DFA or NFA No. Matching
No.
no. of RE
(0) DFA Z 1. 3
2. 8
(i) DFA j 3. 7
(ii) NFA b 4. 6
(iii) NFA a 5. 1
(iv) DFA g 6. 2
(v) DFA i 7. 5
(vi) DFA h 8. 9
(vii) DFA e 9. 10
(viii) DFA f 10. 4

179 | P a g e
4 Finite
Automata

(ix) DFA c
(x) DFA d

180 | P a g e

Das könnte Ihnen auch gefallen