Chapter 1

Regular Languages

[73/75%]
Show
LaTeX
Problem 1.1

ᴬ The following are the state diagrams of two DFAs, M1M_{1} and M2M_{2}. Answer the following questions about each of these machines.

?
(a)

What is the start state?

(b)

What is the set of accept states?

(c)

What sequence of states does the machine go through on input aabb?

(d)

Does the machine accept the string aabb?

(e)

Does the machine accept the string ε\varepsilon?

Problem 1.2

ᴬ Give the formal description of the machines M1M_{1} and M2M_{2} pictured in Exercise 1.1.

?
Problem 1.3

The formal description of a DFA MM is ({q1,q2,q3,q4,q5},{u,d},δ,q3,{q3})\left(\left\{ q_{1}, q_{2}, q_{3}, q_{4}, q_{5}\right\} ,\left\{ \mathrm{u}, \mathrm{d}\right\} , \delta , q_{3},\left\{ q_{3}\right\} \right), where δ\delta is given by the following table. Give the state diagram of this machine.

ud
q1q_{1}q1q_{1}q2q_{2}
q2q_{2}q1q_{1}q3q_{3}
q3q_{3}q2q_{2}q4q_{4}
q4q_{4}q3q_{3}q5q_{5}
q5q_{5}q4q_{4}q5q_{5}
?
Problem 1.4

Each of the following languages is the intersection of two simpler languages. In each part, construct DFAs for the simpler languages, then combine them using the construction discussed in footnote 3 (page 46) to give the state diagram of a DFA for the language given. In all parts, Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}.

?
(a)

{w∣w has at least three a’s and at least two b’s}\left\{ w \mid w\text{ has at least three a's and at least two b's}\right\}

(b)

ᴬ {w∣w has exactly two a’s and at least two b’s}\left\{ w \mid w\text{ has exactly two a's and at least two b's}\right\}

(c)

{w∣w has an even number of a’s and one or two b’s}\left\{ w \mid w\text{ has an even number of a's and one or two b's}\right\}

(d)

