Exercise 3.1
In each case below, find a string of minimum length in not in the language corresponding to the given regular expression.
Exercise 3.2
Consider the two regular expressions
Find a string corresponding to but not to .
Find a string corresponding to but not to .
Find a string corresponding to both and .
Find a string in corresponding to neither nor .
Exercise 3.3
Let and be arbitrary regular expressions over the alphabet . In each case below, find a simpler equivalent regular expression.
Exercise 3.4
Exercise 3.5
In each case below, give a simple description of the smallest set of languages that contains all the “basic” languages , , and (for every ) and is closed under the specified operations.
union
concatenation
union and concatenation
Exercise 3.6
Suppose and are strings in . Find regular expressions corresponding to each of the languages defined recursively below.
; for every , then and are elements of .
; for every , , , and are elements of .
; ; for every , and are in .
Exercise 3.7
Find a regular expression corresponding to each of the following subsets of .
The language of all strings containing exactly two ’s.
The language of all strings containing at least two ’s.
The language of all strings that do not end with .
The language of all strings that begin or end with or .
The language of all strings not containing the substring .
The language of all strings in which the number of ’s is even.
The language of all strings containing no more than one occurrence of the string . (The string should be viewed as containing two occurrences of .)
The language of all strings in which every is followed immediately by .
The language of all strings containing both and as substrings.
The language of all strings not containing the substring .
The language of all strings not containing the substring .
The language of all strings containing both and as substrings.
The language of all strings in which the number of ’s is even and the number of ’s is odd.
The language of all strings in which both the number of ’s and the number of ’s are odd.
Exercise 3.8
Exercise 3.9
Show that every finite language is regular.
Exercise 3.10
Using the example in part (a) as a model, give a recursive definition (based on Definition 3.1) of the reverse of a regular expression .
Show that for every regular expression , if the language corresponds to , then corresponds to .
Exercise 3.11
The star height of a regular expression over , denoted by , is defined as follows:
.
.
for every .
.
.
Find the star heights of the following regular expressions.
Exercise 3.12
For both the regular expressions in the previous exercise, find an equivalent regular expression of star height 1.
Exercise 3.13
Let and be regular expressions over .
Show that the formula , involving the variable , is true if the regular expression is substituted for .
Show that if is not in the language corresponding to , then any regular expression satisfying corresponds to the same language as .
Exercise 3.14
Describe precisely an algorithm that could be used to eliminate the symbol from any regular expression that does not correspond to the empty language.
Exercise 3.15
Describe an algorithm that could be used to eliminate the symbol from any regular expression whose corresponding language does not contain the null string.
Exercise 3.16
The order of a regular language is the smallest integer for which , if there is one, and otherwise.
Show that the order of is finite if and only if there is an integer such that , and that in this case the order of is the smallest such that .
What is the order of the regular language ?
What is the order of the regular language ?
Exercise 3.17
† A generalized regular expression is defined the same way as an ordinary regular expression, except that two additional operations, intersection and complement, are allowed. So, for example, the generalized regular expression represents the set of all strings in that start with and don’t contain the substring .
Show that the subset of can be described by a generalized regular expression with no occurrences of .
Can the subset be described this way? Give reasons for your answer.
Exercise 3.18
Figure 3.34 shows a transition diagram for an NFA. For each string below, say whether the NFA accepts it.
Exercise 3.19
Find a regular expression corresponding to the language accepted by the NFA pictured in Figure 3.34. You should be able to do it without applying Kleene’s theorem: First find a regular expression describing the most general way of reaching state 4 the first time, and then find a regular expression describing the most general way, starting in state 4, of moving to state 4 the next time.
Exercise 3.20
For each of the NFAs shown in Figure 3.35, find a regular expression corresponding to the language it accepts.
Exercise 3.21
The following is the transition table for an NFA with states 1–5 and input alphabet . There are no -transitions.
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
Draw a transition diagram.
Calculate .
Calculate .
Exercise 3.22
A transition table is given for an NFA with seven states.
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 |
Find:
Exercise 3.23
A transition table is given for another NFA with seven states.
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 |
Calculate .
Exercise 3.24
Let be an NFA with no -transitions. Show that for every and every , .
Exercise 3.25
It is easy to see that if is an FA accepting , then the FA accepts (the FA obtained from Theorem 2.15 by writing is essentially ). Does this still work if is an NFA? If so, prove it. If not, find a counterexample.
Exercise 3.26
In Definition 3.14, is defined recursively in an NFA by first defining and then defining , where and . Give an acceptable recursive definition in which the recursive part of the definition defines instead.
Exercise 3.27
Which of the following, if any, would be a correct substitute for the second part of Definition 3.14? Give reasons for your answer.
Exercise 3.28
Let be an NFA. This exercise involves properties of the -closure of a set . Since is defined recursively, structural induction can be used to show that is a subset of some other set.
Show that if and are subsets of for which , then .
Show that for any , .
Show that if , then .
Show that if , then .
Draw a transition diagram to illustrate the fact that and are not always the same. Which is always a subset of the other?
Draw a transition diagram illustrating the fact that and are not always the same. Which is always a subset of the other? Under what circumstances are they equal?
Exercise 3.29
Let be an NFA. A set is called -closed if .
Show that the union of two -closed sets is -closed.
Show that the intersection of two -closed sets is -closed.
Show that for any subset of , is the smallest -closed set of which is a subset.
Exercise 3.30
† Let be an NFA. Show that for every and every ,
Exercise 3.31
Let be an FA, and let be the NFA with no -transitions for which for every and . Show that for every and , . Recall that the two functions and are defined differently.
Transcription note
Exercise 3.31 prints . For an arbitrary string , the FA’s extended transition function gives .
Exercise 3.32
Let be an NFA accepting a language . Assume that there are no transitions to , that has only one element, , and that there are no transitions from .
Let be obtained from by adding -transitions from to every state that is reachable from in . (If and are states, is reachable from if there is a string such that .) Describe (in terms of ) the language accepted by .
Let be obtained from by adding -transitions to from every state from which is reachable in . Describe in terms of the language accepted by .
Let be obtained from by adding both the -transitions in (a) and those in (b). Describe the language accepted by .
Exercise 3.33
Give an example of a regular language containing that cannot be accepted by any NFA having only one accepting state and no -transitions, and show that your answer is correct.
Exercise 3.34
Can every regular language not containing be accepted by an NFA having only one accepting state and no -transitions? Prove your answer.
Exercise 3.35
Let be an NFA, let be the maximum size of any of the sets for and , and let be a string of length over the input alphabet.
What is the maximum number of distinct paths that there might be in the computation tree corresponding to ?
In order to determine whether is accepted by , it is sufficient to replace the complete computation tree by one that is perhaps smaller, obtained by “pruning” the original one so that no level of the tree contains more nodes than the number of states in (and no level contains more nodes than there are at that level of the original tree). Explain why this is possible, and how it might be done.
Exercise 3.36
Let be an NFA. The NFA obtained by eliminating -transitions from might have more accepting states than , because the initial state is made an accepting state if . Explain why it is not necessary to make all the states for which accepting states in .
Exercise 3.37
In each part of Figure 3.36 is pictured an NFA. Use the algorithm described in the proof of Theorem 3.17 to draw an NFA with no -transitions accepting the same language.
Exercise 3.38
Each part of Figure 3.37 pictures an NFA. Using the subset construction, draw an FA accepting the same language. Label the final picture so as to make it clear how it was obtained from the subset construction.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
Exercise 3.39
Suppose is a regular language. If every FA accepting has at least states, then every NFA accepting has at least states. (Fill in the blank, and explain your answer.)
Exercise 3.40
Each part of Figure 3.38 shows an NFA. Draw an FA accepting the same language.
(a)
(b)
Exercise 3.41
For each of the following regular expressions, draw an NFA accepting the corresponding language, so that there is a recognizable correspondence between the regular expression and the transition diagram.
Exercise 3.42
For part (e) of Exercise 3.41, draw the NFA that is obtained by a literal application of Kleene’s theorem, without any simplifications.
Exercise 3.43
Suppose is an NFA accepting a language . Let be the NFA obtained from by adding -transitions from each element of to . Describe (in terms of ) the language .
Exercise 3.44
Suppose is an NFA accepting a language .
Describe how to construct an NFA with no transitions to its initial state so that also accepts .
Describe how to construct an NFA with exactly one accepting state and no transitions from that state, so that also accepts .
Exercise 3.45
Suppose is an NFA with exactly one accepting state that accepts the language . In order to find NFAs accepting the languages and , we might try adding -transitions from to itself and from to itself, respectively. Draw transition diagrams to show that neither technique always works.
Exercise 3.46
In the construction of in the proof of Theorem 3.25, consider this alternative to the construction described: Instead of a new state and -transitions from it to and , make the initial state of the new NFA, and create a -transition from it to . Either prove that this works in general, or give an example in which it fails.
Exercise 3.47
In the construction of in the proof of Theorem 3.25, consider the simplified case in which has only one accepting state. Suppose that we eliminate the -transition from the accepting state of to , and merge these two states into one. Either show that this would always work in this case, or give an example in which it fails.
Exercise 3.48
In the construction of in the proof of Theorem 3.25, suppose that instead of adding a new state , with -transitions from it to and to it from each accepting state of , we make both the initial state and the accepting state, and create -transitions from each accepting state of to . Either show that this works in general, or give an example in which it fails.
Transcription note
Exercise 3.48 prints in its final sentence although the proposed construction names as its initial state. The wording above preserves that distinction in the source.
Exercise 3.49
Figure 3.39 shows FAs and accepting languages and , respectively. Draw NFAs accepting each of the following languages, using the constructions in the proof of Theorem 3.25.
(a)
(b)
Exercise 3.50
Draw NFAs with no -transitions accepting and , where and are as in Exercise 3.49. Do this by connecting the two given diagrams directly, by arrows with appropriate labels.
Exercise 3.51
Use the algorithm of Theorem 3.30 to find a regular expression corresponding to each of the FAs shown in Figure 3.40. In each case, if the FA has states, construct tables showing for each with .
Exercise 3.52
Exercise 3.53
Suppose and are alphabets, and the function is a homomorphism; i.e., for every .
Show that .
Show that if is regular, then is regular. ( is the set .)
Show that if is regular, then is regular. ( is the set .)
Exercise 3.54
Suppose is an NFA. For two (not necessarily distinct) states and , we define the regular expression as follows: , where is either (if contains ) or , and the ’s are all the elements of for which contains . It’s possible for to be , if there are no transitions from to ; otherwise, represents the “most general” transition from to .
If we generalize this by allowing to be an arbitrary regular expression over , we get what is called an expression graph. If and are two states in an expression graph , and , we say that allows to move from to if there are states , with and , such that corresponds to the regular expression . This allows us to say how accepts a string ( allows to move from the initial state to an accepting state), and therefore to talk about the language accepted by . It is easy to see that in the special case where is simply an NFA, the two definitions for the language accepted by coincide. It is also not hard to convince yourself, using Theorem 3.25, that for any expression graph , the language accepted by can be accepted by an NFA.
We can use the idea of an expression graph to obtain an alternate proof of Theorem 3.30, as follows. Starting with an FA accepting , we may easily convert it to an NFA accepting , so that has no transitions to its initial state , exactly one accepting state (which is different from ), and no transitions from . The remainder of the proof is to specify a reduction technique to reduce by one the number of states other than and , obtaining an equivalent expression graph at each step, until and are the only states remaining. The regular expression then describes the language accepted. If is the state to be eliminated, the reduction step involves redefining for every pair of states and other than .
Describe in more detail how this reduction can be done. Then apply this technique to the FAs in Figure 3.40 to obtain regular expressions corresponding to their languages.
Transcription note
The path in Exercise 3.54 is indexed through , but the final factor is printed with . Consistent indexing gives .