Section 1.1

Exercises

[30/60%]
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.

?