This page uses content from Wikipedia and is licensed under CC BYSA.
In automata theory, a finite state machine is called a deterministic finite automaton (DFA), if
A nondeterministic finite automaton (NFA), or nondeterministic finite state machine, does not need to obey these restrictions. In particular, every DFA is also an NFA. Sometimes the term NFA is used in a narrower sense, referring to a NFA that is not a DFA, but not in this article.
Using the subset construction algorithm, each NFA can be translated to an equivalent DFA, i.e. a DFA recognizing the same formal language.^{[1]} Like DFAs, NFAs only recognize regular languages.
NFAs were introduced in 1959 by Michael O. Rabin and Dana Scott,^{[2]} who also showed their equivalence to DFAs. NFAs are used in the implementation of regular expressions: Thompson's construction is an algorithm for compiling a regular expression to an NFA that can efficiently perform pattern matching on strings.
NFAs have been generalized in multiple ways, e.g., nondeterministic finite automaton with εmoves, finite state transducers, pushdown automata, alternating automata, ωautomata, and probabilistic automata. Besides the DFAs, other known special cases of NFAs are unambiguous finite automata (UFA) and selfverifying finite automata (SVFA).
An NFA, similar to a DFA, consumes a string of input symbols. For each input symbol, it transitions to a new state until all input symbols have been consumed. Unlike a DFA, it is nondeterministic, i.e., for some state and input symbol, the next state may be nothing or one or two or more possible states. Thus, in the formal definition, the next state is an element of the power set of the states, which is a set of states to be considered at once. The notion of accepting an input is similar to that for the DFA. When the last input symbol is consumed, the NFA accepts if and only if there is some set of transitions that will take it to an accepting state. Equivalently, it rejects, if, no matter what transitions are applied, it would not end in an accepting state.
An NFA is represented formally by a 5tuple, , consisting of
Here, denotes the power set of . Let be a word over the alphabet . The automaton accepts the word if a sequence of states, , exists in with the following conditions:
In words, the first condition says that the machine starts in the start state . The second condition says that given each character of string , the machine will transition from state to state according to the transition function . The last condition says that the machine accepts if the last input of causes the machine to halt in one of the accepting states. In order for to be accepted by , it is not required that every state sequence ends in an accepting state, it is sufficient if one does. Otherwise, i.e. if it is impossible at all to get from to a state from by following , it is said that the automaton rejects the string. The set of strings accepts is the language recognized by and this language is denoted by .
We can also define in terms of such that:
Now .
Note that there is a single initial state, which is not necessary. Sometimes, NFAs are defined with a set of initial states. There is an easy construction that translates a NFA with multiple initial states to a NFA with single initial state, which provides a convenient notation.
For a more elementary introduction of the formal definition see automata theory.
Let be an NFA, with a binary alphabet, that determines if the input ends with a 1.
In formal notation, let where the transition function can be defined by this state transition table:
Input State

0  1 

Note that has more than one state, therefore is nondeterministic.
The language of can be described by the regular language given by the regular expression (01)*1
.
Some possible state sequences for the input word "1011" are:
Input:  1  0  1  1  