ᴬ {w∣w has an even number of a’s and each a is followed by at least one b}\left\{ w \mid w\text{ has an even number of a's and each }\mathbf{a}\text{ is followed by at least one }\mathbf{b}\right\}

(e)

{w∣w starts with an a and has at most one b}\left\{ w \mid w\text{ starts with an }\mathbf{a}\text{ and has at most one }\mathbf{b}\right\}

(f)

{w∣w has an odd number of a’s and ends with a b}\left\{ w \mid w\text{ has an odd number of a's and ends with a b}\right\}

(g)

{w∣w has even length and an odd number of a’s}\left\{ w \mid w\text{ has even length and an odd number of a's}\right\}

Problem 1.5

Each of the following languages is the complement of a simpler language. In each part, construct a DFA for the simpler language, then use it to give the state diagram of a DFA for the language given. In all parts, Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}.

?
(a)

ᴬ {w∣w does not contain the substring ab}\left\{ w \mid w\text{ does not contain the substring }\mathbf{a b}\right\}

(b)

ᴬ {w∣w does not contain the substring baba }\left\{ w \mid w\text{ does not contain the substring baba }\right\}

(c)

{w∣w contains neither the substrings ab nor ba}\left\{ w \mid w\text{ contains neither the substrings ab nor ba}\right\}

(d)

{w∣w is any string not in a∗ b∗}\left\{ w \mid w \text{ is any string not in } \mathrm{a}^{*} \mathrm{~ b}^{*}\right\}

(e)

{w∣w is any string not in (ab+)∗}\left\{ w \mid w \text{ is any string not in } \left(\mathrm{ab}^{+}\right)^{*}\right\}

(f)

{w∣w is any string not in a∗∪ b∗}\left\{ w \mid w \text{ is any string not in } \mathrm{a}^{*} \cup \mathrm{~ b}^{*}\right\}

(g)

{w∣w is any string that doesn’t contain exactly two a’s}\left\{ w \mid w\text{ is any string that doesn't contain exactly two a's}\right\}

(h)

{w∣w is any string except a and b}\left\{ w \mid w\text{ is any string except a and b}\right\}

Problem 1.6

Give state diagrams of DFAs recognizing the following languages. In all parts, the alphabet is {0,1}\left\{ 0,1\right\}.

?
(a)

{w∣w begins with a 1 and ends with a 0}\left\{ w \mid w\text{ begins with a 1 and ends with a 0}\right\}

(b)

{w∣w contains at least three 1 s }\left\{ w \mid w\text{ contains at least three 1 s }\right\}

(c)

{w∣w contains the substring 0101 (i.e., w=x0101y for some x and y )}\left\{ w \mid w\text{ contains the substring 0101 (i.e., }w=x 0101 y\text{ for some }x\text{ and }y\text{ )}\right\}

(d)

{w∣w has length at least 3 and its third symbol is a 0}\left\{ w \mid w\text{ has length at least 3 and its third symbol is a 0}\right\}

(e)

{w∣w starts with 0 and has odd length, or starts with 1 and has even length}\left\{ w \mid w\text{ starts with 0 and has odd length, or starts with 1 and has even length}\right\}

(f)

{w∣w doesn’t contain the substring 110}\left\{ w \mid w\text{ doesn't contain the substring 110}\right\}

(g)

{w∣ the length of w is at most 5}\left\{ w \mid \text{ the length of }w\text{ is at most 5}\right\}

(h)

{w∣w is any string except 11 and 111}\left\{ w \mid w\text{ is any string except 11 and 111}\right\}

(i)

{w∣ every odd position of w is a 1}\left\{ w \mid \text{ every odd position of }w\text{ is a 1}\right\}

(j)

{w∣w contains at least two 0s and at most one 1}\left\{ w \mid w\text{ contains at least two 0s and at most one 1}\right\}

(k)

{ε,0}\left\{ \varepsilon , 0\right\}

(l)

{w∣w contains an even number of 0 s, or contains exactly two 1 s }\left\{ w \mid w\text{ contains an even number of 0 s, or contains exactly two 1 s }\right\}

(m)

The empty set

(n)

All strings except the empty string

Problem 1.7

Give state diagrams of NFAs with the specified number of states recognizing each of the following languages. In all parts, the alphabet is {0,1}\left\{ 0,1\right\}.

?
(a)

ᴬ The language {w∣w ends with 00}\left\{ w \mid w\text{ ends with 00}\right\} with three states

(b)

The language of Exercise 1.6c with five states

(c)

The language of Exercise 1.6l with six states

(d)

The language {0}\left\{ 0\right\} with two states

(e)

The language 0∗1∗0+0^{*} 1^{*} 0^{+}with three states

(f)

ᴬ The language 1∗(001+)∗1^{*}\left(001^{+}\right)^{*} with three states

(g)

The language {ε}\left\{ \varepsilon \right\} with one state

(h)

The language 0* with one state

Problem 1.8

Use the construction in the proof of Theorem 1.45 to give the state diagrams of NFAs recognizing the union of the languages described in

?
(a)

Exercises 1.6a and 1.6b.

(b)

Exercises 1.6c and 1.6f.

Problem 1.9

Use the construction in the proof of Theorem 1.47 to give the state diagrams of NFAs recognizing the concatenation of the languages described in

?
(a)

Exercises 1.6g and 1.6i.

(b)

Exercises 1.6b and 1.6m.

Problem 1.10

Use the construction in the proof of Theorem 1.49 to give the state diagrams of NFAs recognizing the star of the languages described in

?
(a)

Exercise 1.6b.

(b)

Exercise 1.6j.

(c)

Exercise 1.6m.

Problem 1.11

ᴬ Prove that every NFA can be converted to an equivalent one that has a single accept state.

?
Problem 1.12

Let D={w∣w contains an even number of a’s and an odd number of b’s and does not contain the substring ab}D=\left\{ w \mid w\text{ contains an even number of a's and an odd number of b's and does not contain the substring ab}\right\}. Give a DFA with five states that recognizes DD and a regular expression that generates DD. (Suggestion: Describe DD more simply.)

?
Problem 1.13

Let FF be the language of all strings over 0,1 that do not contain a pair of 1s that are separated by an odd number of symbols. Give the state diagram of a DFA with five states that recognizes FF. (You may find it helpful first to find a 4-state NFA for the complement of FF.)

?
Problem 1.14
?
(a)

Show that if MM is a DFA that recognizes language BB, swapping the accept and nonaccept states in MM yields a new DFA recognizing the complement of BB. Conclude that the class of regular languages is closed under complement.

(b)

Show by giving an example that if MM is an NFA that recognizes language CC, swapping the accept and nonaccept states in MM doesn't necessarily yield a new NFA that recognizes the complement of CC. Is the class of languages recognized by NFAs closed under complement? Explain your answer.

Problem 1.15

Give a counterexample to show that the following construction fails to prove Theorem 1.49, the closure of the class of regular languages under the star operation. 1 Let N1=(Q1,Σ,δ1,q1,F1)N_{1}=\left(Q_{1}, \Sigma , \delta_{1}, q_{1}, F_{1}\right) recognize A1A_{1}. Construct N=(Q1,Σ,δ,q1,F)N=\left(Q_{1}, \Sigma , \delta , q_{1}, F\right) as follows. NN is supposed to recognize A1∗A_{1}^{*}.

Footnotes

  1. In other words, you must present a finite automaton, N1N_{1}, for which the constructed automaton NN does not recognize the star of N1N_{1} ’s language. ↩

?
(a)

The states of NN are the states of N1N_{1}.

(b)

The start state of NN is the same as the start state of N1N_{1}.

(c)

F={q1}∪F1F=\left\{ q_{1}\right\} \cup F_{1}. The accept states FF are the old accept states plus its start state.

(d)

Define δ\delta so that for any q∈Q1q \in Q_{1} and any a∈Σεa \in \Sigma_{\varepsilon },

δ(q,a)={δ1(q,a)q∉F1 or a≠εδ1(q,a)∪{q1}q∈F1 and a=ε. \delta (q, a)= \begin{cases} \delta _{1}(q, a) & q \notin F_{1} \text{ or } a \neq \varepsilon \\ \delta _{1}(q, a) \cup \left\{ q_{1}\right\} & q \in F_{1} \text{ and } a=\varepsilon . \end{cases}

(Suggestion: Show this construction graphically, as in Figure 1.50.)

Problem 1.16

Use the construction given in Theorem 1.39 to convert the following two nondeterministic finite automata to equivalent deterministic finite automata.

?
(a)

(b)

Problem 1.17
?
(a)

Give an NFA recognizing the language (01∪001∪010)∗(01 \cup 001 \cup 010)^{*}.

(b)

Convert this NFA to an equivalent DFA. Give only the portion of the DFA that is reachable from the start state.

Problem 1.18

Give regular expressions generating the following languages (cf. Exercise 1.6). In all parts, the alphabet is {0,1}\left\{ 0,1\right\}.

?
(a)

{w∣w begins with a 1 and ends with a 0}\left\{ w \mid w\text{ begins with a 1 and ends with a 0}\right\}

(b)

{w∣w contains at least three 1 s }\left\{ w \mid w\text{ contains at least three 1 s }\right\}

(c)

{w∣w contains the substring 0101 (i.e., w=x0101y for some x and y )}\left\{ w \mid w\text{ contains the substring 0101 (i.e., }w=x 0101 y\text{ for some }x\text{ and }y\text{ )}\right\}

(d)

{w∣w has length at least 3 and its third symbol is a 0}\left\{ w \mid w\text{ has length at least 3 and its third symbol is a 0}\right\}

(e)

{w∣w starts with 0 and has odd length, or starts with 1 and has even length}\left\{ w \mid w\text{ starts with 0 and has odd length, or starts with 1 and has even length}\right\}

(f)

{w∣w doesn’t contain the substring 110}\left\{ w \mid w\text{ doesn't contain the substring 110}\right\}

(g)

{w∣ the length of w is at most 5}\left\{ w \mid \text{ the length of }w\text{ is at most 5}\right\}

(h)

{w∣w is any string except 11 and 111}\left\{ w \mid w\text{ is any string except 11 and 111}\right\}

(i)

{w∣ every odd position of w is a 1}\left\{ w \mid \text{ every odd position of }w\text{ is a 1}\right\}

(j)

{w∣w contains at least two 0s and at most one 1}\left\{ w \mid w\text{ contains at least two 0s and at most one 1}\right\}

(k)

{ε,0}\left\{ \varepsilon , 0\right\}

(l)

{w∣w contains an even number of 0 s, or contains exactly two 1 s }\left\{ w \mid w\text{ contains an even number of 0 s, or contains exactly two 1 s }\right\}

(m)

The empty set

(n)

All strings except the empty string

Problem 1.19
?
(a)

(0∪1)∗000(0∪1)∗(0 \cup 1)^{*} 000(0 \cup 1)^{*}

(b)

(((00)*(11)) ∪01)∗\cup 01)^{*}

(c)

∅∗\emptyset^{*}

Problem 1.20
?
(a)

a∗ b∗\mathrm{a}^{*} \mathrm{~ b}^{*}

(b)

a(ba)*b

(c)

a∗∪ b∗\mathrm{a}^{*} \cup \mathrm{~ b}^{*}

(d)

(aaa)∗(\mathrm{aaa})^{*}

(e)

Σ∗aΣ∗ bΣ∗aΣ∗\Sigma^{*} \mathrm{a} \Sigma^{*} \mathrm{~ b} \Sigma^{*} \mathrm{a} \Sigma^{*}

(f)

aba∪baba b a \cup b a b

(g)

(ε∪a)b(\varepsilon \cup a) b

(h)

(a∪ba∪bb)Σ∗(\mathrm{a} \cup \mathrm{ba} \cup \mathrm{bb}) \Sigma^{*}

Problem 1.21

Use the procedure described in Lemma 1.60 to convert the following finite automata to regular expressions.

?
(a)

(b)

Problem 1.22

In certain programming languages, comments appear between delimiters such as / and /. Let CC be the language of all valid delimited comment strings. A member of CC must begin with / and end with / but have no intervening /. For simplicity, assume that the alphabet for CC is Σ={a,b,/,#}\Sigma =\left\{ \mathrm{a}, \mathrm{b}, /, \# \right\}.

?
(a)

Give a DFA that recognizes CC.

(b)

Give a regular expression that generates CC.

Problem 1.23

ᴬ Let BB be any language over the alphabet Σ\Sigma. Prove that B=B+B=B^{+}iff BB⊆BB B \subseteq B.

?
Problem 1.24

A finite state transducer (FST) is a type of deterministic finite automaton whose output is a string and not just accept or reject. The following are state diagrams of finite state transducers T1T_{1} and T2T_{2}.

Each transition of an FST is labeled with two symbols, one designating the input symbol for that transition and the other designating the output symbol. The two symbols are written with a slash, /, separating them. In T1T_{1}, the transition from q1q_{1} to q2q_{2} has input symbol 2 and output symbol 1. Some transitions may have multiple input-output pairs, such as the transition in T1T_{1} from q1q_{1} to itself. When an FST computes on an input string ww, it takes the input symbols w1⋯wnw_{1} \cdots w_{n} one by one and, starting at the start state, follows the transitions by matching the input labels with the sequence of symbols w1⋯wn=ww_{1} \cdots w_{n}=w. Every time it goes along a transition, it outputs the corresponding output symbol. For example, on input 2212011, machine T1T_{1} enters the sequence of states q1,q2,q2,q2,q2,q1,q1,q1q_{1}, q_{2}, q_{2}, q_{2}, q_{2}, q_{1}, q_{1}, q_{1} and produces output 1111000. On input abbb, T2T_{2} outputs 1011. Give the sequence of states entered and the output produced in each of the following parts.

?
(a)

T1T_{1} on input 011

(b)

T1T_{1} on input 211

(c)

T1T_{1} on input 121

(d)

T1T_{1} on input 0202

(e)

T2T_{2} on input b

(f)

T2T_{2} on input bbab

(g)

T2T_{2} on input bbbbbb

(h)

T2T_{2} on input ε\varepsilon

Problem 1.25

Read the informal definition of the finite state transducer given in Exercise 1.24. Give a formal definition of this model, following the pattern in Definition 1.5 (page 35). Assume that an FST has an input alphabet Σ\Sigma and an output alphabet Γ\Gamma but not a set of accept states. Include a formal definition of the computation of an FST. (Hint: An FST is a 5-tuple. Its transition function is of the form δ:Q×Σ⟶Q×Γ\delta : Q \times \Sigma \longrightarrow Q \times \Gamma.)

Exercise 1.24: A finite state transducer (FST) is a type of deterministic finite automaton whose output is a string and not just accept or reject. Each transition of an FST is labeled with two symbols, one designating the input symbol for that transition and the other designating the output symbol, with the two symbols written with a slash, /, separating them. Some transitions may have multiple input-output pairs. When an FST computes on an input string ww, it takes the input symbols w1⋯wnw_{1} \cdots w_{n} one by one and, starting at the start state, follows the transitions by matching the input labels with the sequence of symbols w1⋯wn=ww_{1} \cdots w_{n}=w. Every time it goes along a transition, it outputs the corresponding output symbol.

?
Problem 1.26

Using the solution you gave to Exercise 1.25, give a formal description of the machines T1T_{1} and T2T_{2} depicted in Exercise 1.24.

?
(a)

T1T_{1}

(b)

T2T_{2}

Problem 1.27

Read the informal definition of the finite state transducer given in Exercise 1.24. Give the state diagram of an FST with the following behavior. Its input and output alphabets are {0,1}\left\{ 0,1\right\}. Its output string is identical to the input string on the even positions but inverted on the odd positions. For example, on input 0000111 it should output 1010010.

Exercise 1.24: A finite state transducer (FST) is a type of deterministic finite automaton whose output is a string and not just accept or reject. Each transition of an FST is labeled with two symbols, one designating the input symbol for that transition and the other designating the output symbol, with the two symbols written with a slash, /, separating them. Some transitions may have multiple input-output pairs. When an FST computes on an input string ww, it takes the input symbols w1⋯wnw_{1} \cdots w_{n} one by one and, starting at the start state, follows the transitions by matching the input labels with the sequence of symbols w1⋯wn=ww_{1} \cdots w_{n}=w. Every time it goes along a transition, it outputs the corresponding output symbol.

?
Problem 1.28

Convert the following regular expressions to NFAs using the procedure given in Theorem 1.54. In all parts, Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}.

?
(a)

a(abb)∗∪ b\mathrm{a}(\mathrm{abb})^{*} \cup \mathrm{~ b}

(b)

a+∪(ab)+\mathrm{a}^{+} \cup (\mathrm{ab})^{+}

(c)

(a∪b+)a+b+\left(a \cup b^{+}\right) a^{+} b^{+}

Problem 1.29

Use the pumping lemma to show that the following languages are not regular.

?
(a)

ᴬ A1={0n1n2n∣n≥0}A_{1}=\left\{ 0^{n} 1^{n} 2^{n} \mid n \geq 0\right\}

(b)

A2={www∣w∈{a,b}∗}A_{2}=\left\{ w w w \mid w \in \left\{ \mathrm{a}, \mathrm{b}\right\}^{*}\right\}

(c)

ᴬ A3={a2n∣n≥0}A_{3}=\left\{ \mathrm{a}^{2^{n}} \mid n \geq 0\right\} (Here, a2n\mathrm{a}^{2^{n}} means a string of 2n2^{n} a's.)

Problem 1.30

Describe the error in the following "proof" that 0∗1∗0^{*} 1^{*} is not a regular language. (An error must exist because 0∗1∗0^{*} 1^{*} is regular.) The proof is by contradiction. Assume that 0∗1∗0^{*} 1^{*} is regular. Let pp be the pumping length for 0∗1∗0^{*} 1^{*} given by the pumping lemma. Choose ss to be the string 0p1p0^{p} 1^{p}. You know that ss is a member of 0∗1∗0^{*} 1^{*}, but Example 1.73 shows that ss cannot be pumped. Thus you have a contradiction. So 0∗1∗0^{*} 1^{*} is not regular.

?
Problem 1.31

For any string w=w1w2⋯wnw=w_{1} w_{2} \cdots w_{n}, the reverse of ww, written wRw^{\mathcal{R}}, is the string ww in reverse order, wn⋯w2w1w_{n} \cdots w_{2} w_{1}. For any language AA, let AR={wR∣w∈A}A^{\mathcal{R}}=\left\{ w^{\mathcal{R}} \mid w \in A\right\}. Show that if AA is regular, so is ARA^{\mathcal{R}}.

?
Problem 1.32

Let

Σ3={[000],[001],[010],…,[111]}. \Sigma _{3}=\left\{ \left[\begin{array}{l} 0 \\ 0 \\ 0 \end{array}\right],\left[\begin{array}{l} 0 \\ 0 \\ 1 \end{array}\right],\left[\begin{array}{l} 0 \\ 1 \\ 0 \end{array}\right], \ldots ,\left[\begin{array}{l} 1 \\ 1 \\ 1 \end{array}\right]\right\} .

Σ3\Sigma_{3} contains all size 3 columns of 0s and 1s. A string of symbols in Σ3\Sigma_{3} gives three rows of 0s and 1s. Consider each row to be a binary number and let

B={w∈Σ3∗∣ the bottom row of w is the sum of the top two rows }. B=\left\{ w \in \Sigma _{3}^{*} \mid \text{ the bottom row of } w \text{ is the sum of the top two rows }\right\} .

For example,

[001][100][110]∈B, but [001][101]∉B. \left[\begin{array}{l} 0 \\ 0 \\ 1 \end{array}\right]\left[\begin{array}{l} 1 \\ 0 \\ 0 \end{array}\right]\left[\begin{array}{l} 1 \\ 1 \\ 0 \end{array}\right] \in B, \quad \text{ but } \quad \left[\begin{array}{l} 0 \\ 0 \\ 1 \end{array}\right]\left[\begin{array}{l} 1 \\ 0 \\ 1 \end{array}\right] \notin B.

Show that BB is regular. (Hint: Working with BRB^{\mathcal{R}} is easier. You may assume the result claimed in Problem 1.31.)

?
Problem 1.33

Let

Σ2={[00],[01],[10],[11]}. \Sigma _{2}=\left\{ \left[\begin{array}{l} 0 \\ 0 \end{array}\right],\left[\begin{array}{l} 0 \\ 1 \end{array}\right],\left[\begin{array}{l} 1 \\ 0 \end{array}\right],\left[\begin{array}{l} 1 \\ 1 \end{array}\right]\right\} .

Here, Σ2\Sigma_{2} contains all columns of 0s and 1s of height two. A string of symbols in Σ2\Sigma_{2} gives two rows of 0 s and 1 s. Consider each row to be a binary number and let

C={w∈Σ2∗∣ the bottom row of w is three times the top row }. C=\left\{ w \in \Sigma _{2}^{*} \mid \text{ the bottom row of } w \text{ is three times the top row }\right\} .

For example, [00][01][11][00]∈C\left[\begin{array}{l}0 \\ 0\end{array}\right]\left[\begin{array}{l}0 \\ 1\end{array}\right]\left[\begin{array}{l}1 \\ 1\end{array}\right]\left[\begin{array}{l}0 \\ 0\end{array}\right] \in C, but [01][01][10]∉C\left[\begin{array}{l}0 \\ 1\end{array}\right]\left[\begin{array}{l}0 \\ 1\end{array}\right]\left[\begin{array}{l}1 \\ 0\end{array}\right] \notin C. Show that CC is regular. (You may assume the result claimed in Problem 1.31.)

?
Problem 1.34

Let Σ2\Sigma_{2} be the same as in Problem 1.33. Consider each row to be a binary number and let

D={w∈Σ2∗∣ the top row of w is a larger number than is the bottom row }. D=\left\{ w \in \Sigma _{2}^{*} \mid \text{ the top row of } w \text{ is a larger number than is the bottom row }\right\} .

Problem 1.33: Σ2\Sigma_{2} contains all columns of 0s and 1s of height two,

Σ2={[00],[01],[10],[11]}. \Sigma _{2}=\left\{ \left[\begin{array}{l} 0 \\ 0 \end{array}\right],\left[\begin{array}{l} 0 \\ 1 \end{array}\right],\left[\begin{array}{l} 1 \\ 0 \end{array}\right],\left[\begin{array}{l} 1 \\ 1 \end{array}\right]\right\} .

A string of symbols in Σ2\Sigma_{2} gives two rows of 0s and 1s. For example, [00][10][11][00]∈D\left[\begin{array}{l}0 \\ 0\end{array}\right]\left[\begin{array}{l}1 \\ 0\end{array}\right]\left[\begin{array}{l}1 \\ 1\end{array}\right]\left[\begin{array}{l}0 \\ 0\end{array}\right] \in D, but [00][01][11][00]∉D\left[\begin{array}{l}0 \\ 0\end{array}\right]\left[\begin{array}{l}0 \\ 1\end{array}\right]\left[\begin{array}{l}1 \\ 1\end{array}\right]\left[\begin{array}{l}0 \\ 0\end{array}\right] \notin D. Show that DD is regular.

?
Problem 1.35

Let Σ2\Sigma_{2} be the same as in Problem 1.33. Consider the top and bottom rows to be strings of 0s and 1s, and let

E={w∈Σ2∗∣ the bottom row of w is the reverse of the top row of w}. E=\left\{ w \in \Sigma _{2}^{*} \mid \text{ the bottom row of } w \text{ is the reverse of the top row of } w\right\} .

Problem 1.33: Σ2\Sigma_{2} contains all columns of 0s and 1s of height two,

Σ2={[00],[01],[10],[11]}. \Sigma _{2}=\left\{ \left[\begin{array}{l} 0 \\ 0 \end{array}\right],\left[\begin{array}{l} 0 \\ 1 \end{array}\right],\left[\begin{array}{l} 1 \\ 0 \end{array}\right],\left[\begin{array}{l} 1 \\ 1 \end{array}\right]\right\} .

A string of symbols in Σ2\Sigma_{2} gives two rows of 0s and 1s. Show that EE is not regular.

?
Problem 1.36

Let Bn={ak∣k is a multiple of n}B_{n}=\left\{ \mathrm{a}^{k} \mid k \text{ is a multiple of } n\right\}. Show that for each n≥1n \geq 1, the language BnB_{n} is regular.

?
Problem 1.37

Let Cn={x∣x is a binary number that is a multiple of n}C_{n}=\left\{ x \mid x\text{ is a binary number that is a multiple of }n\right\}. Show that for each n≥1n \geq 1, the language CnC_{n} is regular.

?
Problem 1.38

An all-NFA MM is a 5-tuple (Q,Σ,δ,q0,F)\left(Q, \Sigma , \delta , q_{0}, F\right) that accepts x∈Σ∗x \in \Sigma^{*} if every possible state that MM could be in after reading input xx is a state from FF. Note, in contrast, that an ordinary NFA accepts a string if some state among these possible states is an accept state. Prove that all-NFAs recognize the class of regular languages.

?
Problem 1.39

The construction in Theorem 1.54 shows that every GNFA is equivalent to a GNFA with only two states. We can show that an opposite phenomenon occurs for DFAs. Prove that for every k>1k>1, a language Ak⊆{0,1}∗A_{k} \subseteq \left\{ 0,1\right\}^{*} exists that is recognized by a DFA with kk states but not by one with only k−1k-1 states.

?
Problem 1.40

Recall that string xx is a prefix of string yy if a string zz exists where xz=yx z=y, and that xx is a proper prefix of yy if in addition x≠yx \neq y. In each of the following parts, we define an operation on a language AA. Show that the class of regular languages is closed under that operation.

?
(a)

ᴬ NOPREFIX⁡(A)={w∈A∣ no proper prefix of w is a member of A}\operatorname {NOPREFIX}(A)=\left\{ w \in A \mid \text{ no proper prefix of }w\text{ is a member of }A\right\}.

(b)

NOEXTEND⁡(A)={w∈A∣w is not the proper prefix of any string in A}\operatorname {NOEXTEND}(A)=\left\{ w \in A \mid w\text{ is not the proper prefix of any string in }A\right\}.

Problem 1.41

For languages AA and BB, let the perfect shuffle of AA and BB be the language

{w∣w=a1b1⋯akbk, where a1⋯ak∈A and b1⋯bk∈B, each ai,bi∈Σ}. \left\{ w \mid w=a_{1} b_{1} \cdots a_{k} b_{k}, \text{ where } a_{1} \cdots a_{k} \in A \text{ and } b_{1} \cdots b_{k} \in B, \text{ each } a_{i}, b_{i} \in \Sigma \right\} .

Show that the class of regular languages is closed under perfect shuffle.

?
Problem 1.42

For languages AA and BB, let the shuffle of AA and BB be the language

{w∣w=a1b1⋯akbk, where a1⋯ak∈A and b1⋯bk∈B, each ai,bi∈Σ∗}. \left\{ w \mid w=a_{1} b_{1} \cdots a_{k} b_{k}, \text{ where } a_{1} \cdots a_{k} \in A \text{ and } b_{1} \cdots b_{k} \in B, \text{ each } a_{i}, b_{i} \in \Sigma ^{*}\right\} .

Show that the class of regular languages is closed under shuffle.

?
Problem 1.43

Let AA be any language. Define DROP-OUT⁡(A)\operatorname {DROP-OUT}(A) to be the language containing all strings that can be obtained by removing one symbol from a string in AA. Thus, DROP-OUT⁡(A)={xz∣xyz∈A where x,z∈Σ∗,y∈Σ}\operatorname {DROP-OUT}(A)=\left\{ x z \mid x y z \in A \text{ where } x, z \in \Sigma^{*}, y \in \Sigma \right\}. Show that the class of regular languages is closed under the DROP-OUT operation. Give both a proof by picture and a more formal proof by construction as in Theorem 1.47.

?
Problem 1.44

ᴬ Let BB and CC be languages over Σ={0,1}\Sigma =\left\{ 0,1\right\}. Define B←1C={w∈B∣ for some y∈C, strings w and y contain equal numbers of 1 s }B \stackrel{1}{\leftarrow } C=\left\{ w \in B \mid \text{ for some }y \in C\text{, strings }w\text{ and }y\text{ contain equal numbers of 1 s }\right\}. Show that the class of regular languages is closed under the ←1\stackrel{1}{\leftarrow } operation.

?
Problem 1.45
  • Let A/B={w∣wx∈A for some x∈B}A / B=\left\{ w \mid w x \in A\text{ for some }x \in B\right\}. Show that if AA is regular and BB is any language, then A/BA / B is regular.
?
Problem 1.46

Prove that the following languages are not regular. You may use the pumping lemma and the closure of the class of regular languages under union, intersection, and complement.

?
(a)

{0n1m0n∣m,n≥0}\left\{ 0^{n} 1^{m} 0^{n} \mid m, n \geq 0\right\}

(b)

{0m1n∣m≠n}\left\{ 0^{m} 1^{n} \mid m \neq n\right\}

(c)

{w∣w∈{0,1}∗ is not a palindrome }\left\{ w \mid w \in \left\{ 0,1\right\}^{*} \text{ is not a palindrome }\right\}1

Footnotes

  1. A palindrome is a string that reads the same forward and backward. ↩

(d)
  • {wtw∣w,t∈{0,1}+}\left\{ w t w \mid w, t \in \left\{ 0,1\right\}^{+}\right\}
Problem 1.47

Let Σ={1,#}\Sigma =\left\{ 1, \# \right\} and let Y={w∣w=x1#x2#⋯#xk for k≥0, each xi∈1∗, and xi≠xj for i≠j}Y=\left\{ w \mid w=x_{1} \# x_{2} \# \cdots \# x_{k} \text{ for } k \geq 0, \text{ each } x_{i} \in 1^{*}, \text{ and } x_{i} \neq x_{j} \text{ for } i \neq j\right\}. Prove that YY is not regular.

?
Problem 1.48

Let Σ={0,1}\Sigma =\left\{ 0,1\right\} and let D={w∣w contains an equal number of occurrences of the substrings 01 and 10}D=\left\{ w \mid w\text{ contains an equal number of occurrences of the substrings 01 and 10}\right\}. Thus 101∈D101 \in D because 101 contains a single 01 and a single 10, but 1010∉D1010 \notin D because 1010 contains two 10 s and one 01. Show that DD is a regular language.

?
Problem 1.49
?
(a)

Let B={1ky∣y∈{0,1}∗ and y contains at least k 1’s, for k≥1}B=\left\{ 1^{k} y \mid y \in \left\{ 0,1\right\}^{*} \text{ and } y \text{ contains at least } k \text{ 1's, for } k \geq 1\right\}. Show that BB is a regular language.

(b)

Let C={1ky∣y∈{0,1}∗ and y contains at most k 1’s, for k≥1}C=\left\{ 1^{k} y \mid y \in \left\{ 0,1\right\}^{*} \text{ and } y \text{ contains at most } k \text{ 1's, for } k \geq 1\right\}. Show that CC isn't a regular language.

Problem 1.50

ᴬ Read the informal definition of the finite state transducer given in Exercise 1.24. Prove that no FST can output wRw^{\mathcal{R}} for every input ww if the input and output alphabets are {0,1}\left\{ 0,1\right\}.

Exercise 1.24: A finite state transducer (FST) is a type of deterministic finite automaton whose output is a string and not just accept or reject. Each transition of an FST is labeled with two symbols, one designating the input symbol for that transition and the other designating the output symbol, with the two symbols written with a slash, /, separating them. Some transitions may have multiple input-output pairs. When an FST computes on an input string ww, it takes the input symbols w1⋯wnw_{1} \cdots w_{n} one by one and, starting at the start state, follows the transitions by matching the input labels with the sequence of symbols w1⋯wn=ww_{1} \cdots w_{n}=w. Every time it goes along a transition, it outputs the corresponding output symbol.

?
Problem 1.51

Let xx and yy be strings and let LL be any language. We say that xx and yy are distinguishable by L\boldsymbol {L} if some string zz exists whereby exactly one of the strings xzx z and yzy z is a member of LL; otherwise, for every string zz, we have xz∈Lx z \in L whenever yz∈Ly z \in L and we say that xx and yy are indistinguishable by L\boldsymbol {L}. If xx and yy are indistinguishable by LL, we write x≡Lyx \equiv_{L} y. Show that ≡L\equiv_{L} is an equivalence relation.

?
Problem 1.52

ᴬ Myhill-Nerode theorem. Refer to Problem 1.51. Let LL be a language and let XX be a set of strings. Say that XX is pairwise distinguishable by L\boldsymbol {L} if every two distinct strings in XX are distinguishable by LL. Define the index of L\boldsymbol {L} to be the maximum number of elements in any set that is pairwise distinguishable by LL. The index of LL may be finite or infinite.

Problem 1.51: We say that strings xx and yy are distinguishable by L\boldsymbol {L} if some string zz exists whereby exactly one of the strings xzx z and yzy z is a member of LL; otherwise, for every string zz, we have xz∈Lx z \in L whenever yz∈Ly z \in L and we say that xx and yy are indistinguishable by L\boldsymbol {L}.

?
(a)

Show that if LL is recognized by a DFA with kk states, LL has index at most kk.

(b)

Show that if the index of LL is a finite number kk, it is recognized by a DFA with kk states.

(c)

Conclude that LL is regular iff it has finite index. Moreover, its index is the size of the smallest DFA recognizing it.

Problem 1.53

Let Σ={0,1,+,=}\Sigma =\left\{ 0,1,+,=\right\} and

ADD⁡={x=y+z∣x,y,z are binary integers, and x is the sum of y and z}. \operatorname {ADD}=\left\{ x=y+z \mid x, y, z \text{ are binary integers, and } x \text{ is the sum of } y \text{ and } z\right\} .

Show that ADD⁡\operatorname {ADD} is not regular.

?
Problem 1.54

Consider the language F={ai bjck∣i,j,k≥0 and if i=1 then j=k}F=\left\{ \mathrm{a}^{i} \mathrm{~ b}^{j} \mathrm{c}^{k} \mid i, j, k \geq 0 \text{ and if } i=1 \text{ then } j=k\right\}.

?
(a)

Show that FF is not regular.

(b)

Show that FF acts like a regular language in the pumping lemma. In other words, give a pumping length pp and demonstrate that FF satisfies the three conditions of the pumping lemma for this value of pp.

(c)

Explain why parts (a) and (b) do not contradict the pumping lemma.

Problem 1.55

The pumping lemma says that every regular language has a pumping length pp, such that every string in the language can be pumped if it has length pp or more. If pp is a pumping length for language AA, so is any length p′≥pp^{\prime } \geq p. The minimum pumping length for AA is the smallest pp that is a pumping length for AA. For example, if A=01∗A=01^{*}, the minimum pumping length is 2. The reason is that the string s=0s=0 is in AA and has length 1 yet ss cannot be pumped; but any string in AA of length 2 or more contains a 1 and hence can be pumped by dividing it so that x=0,y=1x=0, y=1, and zz is the rest. For each of the following languages, give the minimum pumping length and justify your answer.

?
(a)

ᴬ 0001*

(b)

ᴬ 0∗1∗0^{*} 1^{*}

(c)

001∪0∗1∗001 \cup 0^{*} 1^{*}

(d)

ᴬ 0∗1+0+1∗∪10∗10^{*} 1^{+} 0^{+} 1^{*} \cup 10^{*} 1

(e)

(01)*

(f)

ε\varepsilon

(g)

1∗01∗01∗1^{*} 01^{*} 01^{*}

(h)

10(11∗0)∗010\left(11^{*} 0\right)^{*} 0

(i)

1011

(j)

Σ∗\Sigma^{*}

Problem 1.56
  • If AA is a set of natural numbers and kk is a natural number greater than 1, let
Bk(A)={w∣w is the representation in base k of some number in A}. B_{k}(A)=\left\{ w \mid w \text{ is the representation in base } k \text{ of some number in } A\right\} .

Here, we do not allow leading 0s in the representation of a number. For example, B2({3,5})={11,101}B_{2}(\left\{ 3,5\right\} )=\left\{ 11,101\right\} and B3({3,5})={10,12}B_{3}(\left\{ 3,5\right\} )=\left\{ 10,12\right\}. Give an example of a set AA for which B2(A)B_{2}(A) is regular but B3(A)B_{3}(A) is not regular. Prove that your example works.

?
Problem 1.57
  • If AA is any language, let A12−A_{\frac{1}{2}-} be the set of all first halves of strings in AA so that
A12−={x∣ for some y,∣x∣=∣y∣ and xy∈A}. A_{\frac{1}{2}-}=\left\{ x \mid \text{ for some } y,\left|x\right|=\left|y\right| \text{ and } x y \in A\right\} .

Show that if AA is regular, then so is A12−A_{\frac{1}{2}-}.

?
Problem 1.58
  • If AA is any language, let A13−13A_{\frac{1}{3}-\frac{1}{3}} be the set of all strings in AA with their middle thirds removed so that
A13−13={xz∣ for some y,∣x∣=∣y∣=∣z∣ and xyz∈A}. A_{\frac{1}{3}-\frac{1}{3}}=\left\{ x z \mid \text{ for some } y,\left|x\right|=\left|y\right|=\left|z\right| \text{ and } x y z \in A\right\} .

Show that if AA is regular, then A13−13A_{\frac{1}{3}-\frac{1}{3}} is not necessarily regular.

?
Problem 1.59
  • Let M=(Q,Σ,δ,q0,F)M=\left(Q, \Sigma , \delta , q_{0}, F\right) be a DFA and let hh be a state of MM called its "home". A synchronizing sequence for MM and hh is a string s∈Σ∗s \in \Sigma^{*} where δ(q,s)=h\delta (q, s)=h for every q∈Qq \in Q. (Here we have extended δ\delta to strings, so that δ(q,s)\delta (q, s) equals the state where MM ends up when MM starts at state qq and reads input ss.) Say that MM is synchronizable if it has a synchronizing sequence for some state hh. Prove that if MM is a kk-state synchronizable DFA, then it has a synchronizing sequence of length at most k3k^{3}. Can you improve upon this bound?
?
Problem 1.60

Let Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}. For each k≥1k \geq 1, let CkC_{k} be the language consisting of all strings that contain an a exactly kk places from the right-hand end. Thus Ck=Σ∗aΣk−1C_{k}=\Sigma^{*} \mathrm{a} \Sigma^{k-1}. Describe an NFA with k+1k+1 states that recognizes CkC_{k} in terms of both a state diagram and a formal description.

?
Problem 1.61

Consider the languages CkC_{k} defined in Problem 1.60. Prove that for each kk, no DFA can recognize CkC_{k} with fewer than 2k2^{k} states.

Problem 1.60: Let Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}. For each k≥1k \geq 1, let CkC_{k} be the language consisting of all strings that contain an a exactly kk places from the right-hand end. Thus Ck=Σ∗aΣk−1C_{k}=\Sigma^{*} \mathrm{a} \Sigma^{k-1}.

?
Problem 1.62

Let Σ={a,b}\Sigma =\left\{ \mathrm{a}, \mathrm{b}\right\}. For each k≥1k \geq 1, let DkD_{k} be the language consisting of all strings that have at least one a among the last kk symbols. Thus Dk=Σ∗a(Σ∪ε)k−1D_{k}=\Sigma^{*} \mathrm{a}(\Sigma \cup \varepsilon )^{k-1}. Describe a DFA with at most k+1k+1 states that recognizes DkD_{k} in terms of both a state diagram and a formal description.

?
Problem 1.63
?
(a)

Let AA be an infinite regular language. Prove that AA can be split into two infinite disjoint regular subsets.

(b)

Let BB and DD be two languages. Write B⊆DB \subseteq D if B⊆DB \subseteq D and DD contains infinitely many strings that are not in BB. Show that if BB and DD are two regular languages where B∈DB \in D, then we can find a regular language CC where B⋐C⋐DB \Subset C \Subset D.

Problem 1.64

Let NN be an NFA with kk states that recognizes some language AA.

?
(a)

Show that if AA is nonempty, AA contains some string of length at most kk.

(b)

Show, by giving an example, that part (a) is not necessarily true if you replace both AA 's by Aˉ\bar{A}.

(c)

Show that if Aˉ\bar{A} is nonempty, Aˉ\bar{A} contains some string of length at most 2k2^{k}.

(d)

Show that the bound given in part (c) is nearly tight; that is, for each kk, demonstrate an NFA recognizing a language AkA_{k} where Ak‾\overline{A_{k}} is nonempty and where Ak‾\overline{A_{k}} 's shortest member strings are of length exponential in kk. Come as close to the bound in (c) as you can.

Problem 1.65
  • Prove that for each n>0n>0, a language BnB_{n} exists where
?
(a)

BnB_{n} is recognizable by an NFA that has nn states, and

(b)

if Bn=A1∪⋯∪AkB_{n}=A_{1} \cup \cdots \cup A_{k}, for regular languages AiA_{i}, then at least one of the AiA_{i} requires a DFA with exponentially many states.

Problem 1.66

A homomorphism is a function f:Σ⟶Γ∗f: \Sigma \longrightarrow \Gamma^{*} from one alphabet to strings over another alphabet. We can extend ff to operate on strings by defining f(w)=f(w1)f(w2)⋯f(wn)f(w)=f\left(w_{1}\right) f\left(w_{2}\right) \cdots f\left(w_{n}\right), where w=w1w2⋯wnw=w_{1} w_{2} \cdots w_{n} and each wi∈Σw_{i} \in \Sigma. We further extend ff to operate on languages by defining f(A)={f(w)∣w∈A}f(A)=\left\{ f(w) \mid w \in A\right\}, for any language AA.

?
(a)

Show, by giving a formal construction, that the class of regular languages is closed under homomorphism. In other words, given a DFA MM that recognizes BB and a homomorphism ff, construct a finite automaton M′M^{\prime } that recognizes f(B)f(B). Consider the machine M′M^{\prime } that you constructed. Is it a DFA in every case?

(b)

Show, by giving an example, that the class of non-regular languages is not closed under homomorphism.

Problem 1.67
  • Let the rotational closure of language AA be RC⁡(A)={yx∣xy∈A}\operatorname {RC}(A)=\left\{ y x \mid x y \in A\right\}.
?
(a)

Show that for any language AA, we have RC⁡(A)=RC⁡(RC⁡(A))\operatorname {RC}(A)=\operatorname {RC}(\operatorname {RC}(A)).

(b)

Show that the class of regular languages is closed under rotational closure.

Problem 1.68
  • In the traditional method for cutting a deck of playing cards, the deck is arbitrarily split two parts, which are exchanged before reassembling the deck. In a more complex cut, called Scarne's cut, the deck is broken into three parts and the middle part in placed first in the reassembly. We'll take Scarne's cut as the inspiration for an operation on languages. For a language AA, let CUT⁡(A)={yxz∣xyz∈A}\operatorname {CUT}(A)=\left\{ y x z \mid x y z \in A\right\}.
?
(a)

Exhibit a language BB for which CUT⁡(B)≠CUT⁡(CUT⁡(B))\operatorname {CUT}(B) \neq \operatorname {CUT}(\operatorname {CUT}(B)).

(b)

Show that the class of regular languages is closed under CUT.

Problem 1.69

Let Σ={0,1}\Sigma =\left\{ 0,1\right\}. Let WWk={ww∣w∈Σ∗ and w is of length k}W W_{k}=\left\{ w w \mid w \in \Sigma^{*} \text{ and } w \text{ is of length } k\right\}.

?
(a)

Show that for each kk, no DFA can recognize WWkW W_{k} with fewer than 2k2^{k} states.

(b)

Describe a much smaller NFA for WW‾k\overline{W W}_{k}, the complement of WWkW W_{k}.

Problem 1.70

We define the avoids operation for languages AA and BB to be AA avoids B={w∣w∈A and w doesn’t contain any string in B as a substring}B=\left\{ w \mid w \in A\text{ and }w\text{ doesn't contain any string in }B\text{ as a substring}\right\}. Prove that the class of regular languages is closed under the avoids operation.

?
Problem 1.71

Let Σ={0,1}\Sigma =\left\{ 0,1\right\}.

?
(a)

Let A={0ku0k∣k≥1 and u∈Σ∗}A=\left\{ 0^{k} u 0^{k} \mid k \geq 1 \text{ and } u \in \Sigma^{*}\right\}. Show that AA is regular.

(b)

Let B={0k1u0k∣k≥1 and u∈Σ∗}B=\left\{ 0^{k} 1 u 0^{k} \mid k \geq 1 \text{ and } u \in \Sigma^{*}\right\}. Show that BB is not regular.

Problem 1.72

Let M1M_{1} and M2M_{2} be DFAs that have k1k_{1} and k2k_{2} states, respectively, and then let U=L(M1)∪L(M2)U=L\left(M_{1}\right) \cup L\left(M_{2}\right).

?
(a)

Show that if U≠∅U \neq \emptyset, then UU contains some string ss, where ∣s∣<max⁡(k1,k2)\left|s\right|<\max \left(k_{1}, k_{2}\right).

(b)

Show that if U≠Σ∗U \neq \Sigma^{*}, then UU excludes some string ss, where ∣s∣<k1k2\left|s\right|<k_{1} k_{2}.

Problem 1.73

Let Σ={0,1,#}\Sigma =\left\{ 0,1, \# \right\}. Let C={x#xR#x∣x∈{0,1}∗}C=\left\{ x \# x^{\mathcal{R}} \# x \mid x \in \left\{ 0,1\right\}^{*}\right\}. Show that Cˉ\bar{C} is a CFL.

?