# Nondeterministic Finite State Automata: Examples

Abstract

Practice designing and working with NFAs.

# 1 JFLAP

1. Return to the Finite Automata_ section of the Tutorial. Read the subsection devoted to Nondeterministic Finite Automata, specifically the sections titled “Construct and Run”, “Manipulating Transitions”, and "“Add a Trap State to DFA”. Also read “Convert to DFA”.

2. The NFA shown to the right is intended to accept the language ${aa,aab}^{*}{b}$. Try creating it in JFlap and running it on each of the following inputs to see if it works as expected:

• b
• aa
• aab
• aabb
• aaab
• aaaab
• aaaabb
• aaaabbb

3. Try constructing the NFA in Figure 3.10 of your text. This one uses a lambda transition, unlike the previous one.

Note: JFLAP marks lambda transitions with a lower-case $\lambda$ instead of the upper-case $\Lambda$ used in your textbook. Both conventions are quite common. I actually prefer the lower-case myself because elsewhere we have been following the convention of using upper-case (Roman) letters to denote sets and lower-case letter to denote individual symbols from our alphabet.

Try running your NFA on each of the following inputs to see if it works as expected:

• a
• aa
• aab
• aba
• aaba
• aabaab
• aabaaba
• aababa
• abaaab

4. JFLAP can convert NFAs to DFAs. Try converting each of your saved NFAs. Notice that the process used is directly comparable to the process described in section 3.3 of your text.

5. Look back at the example I gave of an NFA for the union of two languages.

Here is the NFA for the union.

Note: By default, JFLAP marks instantaneous transitions with a $\lambda$ instead of the $\epsilon$ used in your textbook. Both conventions are quite common. But for the sake of consistency, change the option in the JFLAP settings to use $\epsilon$.

Run this NFA on the following inputs, “Step” by step, observing how transitions take us to multiple states at once. Take note of which inputs are accepted.

• a
• b
• ba
• aba
• babba
• aabba
6. Use JFlap to convert this to a DFA. Compare the results and the steps with what we went through in the lecture notes.

7. Run the same inputs as the previous step through this new DFA. Convince yourself that it does accept the inputs that the NFA did.

8. Revisit some of the DFA problems that you worked in the final step of the earlier JFLAP exercise. Try rewriting some of them as NFAs.

• In many cases, an NFA will use fewer states and transitions than the corresponding DFA. Certainly, it should never need more states or transitions than a DFA (because every DFA is also an NFA that just happens to not use non-determinism).

• You can think of this simplification as the pay-off for the slightly more complicated conceptual effort involved in understanding non-determinism.

9. Exercise 2.3.4 at the end of section 2.3 2 of your text suggests drawing a number of NFAs. Pick one or two of these and create them in JFLAP. Run a handful of inputs through each one to convince yourself that you have done so correctly.

# 2 Sample Problems

Try to solve these on your own, first, then check my answer. If you don’t see where I got my answer from, the videos will walk you through my thought process. If you want to check my answer, my JFLAP files are provided.

## 2.1 Basic Patterns

Design an NFSA to recognize the language consisting of…

1. the string 101

Reveal
2. all strings beginning with 101

Reveal
3. all strings ending with 101

Reveal
4. all strings containing 101

Reveal

## 2.2 Combining Smaller Machines into Larger Ones

### 2.2.1 Sequencing

Putting two NSAs together in a sequence is, roughly speaking, accomplished by “connecting” each final state of the first FSA to the starting state of the second one with an $\epsilon$ transition.

No merging is required.

Design an FSA to recognize the language consisting of…

1. all strings beginning with and ending with 101

### 2.2.2 Alternation (Choice)

Join the alternatives at initial and accepting states to a common start and end with $\epsilon$ transitions.

Design an FSA to recognize the language consisting of…

1. strings beginning with 101 or 110

### 2.2.3 Repetition

Design an FSA to recognize the language consisting of…

1. All strings containing one or more instances of 101

Reveal
2. All strings containing zero or more instances of 101

Reveal
3. all strings composed of 1 or more (non-overlapping) occurrences of 101

Reveal
4. all strings composed of zero or more occurrences of 101 only

Reveal
5. all strings that do not contain 101

Reveal

## 2.3 Converting An NFA to a DFA

1. Convert the automaton below to a deterministic FA.

Reveal

^