State sequence 1:  p  q  ?  
State sequence 2:  p  p  p  q  ?  
State sequence 3:  p  p  p  p  q 
The word is accepted by since state sequence 3 satisfies the above definition; it doesn't matter that sequences 1 and 2 fail to do so. In contrast, the word "10" is rejected by , since there is no way to reach the only accepting state, , by reading the final 0 symbol or by an εtransition.
A Deterministic finite automaton (DFA) can be seen as a special kind of NFA, in which for each state and alphabet, the transition function has exactly one state. Thus, it is clear that every formal language that can be recognized by a DFA can be recognized by a NFA.
Conversely, for each NFA, there is a DFA such that it recognizes the same formal language. The DFA can be constructed using the powerset construction.
This result shows that NFAs, despite their additional flexibility, are unable to recognize languages that cannot be recognized by some DFA. It is also important in practice for converting easiertoconstruct NFAs into more efficiently executable DFAs. However, if the NFA has n states, the resulting DFA may have up to 2^{n} states, which sometimes makes the construction impractical for large NFAs.
Nondeterministic finite automaton with εmoves (NFAε) is a further generalization to NFA. This automaton replaces the transition function with the one that allows the empty string ε as a possible input. The transitions without consuming an input symbol are called εtransitions. In the state diagrams, they are usually labeled with the Greek letter ε. εtransitions provide a convenient way of modeling the systems whose current states are not precisely known: i.e., if we are modeling a system and it is not clear whether the current state (after processing some input string) should be q or q', then we can add an εtransition between these two states, thus putting the automaton in both states simultaneously.
An NFAε is represented formally by a 5tuple, , consisting of
Here, denotes the power set of and ε denotes empty string.
For a state , let denote the set of states that are reachable from by following εtransitions in the transition function , i.e., if there is a sequence of states such that
is known as the εclosure of .
εclosure is also defined for a set of states. The εclosure of a set of states, , of an NFA is defined as the set of states reachable from any state in following εtransitions. Formally, for ∪_{q∈P} E(q).
Let be a word over the alphabet . The automaton accepts the word if a sequence of states, , exists in with the following conditions:
In words, the first condition says that the machine starts at the state that is reachable from the start state via εtransitions. The second condition says that after reading , the machine takes a transition of from to , and then takes any number of εtransitions according to to move from to . The last condition says that the machine accepts if the last input of causes the machine to halt in one of the accepting states. Otherwise, it is said that the automaton rejects the string. The set of strings accepts is the language recognized by and this language is denoted by .
Let be a NFAε, with a binary alphabet, that determines if the input contains an even number of 0s or an even number of 1s. Note that 0 occurrences is an even number of occurrences as well.
In formal notation, let where the transition relation can be defined by this state transition table:
Input State

0  1  ε 

S_{0}  {}  {}  {S_{1}, S_{3}} 
S_{1}  {S_{2}}  {S_{1}}  {} 
S_{2}  {S_{1}}  {S_{2}}  {} 
S_{3}  {S_{3}}  {S_{4}}  {} 
S_{4}  {S_{4}}  {S_{3}}  {} 
can be viewed as the union of two DFAs: one with states and the other with states . The language of can be described by the regular language given by this regular expression (1*(01*01*)*) ∪ (0*(10*10*)*). We define using εmoves but can be defined without using εmoves.
To show NFAε is equivalent to NFA, first note that NFA is a special case of NFAε, so it remains to show for every NFAε, there exists an equivalent NFA.
Let be a NFAε. The NFA is equivalent to , where for each and , .
Thus NFAε is equivalent to NFA. Since NFA is equivalent to DFA, NFAε is also equivalent to DFA.
NFAs are said to be closed under a (binary/unary) operator if NFAs recognize the languages that are obtained by applying the operation on the NFA recognizable languages. The NFAs are closed under the following operations.
Since NFAs are equivalent to nondeterministic finite automaton with εmoves (NFAε), the above closures are proved using closure properties of NFAε. The above closure properties imply that NFAs only recognize regular languages.
NFAs can be constructed from any regular expression using Thompson's construction algorithm.
The machine starts in the specified initial state and reads in a string of symbols from its alphabet. The automaton uses the state transition function Δ to determine the next state using the current state, and the symbol just read or the empty string. However, "the next state of an NFA depends not only on the current input event, but also on an arbitrary number of subsequent input events. Until these subsequent events occur it is not possible to determine which state the machine is in".^{[3]} If, when the automaton has finished reading, it is in an accepting state, the NFA is said to accept the string, otherwise it is said to reject the string.
The set of all strings accepted by an NFA is the language the NFA accepts. This language is a regular language.
For every NFA a deterministic finite automaton (DFA) can be found that accepts the same language. Therefore, it is possible to convert an existing NFA into a DFA for the purpose of implementing a (perhaps) simpler machine. This can be performed using the powerset construction, which may lead to an exponential rise in the number of necessary states. For a formal proof of the powerset construction, please see the Powerset construction article.
There are many ways to implement a NFA:
NFAs and DFAs are equivalent in that if a language is recognized by an NFA, it is also recognized by a DFA and vice versa. The establishment of such equivalence is important and useful. It is useful because constructing an NFA to recognize a given language is sometimes much easier than constructing a DFA for that language. It is important because NFAs can be used to reduce the complexity of the mathematical work required to establish many important properties in the theory of computation. For example, it is much easier to prove closure properties of regular languages using NFAs than DFAs.