Automata Excercises
Automata Excercises
PROBLEMS
1. Consider the language S*, where S = {a, b}.
How many words does this language have of length 2? of length 3? of
length n?
1
2
3. Consider the language S*, where S = {ab, ba}. Write out all the words
in S* that have seven or fewer letters. Can any word in this language
contain the substrings aaa or bbb?
3
4. Consider the language S*, where S = {a ab bal. Is the string (abbba)
a word in this language? Write out all the words in this language with
seven or fewer letters. What is another way in which to describe the
words in this language? Be careful, this is not simply the language of
all words without bbb.
4
5. Consider the language S*, where S = {aa aba baa}. Show that the words
aabaa, baaabaaa, and baaaaababaaaaa re all in this language. Can any
word in this language be interpreted as a string of elements from S in
two different ways? Can any word in this language have an odd total
number of a's?
5
6. Consider the language S* where S = {xx xxx}. In how many ways can
x"9 be written as the product of words in S? This means: How many
different factorizations are there of x19 into xx and xxx?
6
7
7. (i) Prove that if x is in PALINDROME then so is x" for any n.
8
(ii) Prove that if y3 is in PALINDROME then so is y.
9
(iv) Prove that PALINDROME has as many words of length 4 as it does
of length 3.
10
9. Let S = {ab, bb} and let T = {ab, bb, bbbb}. Show that S* = T*. What
principle does this illustrate?
11
10. How does the situation in Problem 9 change if we replace the operator
* with the operator + as defined in this chapter? Note the language S'
means the same as S* but does not allow the "concatenation of no words"
of S.
12
12. Prove that for all sets S,
(i) (S+)* =(S*)*
(ii) (S+)' =S
(iii) Is (S*)+ = (S+)* for all sets S?
13
12. Let S = {a, bb, bab, abaab}. Is abbabaabab in S*? Is abaabbabbaabb?
Does any word in S* have an odd total number of b's?
13. Suppose that for some language L we can always concatenate two words
in L and get another word in L if and only if the words are not the
same. That is, for any words w, and w2 in L where w, 4- w2, the word
wIw 2 is in L but the word w1w1 is not in L. Prove that this cannot
happen.
14
14. By definition
(S**)* = S***
is this set bigger than S*? Is it bigger than S?
15th ans
15
LANGUAGES 25
16. Give an example of a set S such that the language S* has more six
letter words than seven letter words. Give an example of an S* that has
more six letter words than eight letter words. Does there exist an S*
such that it has more six letter words than twelve letter words?
17. (i) Consider the language S* where S {aa, ab, ba, bb}. Give another
description of this language.
(ii) Give an example of a set S such that S* contains all possible strings
of a's and b's that have length divisible by three.
16
18th ans
19. One student suggested the following algorithm to test a string of a's and
b's to see if it is a word in S* where S = {aa, ba, aba, abaab}. Step
1, cross off the longest set of characters from the front of the string
that is a word in S. Step 2, repeat step 1 until it is no longer possible.
If what remains is the string A, the original string was a word in S*.
If what remains is not A (this means some letters are left but we cannot
find a word in S at the beginning), the original string was not a word
17
in S*. Find a string that disproves this algorithm.
20. The reason * is called the "closure operator" is because the set S* is
closed under concatenation. This means that if we take any two words
in S* and concatenate them, we get another word in S*. If S = {ab,
bbb}, then S is not closed under concatenation since abab is not in S,
but S* is closed under concatenation.
(i) Let T be any set that contains all of S, and suppose T is closed
under concatenation. Show that T contains S*.
(ii) Explain why we may say "S* is the smallest set that is closed under
concatenation that contains S."
(iii) What is the smallest set, closed under concatenation, that contains
both the sets of words P and Q?
18
Chapter 3
PROBLEMS
1. Write another recursive definition for the language L, of Chapter 2.
19
2. Using the second recursive definition of the set EVEN, how many different
ways can we prove that 14 is in EVEN?
20
21
4. Show that the following is another recursive definition of the set EVEN.
Rule 1 2 and 4 are in EVEN.
Rule 2 If x is in EVEN, then so is x + 4.
22
5. Show that there are infinitely many different recursive definitions for the
set EVEN.
23
24
6. Using any recursive definition of the set EVEN, show that all the numbers
in it end in the digits 0, 2, 4, 6, or 8.
25
7. The set POLYNOMIAL defined in this chapter contains only the polynomials
in the one variable x. Write a recursive definition for the set
of all polynomials in the two variables x and y.
26
8. Define the set of valid algebraic expressions ALEX as follows:
Rule 1 All polynomials are in ALEX.
Rule 2 If f(x) and g(x) are in ALEX then so are
(i) (f(x))
(ii) - (f(x))
(iii) f(x) + g(x)
(iv) f(x) - g(x)
(v) f(x)g(x)
(vi) f(x) / g(x)
36 AUTOMATA THEORY
(vii) f(x)9(x)
(viii) ftg(x))
(a) Show that (x + 2)3x is in ALEX.
27
(b) Show that elementary calculus contains enough rules to prove the
theorem that all algebraic expressions can be differentiated.
(c) Is Rule (viii) really necessary?
28
29
10. Show that if n is less than 29, then x' can be shown to be in
POLYNOMIAL in fewer than eight steps.
30
occur in arithmetic expressions, such as (/, +), // and */. What is the
complete list of substrings of length 2 that cannot occur?
12. Are there any substrings of length 3 that cannot occur that do not contain
forbidden substrings of length 2? (This means that 1/H is already known
to be illegal because it contains the forbidden substring //.) What is the
longest forbidden substring that does not contain a shorter forbidden
substring?
13. The rules given above for the set AE, allow for the peculiar expressions
(((((9))))) and -(-(-(-())
It is not really harmful to allow these in AE, but is there some modified
definition of AE that eliminates this problem?
14. Write out the full recursive definition for the propositional calculus that
contains the symbols V and A as well as ---i and --. What are all the
forbidden substrings of length 2 in this language?
31
15. (i) When asked to give a recursive definition for the language
PALINDROME over the alphabet I = {a, b}, a student wrote:
Rule 1 a and b are in PALINDROME
Rule 2 If x is in PALINDROME, then so are axa and bxb
Unfortunately all of the words in the language defined above have
an odd length and so it is not all of PALINDROME. Fix this problem.
(ii) Give a recursive definition for the language EVENPALINDROME of
all palindromes of even length.
32
16. (i) Give a recursive definition for the set ODD = {1,3,5,7 . . .
(ii) Give a recursive definition for the set of strings of digits 0, 1, 2,
3, . . . 9 that cannot start with the digit 0.
17. (i) Give a recursive definition for the language S* where S = {aa,b}.
(ii) Give a recursive definition for the language T* where
T = {wj, w2, w3, W41,
where these w's are some particular words.
33
18. Give two recursive definitions for the set
POWERS-OF-TWO = {1 2 4 8 16 . . . }
Use one of them to prove that the product of two powers of two is also
a power of two.
19. Give recursive definitions for the following languages over the alphabet
{a,b}:
(i) The language EVENSTRING of all words of even length.
(ii) The language ODDSTRING of all words of odd length.
(iii) The language AA of all words containing the substring aa.
(iv) The language NOTAA of all words not containing the substring aa.
34
20. (i) Consider the following recursive definition of 3-PERMUTATION
(a) 123 is a 3-PERMUTATION
(b) if xyz is a 3-PERMUTATION then so are
zyx and yzx
Show that there are six different 3-PERMUTATION's.
(ii) Consider the following recursive definition of 4-PERMUTATION
(a) 1234 is a 4-PERMUTATION
(b) if xyzw is a 4-PERMUTATION then so are
wzyx and yzwx
35
How many 4-PERMUTATION's are there (by this
Chapter 4
PROBLEMS
1. Let ri, r 2, and r3 be three regular expressions. Show that the language
associated with (r, + r 2)r3 is the same, as the language associated with
rjr 3 + r2r 3. Show that r1 (r2 + r 3) is equivalent to r1r2 + r j r3 . This
will be the same as "proving a distributive law" for regular expressions.
Construct a regular expression defining each of the following languages
over the alphabet I = {a, b}.
36
2. All words in which a appears tripled, if at all. This means that every
clump of a's contains 3 or 6 or 9 or 12... a's.
37
4. All words that contain exactly three b's in total.
5. All words that contain exactly two b's or exactly three b's, not more.
7. All strings in which the letter b is never tripled. This means that no
word contains the substring bbb.
8. All words in which a is tripled or b is tripled, but not both. This means
each word contains the substring aaa or the substring bbb but not both.
38
10. All strings in which the total number of a's is divisible by three, such
as aabaabbaba.
11. (i) All strings in which any b's that occur are found in clumps of
an odd number at a time, such as abaabbbab.
(ii) All strings that have an even number of a's and an odd number
of b's.
(iii) All strings that have an odd number of a's and an odd number
of b's.
39
REGULAR EXPRESSIONS 61
12. Let us reconsider the regular expression
(a + b)*a(a + b)*b(a + b)*
(i) Show that this is equivalent to
(a + b)*ab(a + b)*
in the sense that they define the same language.
(ii) Show that
(a + b)*ab(a +b)* + b*a* = (a + b)*
(iii) Show that
(a + b)* ab[(a + b)*ab(a + b)* + b*a*] + b*a* = (a + b)*
(iv) Is (iii) the last variation of this theme or are there more beasts
left in this cave?
40
13. We have defined the product of two sets of strings in general. If we
apply this to the case where both factors are the same set, S = T, we
obtain squares, S2. Similarly we can define S3, S4. Show that
(i) S* = A + S + S' + S2 + S3 + S 4 + ...
(ii) S+ = S + S1 + S2 + S3 + S4 + ...
Show that the following pairs of regular expressions define the same
language over the alphabet I = {a, b}.
41
14. (i) (ab)*a and a(ba)*
(ii) (a* + b)* and (a + b)*
(iii) (a* + b*)* and (a + b)*
42
15. (i) A* and A
(ii) (a*b)*a* and a*(ba*)*
(iii) (a*bbb)*a* and a*(bbba*)*
43
44
16. (i) ((a + bb)*aa)* and A + (a + bb)*aa
(ii) (aa)*(A + a) and a*
(iii) a(aa)*(A + a)b + b and a*b
45
17. (i) a(ba + a)*b and aa*b(aa*b)*
(ii) A + a(a + b)* + (a + b)* aa(a + b)* and ((b*a)*ab*)*
Describe (in English phrases) the languages associated with the following
46
regular expressions.
47
18. (i) (a + b)* a(A + bbbb)
(ii) (a(a + bb)*)*
(iii) (a(aa)*b(bb)*)*
(iv) (b(bb)*)*(a(aa)*b(bb)*)*
(v) (b(bb)*)*(a(aa)*b(bb)*)*(a(aa)*)*
(vi) ((a + b)a)*
48
19. (D.N. Arden) Let R, S, and T be three languages and assume that. A
is not in S. Prove the following statements.
(i) From the premise that R = SR + T, we can conclude that R = S*T.
(ii) From the premise that R = S*T, we can conclude that R = SR + T.
20. Explain why we can take any pair of equivalent regular expressions and
replace the letter a in both with any regular expression R and the letter
b with any regular expression S and the resulting regular expressions
will have the same language. For example, 15.(ii)
49
(a*b)*a* = a*(ba*)*
becomes the identity
(R*S)*R* = R*(SR*)*
which is true for all regular expressions R and S. In particular
R = a + bb, S = ba* results in the complicated identity
((a + bb)*(ba*))*(a + bb)* = (a + bb)* ((ba*)(a + bb)*)*
What is the deeper meaning of this transformation?
What identity would result from using
R = (ba*)* S = (A + b)
Chapter 5
PROBLEMS
1. Write out the transition table for the FA's on pages 68, 70 (both), 73,
74 and 80 that were defined by pictures. If the states in the pictures
were not labeled, assign them names so that we can build the table.
50
51
52
2. Build an FA that accepts only the language of all words with b as the
second letter. Show both the picture and the transition table for this
machine and find a regular expression for the language.
53
3. Build an FA that accepts only the words baa, ab, and abb and no other
strings longer or shorter.
54
4. (i) Build a new FA that accepts only the word A.
(ii) Build an FA with three states that accept all words.
55
5. Build an FA that accepts only those words that have an even number
of letters total.
56
6. Build an FA that accepts only those words that do not end with ba.
57
7. Build an FA that accepts only those words that begin or end with a
double letter.
58
8. (i) Build an FA that accepts only those words that have more than four
letters.
(ii) Build an FA that accepts only those words that have fewer than four
letters.
82 AUTOMATA THEORY
9. Problems 2 through 12 of Chapter 4 include 14 languages that could be
represented by regular expressions. For each of these find an FA that
accepts exactly it.
59
10. So far we have been dealing with Fa's over the alphabet. {a, b}.
Let us consider for the moment the alphabet I - {a, b, c}.
(i) If we had an FA over this alphabet with five states, how many entries
would there be in the transition table?
(ii) In the picture of this five-state machine, how many edges would need
to be drawn in total (counting an edge with two labels double and an
edge with three labels triple)?
(iii) Build an FA that accepts all the words in this alphabet that have an
a in them somewhere that is followed later in the word by some b
that is followed later in the word by some c (the three being not
necessarily in a row but in that order, as in abaac).
(iv) Write a regular expression for the language accepted by this machine.
11. Recall from Chapter 4 the language of all words over the alphabet {a,
b} that have both the letter a and the letter b in them, but not necessarily
in that order. Build an FA that accepts this language.
12. Build an FA that accepts the language of all words with only a's or
60
only b's in them. Give a regular expression for this language.
13. Draw pictures for all the FA's over the alphabet {a, b} that have exactly
two states. Be careful to put the +'s in in all possible ways. (Hint:
There are 48 different machines.)
14. (i) Write out the transition tables for all the FA's in Problem 13.
(ii) Write out regular expressions to represent all the languages defined
by the machines in Problem 13.
61
15. Let us call two FA's different if their pictures are not the same but
equivalent if they accept the language. How many different languages
are represented by the 48 machines of Problem 13.
62
FINITE AUTOMATA 83
17. Find two FA's that satisfy these conditions: Between them they accept
all words in (a + b)*, but there is no word accepted by both machines.
63
18. Describe the languages accepted by the following FA's.
iv) Write regular expressions for the languages accepted by these three
machines.
64
19. The following is an FA over the alphabet I = {a, b, c}. Prove that it
accepts all strings that have an odd number of occurrences of the substring
abc.
65
66
20. Consider the following FA:
(i) Show that any input string with more than three letters is not accepted
by this FA.
(ii) Show that the only words accepted are a, aab, and bab.
(iii) Show that by changing the + signs alone we can make this FA accept
the language {bb, aba, bba}
(iv) Show that any language in which the words have fewer than four
letters can be accepted by a machine that looks like this one with the
+ signs in different places.
(v) Prove that if L is a finite language, then there is some FA that accepts
L.
67
68
CHAPTER 6
PROBLEMS
1. For the four FA's pictured in Problems 5-18, 5-19 and 5-20 determine
whether a TG could be built that can accept the same language but
requires fewer states.
2. The notion of transition table can be extended to TG's. The rows of the table
would be the states of the machine and the columns of the table would be all
those strings of alphabet characters that are ever used as the label for any edge
in the TG. However, the mere fact that a certain string is the label for an edge
coming from state I does not mean that it is also the label of an edge coming
out of state 2. Therefore, in the transition table some entries are likely to be blank
(that is, no new state is reached from the prior state given this input sequence).
The TG
69
Calculate the transition table for the TG's defined by pictures on pages
86, 87, 89 (bottom), 90, 91 (third), 93 (second), and 94.
One advantage of defining a TG by such a table is that in complicated
cases it may be easier to read the table than a cluttered picture having
many edges with long string labels. (Remember that in cases where not
all the states have names it is necessary to give them names to build
the table.)
70
3. Draw a four-state TG that accepts all the input strings from {a, b}* that
71
are not in EVEN-EVEN. Is there a two-state TG that accepts this language?
4. Here are six TG's. For each of the next 10 words decide which of these
machines accepts the given word.
72
(i) A (vi) aba
(ii) a (vii) abba
(iii) b (viii) bab
'(iv) aa (ix) baab
(v) ab (x) abbb
73
6. Show that any language that can be accepted by a TG can be accepted
by a TG with an even number of states.
74
7. How many different TG's are there over the alphabet {a, b} that have
two states?
8. Show that for every finite language L there is a TG that accepts exactly
75
the words in L and no others. Contrast this with Theorem 5.
9. Prove that for every TG there is another TG that accepts the same language
but has only one + state.
76
10. Build a TG that accepts the language L, of all words that begin and
end with the same doubled letter, either of the form aa . . . aa or
bb . . . bb. Note: aaa and bbb are not words in this language.
77
11. Build a TG that accepts the language of all strings that end in a word
from L1 of Problem 10 above.
78
13. Given a TG for some arbitrary language L, what language would it accept
if every + state were to be connected back to every - state by Aedges?
For example, by this method:
79
14. Let the language L be accepted by the finite automaton F and let L not
contain the word A. Show how to build a new finite automaton that
accepts exactly all the words in L and the word A.
80
15. Let the language L be accepted by the transition graph T and let L not
81
contain the word A. Show how to build a new TG that accepts exactly
all the words in L and the word A.
82
16. Let the language L be accepted by the transition graph T and let L not
contain the word ba. We want to build a new TG that accepts exactly
L and the word ba.
(i) One suggestion is to draw an edge from - to + and label it ba.
Show that this does not always work.
(ii) Another suggestion is to draw a new + state and draw an edge from
a - state to it labeled ba. Show that this does not always work.
(iii) What does work?
83
17. Let L be any language. Let us define the transpose of L to be the
language of exactly those words that are the words in L spelled backward.
For example, if
L = {a abb bbaab bbbaa}
then
transpose (L) = {a bba baabb aabbb}
(i) Prove that if there is a FA that accepts L, then there is a TG that
accepts the transpose of L.
(ii) Prove that if there is a TG that accepts L, then there is a TG that
accepts the transpose of L.
Note: It is true, but much harder to prove that if an FA accepts L then
some FA accepts the transpose of L. However, after Chapter 7 this
will be trivial to prove.
84
85
18. Transition graph T accepts language L. Show that if L has a word of
odd length, then T has an edge with a label with an odd number of
letters.
19. A student walks into a classroom and sees on the blackboard a diagram
of a TG with two states that accepts only the word A. The student
reverses the direction of exactly one, edge leaving all other edges and
all labels and all +'s and -'s the same. But now the new TG accepts
the language a*. What was the original machine?
86
20. Let us now consider an algorithm for determining whether a specific TG
that has no A-edges accepts a given word.
Step I Number each edge in the TG in any order with the integers
1, 2, 3 . . . x, where x is the number of edges in the TG.
TRANSITION GRAPHS 99
Step 2 Observe that if the word has y letters and is accepted at all
by this machine, it can be accepted by tracing a path of not
more than y edges.
Step 3 List all strings of y or fewer integers each of which -- x.
This is a finite list.
Step 4 Check each string on the list in Step 3 by concatenating the
labels of the edges involved to see if they make a path from
a - to a + corresponding to the given word.
Step 5 If there is a string in Step 4 that works, the word is accepted.
If none work, the word is not in the language of the machine.
(i) Prove this algorithm does the job.
(ii) Why is it necessary to assume that the TG has no A-edges?
87
CHAPTER 8
PROBLEMS
1. In the example for NFA3 above, why was it necessary to stipulate that
no edges come into the two different start states? What can be done to
add two machines when this condition fails?
88
2. Suppose NFA1 is a machine for the regular expression r, and NFA2 for
the regular expression r 2. Further suppose that NFA1 has only one +
state and that this state has no edges leading out of it (even back to
itself). Show how to make a simple NFA for the language rjr 2.
150 AUTOMATA THEORY
3. Can anything be done, similar to Problem 2, for (rl)*?
4. (i) How many NFA's are there with exactly two states where there
can be 0, 1, or 2 final states and where the states may even be
disconnected?
(ii) How many are there if the states cannot be disconnected?
(iii) How many different connected NFA's are there with two states
that accept at least one word? (Be careful: We are counting machines
not languages.)
Let us now introduce a machine called "a nondeterministic finite automaton
with null string labels-," abbreviated NFA-A. This machine follows the same
rules as an NFA except that we are allowed to have edges labeled with the
null string A, as in the example below:
89
What is the language for each of the NFA's pictured below? Write regular
expressions for each.
90
15. Build FA's for the languages in Problems 10 through 14.
For each of the following FA's, find NFA's that have fewer states
and accept the same language.
91
92
19. For the language accepted by the machine below, find a different FA
with four states. Find an NFA that accepts the same language and has
only seven edges (where edges with two labels are counted twice).
93
20. A one-person game can be converted into an NFA as follows. Let every
possible board situation be a state. If any move (there may be several
types of moves but we are not interested in distinguishing among them)
can change some state x into some state y, then draw an edge from x
to y and label it m. Label the initial position - and the winning positions
+. "This game can be won in five moves" is the same as saying "m5
is accepted by this NFA." Once we have the NFA we use the algorithm
of Chapter 7 to convert it into a regular expression. The language it
represents tells us how many moves are in each winning sequence.
Let us do this with the following example. The game of Flips is played
with three coins. Initially they are all heads. A move consists of flipping
two coins simultaneously from whatever they were to the opposite side.
For example, flipping the end coins changes THH into HHT. We win
when all three coins are tails. There are eight possible states: HHH,
HHT .... TTT. The only - is HHH; the only + is TTT. Draw this
NFA, labeling any edge that can flip between states with the letter m.
Convert this NFA into a regular expression. Is m3 or m' in the language
of this machine? The shortest word in this language is the shortest
solution of this puzzle. What is it?
CHAPTER 9
PROBLEMS
Each of the following is a Moore machine with input alphabet Y = {a,b} and
output alphabet F = {0,1}. In Problems 1 through 5, draw the machines given
the transition and output tables. In Problems 6 through 10, construct the transition
94
and output tables given the pictorial representations of the machines.
95
96
97
98
99
100
I1. On each of the Moore machines in Problems 1 through 10, run the input
sequence aabab. What are the respective outputs?
12. Even though a Moore machine does not define a language of the strings
that it accepts as input, we can still use it to recogonize a language in
the following sense. We can arrange that the last character printed out
by the machine is an A for accept or an R for reject. For example, the
following Moore machine will recognize the language of all words of
FINITE AUTOMATA WITH OUTPUT 175
the form (a + b)*aa(a + b)* in the sense that these words and only
these words will cause the last character printed by the machine to be
A.
101
13. Suppose we define a Less machine to be a Moore machine that does
not automatically print the character of the start state. The first character
it prints is the character of the second state it enters. From then on, for
every state it enters it prints a character, even when it reenters the start
state. In this way the input string gets to have some say in what the
first character printed is going to be. Show that these Less machines are
equivalent to Mealy machines in the direct sense, that is, for every Less
machine there is a Mealy machine that has the same output for every
input string.
Mealy machines can also be defined by transition tables. The rows and the
columns are both labeled with the names of the states. The entry in the table
is the label of the edge (or edges) going from the row state to the column
state (if there is no such edge, this entry is blank).
Construct the transition table for each of the four Mealy machines shown
below.
102
103
104
105
18. tToh ep eerfxoarmmp le of the increment machine on page 160 used three
states its job. Show that two states are all that are needed.
106
19. (i) Convert the Moore machines in Problems 1 through 10 into Mealy
(ii) Cmoanchvienrte s.the Mealy machines in Problems 14 through 17 into Moore
machines.
107
108
109
20. Draw a Mealy machine equivalent to the following sequential circuit.
110
111