Linz - Chapter 2 & 3 - Exer PDF
Linz - Chapter 2 & 3 - Exer PDF
regular, so are L2, L3, .... We will see later that this is indeed correct.
EXERCISES
1. Which of the strings 0001, 01101, 00001101 are accepted by the dfa
in Figure 2.1?
2. Translate the graph in Figure 2.5 into δ- notation.
3. For Σ = {a, b}, construct dfa’s that accept the sets consisting of
(a) all strings of even length.
(b) all strings of length greater than 5.
(c) all strings with an even number of a’s.
(d) all strings with an even number of a’s and an odd number of b’s.
4. For Σ = {a, b}, construct dfa’s that accept the sets consisting of
(a) all strings with exactly one a.
(b) all strings with at least two a’s.
(c) all strings with no more than two a’s.
(d) all strings with at least one b and exactly two a’s.
(e) all the strings with exactly two a’s and more than three b’s.
5. Give dfa’s for the languages
(a) L = {ab4wb2 : w ∈ {a, b}*}.
(b) L = {abnam : n ≥ 3, m ≥ 2}.
(c) L = {w1abbw2 : w1 ∈ {a, b}*, w2 ∈ {a, b}*}.
(d) L = {ban : n ≥ 1, n ≠ 4}.
6. With Σ = {a, b}, give a dfa for L = {w1aw2 : |w1| ≥ 3, |w2| ≤ 4}.
7. Find dfa’s for the following languages on Σ = {a, b}.
(a) L = {w : |w| mod 3 ≠ 0}.
(b) L = {w : |w| mod 5 = 0}.
(c) L = {w : na (w) mod 3 < 1}.
(d) L = {w : na (w) mod 3 < nb (w) mod 3}.
(e) L = {w : (na (w) − nb (w)) mod 3 = 0}.
(f) L = {w : (na (w)+ 2nb (w)) mod 3 < 1}.
(g) L = {w : |w| mod 3 = 0, |w| ≠ 5}.
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. For instance,
the string abbbaab contains a run of b’s of length three and a run of
a’s of length two. Find dfa’s for the following languages on {a, b}:
(a) L = {w : w contains no runs of length less than three}.
(b) L = {w : every run of a’s has length either two or three}.
(c) L = {w : there are at most two runs of a’s of length three}.
(d) L = {w : there are exactly two runs of a’s of length 3}.
9. Show that if we change Figure 2.6, making q3 a nonfinal state and
making q0, q1, q2 final states, the resulting dfa accepts .
10. Generalize the observation in the previous exercise. Specifically,
show that if M = (Q, Σ, δ, q0, F) and = (Q, Σ, δ, q0, Q − F) are two
dfa’s, then .
11. Consider the set of strings on {0, 1} defined by the requirements
below. For each, construct an accepting dfa.
(a) Every 00 is followed immediately by a 1. For example, the strings
101, 0010, 0010011001 are in the language, but 0001 and 00100
are not.
(b) All strings that contain the substring 000, but not 0000.
(c) The leftmost symbol differs from the rightmost one.
(d) Every substring of four symbols has, at most, two 0’s. For
example, 001110 and 011001 are in the language, but 10010 is
not because one of its substrings, 0010, contains three zeros.
(e) All strings of length five or more in which the third symbol from
the right end is different from the leftmost symbol.
(f) All strings in which the leftmost two symbols and the rightmost
two symbols are identical.
(g) All strings of length four or greater in which the leftmost two
symbols are the same, but different from the rightmost symbol.
12. Construct a dfa that accepts strings on {0, 1} if and only if the value
of the string, interpreted as a binary representation of an integer, is
zero modulo five. For example, 0101 and 1111, representing the
integers 5 and 15, respectively, are to be accepted.
13. Show that the language L = {vwv : v, w ∈ {a, b}*, |v| = 3} is regular.
14. Show that L = {an : n ≥ 3} is regular.
15. Show that the language L = {an : n ≥ 0, n ≠ 3} is regular.
16. Show that the language L = {an : n is either a multiple of three or a
multiple of 5} is regular.
17. Show that the language L = {an : n is a multiple of three, but not a
multiple of 5} is regular.
18. Show that the set of all real numbers in C is a regular language.
19. Show that if L is regular, so is L −{λ}.
20. Show that if L is regular, so is L ∪{aa}, for all a ∈ Σ.
21. Use (2.1) and (2.2) to show that
Show how, given a dfa for any regular language L, one can construct
a dfa for truncate (L). From this, prove that if L is a regular language
not containing λ, then truncate (L) is also regular.
27. While the language accepted by a given dfa is unique, there are
normally many dfa’s that accept a language. Find a dfa with exactly
six states that accepts the same language as the dfa in Figure 2.4.
28. Can you find a dfa with three states that accepts the language of the
dfa in Figure 2.4? If not, can you give convincing arguments that no
such dfa can exist?
In the same vein, nondeterminism is an effective mechanism for
describing some complicated languages concisely. Notice that the
definition of a grammar involves a nondeterministic element. In
S → aSb|λ
we can at any point choose either the first or the second production. This
lets us specify many different strings using only two rules.
Finally, there is a technical reason for introducing nondeterminism. As
we will see, certain theoretical results are more easily established for nfa’s
than for dfa’s. Our next major result indicates that there is no essential
difference between these two types of automata. Consequently, allowing
nondeterminism often simplifies formal arguments without affecting the
generality of the conclusion.
EXERCISES
(b) Do you think the language in part (a) can be accepted by an nfa
with fewer than three states?
12. Find an nfa with four states for L = {an : n ≥ 0}∪{bna : n ≥ 1}.
13. Which of the strings 00, 01001, 10010, 000, 0000 are accepted by
the following nfa?
Show that for every nfa with multiple initial states there exists an nfa
with a single initial state that accepts the same language.
20. Suppose that in Exercise 19 we made the restriction Q0 ∩ F = ∅.
Would this affect the conclusion?
21. Use Definition 2.5 to show that for any nfa
EXERCISES
w = a1a2a3a4...,
then
1. Consider the dfa with initial state q0, final state q2 and
EXERCISES
19. Give regular expressions for the following languages on Σ = {a, b, c}:
(a) All strings containing exactly two a’s.
(b) All strings containing no more than three a’s.
(c) All strings that contain at least one occurrence of each symbol in
Σ.
20. Write regular expressions for the following languages on {0, 1}:
(a) All strings ending in 10.
(b) All strings not ending in 10.
(c) All strings containing an odd number of 0’s.
21. Find regular expressions for the following languages on {a, b}:
(a) L = {w : |w| mod 3 ≠ 0}.
(b) L = {w : na (w) mod 3 = 0}.
(c) L = {w : na (w) mod 5 > 0}.
22. Determine whether or not the following claims are true for all
regular expressions r1 and r2. The symbol ≡ stands for equivalence
of regular expressions in the sense that both expressions denote the
same language.
(a)
(b)
(c)
(d)
EXERCISES
1. Use the construction in Theorem 3.1 to find an nfa that accepts the
language L (a∗a + ab).
2. Use the construction in Theorem 3.1 to find an nfa that accepts the
language L ((aab)∗ab).
3. Use the construction in Theorem 3.1 to find an nfa that accepts the
language L (ab∗aa + bba∗ab).
4. Find an nfa that accepts the complement of the language in Exercise
3.
5. Give an nfa that accepts the language L ((a + b)∗ b (a + bb)∗).
6. Find dfa’s that accept the following languages:
(a) L (aa∗ + aba∗b∗).
(b) L (ab (a + ab)∗ (a + aa)).
(c) L ((abab)∗ +(aaa∗ + b)∗).
(d) L (((aa∗)∗ b)∗).
(e) L((aa∗)∗ + abb).
7. Find dfa’s that accept the following languages:
(a) L = L (ab∗a∗) ∪ L ((ab)∗ ba).
(b) L = L (ab∗a∗) ∩ L ((b)∗ ab).
16. Prove that the construction suggested by Figures 3.11 and 3.12
generate equivalent generalized transition graphs.
17. Write a regular expression for the set of all C real numbers.
18. Use the construction in Theorem 3.1 to find nfa’s for L (a ⊘) and L
(⊘∗). Is the result consistent with the definition of these languages?
FIGURE 3.19
EXERCISES
S → abA,
A → baB,
B → aA|bb.
2. Construct a dfa that accepts the language generated by the grammar
S → abS|A,
A → baB,
B → aA|bb.
3. Find a regular grammar that generates the language L (aa∗ (ab + a)∗).
4. Construct a left-linear grammar for the language in Exercise 1.
5. Construct right- and left-linear grammars for the language
L = {anbm : n ≥ 3, m ≥ 2}.
14. Find regular grammars for the following languages on {a, b}:
(a) L = {w : na(w) is even, nb(w) ≥ 4}.
(b) L = {w : na (w) and nb (w) are both even}.)
(c) L = {w : (na (w) − nb (w)) mod 3 = 1}.
(d) L = {w : (na (w) − nb (w)) mod 3 ≠ 1}.
(e) L = {w : (na (w) − nb (w)) mod 3 ≠ 0}.
(f) L = {w : |na (w) − nb (w)| is odd}.
15. Show that for every regular language not containing λ there exists a
right-linear grammar whose productions are restricted to the forms
A → aB,
or
A → a,
where A, B ∈ V, and a ∈ T.
16. Show that any regular grammar G for which L (G) ⊘= ⊘ must have at
least one production of the form
A→x
where A ∈ V and x ∈ T ∗.
17. Find a regular grammar that generates the set of all real numbers in
C.
18. Let G1 = (V1, Σ, S1, P1) be right-linear and G2 = (V2, Σ, S2, P2) be a
left-linear grammar, and assume that V1 and V2 are disjoint.
Consider the linear grammar G = ({S} ∪ V1 ∪ V2, Σ, S, P), where S
is not in V1 ∪ V2 and P = {S → S1|S2} ∪ P1 ∪ P2. Show that L (G)
is regular.