CMPS 260 Spring 2024
HW #3: NFAs and Regular Expressions
Due: 2pm, Friday February 23

Part I: NFAs

Each of the first five problems describes a language and asks you to present an NFA (i.e., nondeterministic finite automaton) —with a specified maximum number of states and/or transitions— that accepts that language. In counting states and transitions, you need not include the dead state or any transitions directed to it. Nor do you need to show that state or those transitions, as it is understood that if, in a transition graph, a state q has no outgoing transition on a symbol a, it is as though there were such a transition and it went to the dead state.

1. Present an NFA having at most five states and eight transitions that accepts the language

L1 = { 0u110v  |  u,v ∈ {0,1}* }

In words, L1 contains precisely those strings over the alphabet {0,1} having 0 as a prefix and 110 as a substring.

Note that a transition labeled by both 0 and 1 counts as two transitions.


2. Present an NFA having at most six states and at most nine transitions that accepts the language

L2 = { w ∈ {0,1}*  |  w = x011y for some x,y ∈{0,1}*  ∨  w = x0100 for some x ∈ {0,1}*}

In words, L2 contains precisely those strings over the alphabet {0,1} having either 011 as a substring or 0100 as a suffix.

Note that a transition labeled by both 0 and 1 counts as two transitions.


3. Present an NFA having at most five states (only one final state is necessary) that accepts the language

L3 = { wc  |  w ∈ {a,b}*} ∪ { wb  |  w ∈ {a,c}*} ∪ { wa  |  w ∈ {b,c}*}

In words, L3 contains precisely those strings over the alphabet {a,b,c} ending in a symbol that appears exactly once.

Note that using λ-transitions would be helpful.


4. Present an NFA having at most eight states (only one final state is necessary) that accepts the language

L4 = { wbabv  |  w,v ∈ {a,b}* ∧ |v| ≥ 4} ∪ { wbbv  |  w,v ∈ {a,b}* ∧ |v| = 2}

In words, L4 contains precisely those strings over {a,b} that end either
(i) four or more symbols after an occurrence of bab, or
(ii) exactly two symbols after an occurrence of bb.


5. Present an NFA having four states, and only two transitions labeled a, that accepts the language

L5 = { {aa} ∪ {aba} ∪ {cca} }*

In words, L5 contains precisely those strings over {a,b,c} that can be "factored" into a sequence of zero or more substrings, where each factor is either aa, aba, or cca. An example of such a string (in which vertical bars have been inserted in order to show the boundaries between adjacent factors) is

aba|aa|aa|cca|aa|aba|aba|cca|aba|aa

You will find it helpful to use at least one λ transition.



6. Construct a λ-free NFA that is equivalent to (i.e., accepts the same language as) the NFA shown below. Present your answer in tabular form (as on the right side of the figure below) rather than as (or in addition to, if you want) a transition graph. Don't forget to identify the initial state and the final states.

An appropriate algorithm for removing λ-transitions is described in the section titled Step 1 in the web page that describes the Subset Construction algorithm (by which to obtain a DFA equivalent to a given NFA).

You are not to apply the Subset Construction; you are only to rid the NFA of λ-transitions.

Transition Graph Table
Init?Final?State δ(_,a)δ(_,b)δ(_,λ)
q0{q0,q1}
q1{q1} {q0} {q2}
q2 {q3} {q3}
q3{q4}
q4 {q1} {q0}


7. Present the DFA obtained by applying the Subset Construction algorithm to the NFA shown below. (It should have seven states, including the dead state.)

Present your answer in tabular form (as on the right side of the figure below) rather than as (or in addition to, if you want) a transition graph. Don't forget to identify the initial state and the final states.

Your DFA's state names should make obvious which subset of the NFA's state set each one corresponds to. For example, q{0,2} (or simply {0,2}, if you prefer) could be the name of the state corresponding to the set of states {q0, q2} in the given NFA.

Transition Graph Table
Init?Final?State δ(_,a)δ(_,b)
q0{q1} {q2}
q1 {q0,q1}
q2{q2} {q1}



Part II: Regular Expressions

Where r is a regular expression, L(r) denotes the language (i.e., set of strings) described by r.

8. Present a list containing precisely those strings of length five that are members of L( (b(bc + a)* ). Arrange the strings in alphabetical order.


9. Present a list containing precisely those strings of length six or less that are members of

L( a(ba + a)*b(a + ab)* ).

Arrange the strings from shortest to longest; within each group of strings having the same length, put them in alphabetical order.


10. The reverse xR of a string x is what you would expect: the symbols of x written in reverse order. For example, (abbbab)R = babbba. A formal recursive definition (for a ∈ Σ and x ∈ Σ*) is

λR=λ
(ax)R=xRa

Extending the concept from strings to languages, we define LR, the reverse of language L, like this:

LR = { xR  |  x ∈ L }

Present a regular expression describing LR, where L is the language described by the regular expression

(bba + bc)*abc(ba + a)*