Designing NFAs
- embrace the nondeterminism
- good model: guess and check
- is there some information that you’d really like to have? have the machine nondeterministically guess that information
- then, have the machine deterministically check that the choice was correct
- the guess phase corresponds to trying lots of different options
- check phase corresponds to filtering out bad guesses or wrong options
Example
$L=\{w \in \{0,1\}^* ~|~ \text{$w$ ends in 010 or 101} \}$
- it would be a lot easier if you knew where the string ends
- let start $\to_\Sigma$ start
- start $\to_0$ node $\to_1$ node $\to_0$ accepting state
- start $\to_1$ node $\to_0$ node $\to_1$ accepting state
- the genius of this NFA is that it allows the complex part (remembering what the last three characters are) to be part of the nondeterminism
Another Example
$L=\{w \in \{a,b,c\}^*~|~\text{at least one of a, b, and c is not in $w$} \}$
- it would be easier if you knew which character was missing
- lets say you had a node $\to_{a,b}$ same node, node is accepting state
- this is a NFA that allows for only a and b
- now, we can glue 3 copies of that together
- start $\to_\varepsilon$ node 1, node 2, node 3 (guess which character is missing)
- node 1 $\to_{a,b}$ node 1 (accepting)
- node 2 $\to_{a,c}$ node 2 (accepting)
- node 3 $\to_{b, c}$ node 3 (accepting)
Implementing DFAs and NFAs
-
Tabular DFAs
- can make a 2D array representing every transition
- can make every row as a state, every column as a particular label for a transition
- each element in the 2D table is the result of the transition