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 an 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. Conversely, Kleene's algorithm can be used to convert an NFA into a regular expression (whose size is generally exponential in the input automaton).
NFAs have been generalized in multiple ways, e.g., nondeterministic finite automata with ε-moves, finite-state transducers, pushdown automata, alternating automata, ω-automata, and probabilistic automata.Besides the DFAs, other known special cases of NFAsare unambiguous finite automata (UFA)and self-verifying finite automata (SVFA).
There are two ways to describe the behavior of an NFA, and both of them are equivalent. The first way makes use of the nondeterminism in the name of an NFA. For each input symbol, the NFA transitions to a new state until all input symbols have been consumed. In each step, the automaton nondeterministically "chooses" one of the applicable transitions. If there exists at least one "lucky run", i.e. some sequence of choices leading to an accepting state after completely consuming the input, it is accepted. Otherwise, i.e. if no choice sequence at all can consume all the input[3] and lead to an accepting state, the input is rejected.[4] [5]
In the second way, the NFA consumes a string of input symbols, one by one. In each step, whenever two or more transitions are applicable, it "clones" itself into appropriately many copies, each one following a different transition. If no transition is applicable, the current copy is in a dead end, and it "dies". If, after consuming the complete input, any of the copies is in an accept state, the input is accepted, else, it is rejected.[4] [6] [7]
For a more elementary introduction of the formal definition, see automata theory.
An NFA is represented formally by a 5-tuple,
(Q,\Sigma,\delta,q0,F)
Q
\Sigma
\delta
Q x \Sigma → l{P}(Q)
q0\inQ
F
F\subseteqQ
Here,
l{P}(Q)
Q
Given an NFA
M=(Q,\Sigma,\delta,q0,F)
L(M)
\Sigma
M
Loosely corresponding to the above informal explanations, there are several equivalent formal definitions of a string
w=a1a2...an
M
w
r0,r1,...,rn
Q
r0=q0
ri+1\in\delta(ri,ai+1)
i=0,\ldots,n-1
rn\inF
In words, the first condition says that the machine starts in the start state
q0
w
\delta
w
w
w
M
q0
F
w
M
M
L(M)
w
*(q | |
\delta | |
0, |
w)\capF\not=\emptyset
\delta*:Q x \Sigma* → l{P}(Q)
\delta*(r,\epsilon)=\{r\}
\epsilon
\delta*(r,xa)=
cup | |
r'\in\delta*(r,x) |
\delta(r',a)
x\in\Sigma*,a\in\Sigma
In words,
\delta*(r,x)
r
x
w
F
q0
w
The above automaton definition uses 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 an NFA with multiple initial states to an NFA with a single initial state, which provides a convenient notation.
M
M=(\{p,q\},\{0,1\},\delta,p,\{q\})
\delta
0 | 1 | ||
---|---|---|---|
p | \{p\} | \{p,q\} | |
q | \emptyset | \emptyset |
\delta(p,1)
M
M
(0|1)*1
.All possible state sequences for the input string "1011" are shown in the lower picture.The string is accepted by
M
M
M
M
\langler0,r1,r2,r3,r4\rangle=\langlep,p,p,p,q\rangle
\delta*(p,\epsilon)=\{p\}
\delta*(p,1)=\delta(p,1)=\{p,q\}
\delta*(p,10)=\delta(p,0)\cup\delta(q,0)=\{p\}\cup\{\}
\delta*(p,101)=\delta(p,1)=\{p,q\}
\delta*(p,1011)=\delta(p,1)\cup\delta(q,1)=\{p,q\}\cup\{\}
\{q\}
In contrast, the string "10" is rejected by
M
q
q
A deterministic finite automaton (DFA) can be seen as a special kind of NFA, in which for each state and symbol, 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 an 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 easier-to-construct NFAs into more efficiently executable DFAs. However, if the NFA has n states, the resulting DFA may have up to 2n states, which sometimes makes the construction impractical for large NFAs.
Nondeterministic finite automaton with ε-moves (NFA-ε) is a further generalization to NFA. In this kind of automaton, the transition function is additionally defined on the empty string ε. A transition without consuming an input symbol is called an ε-transition and is represented in state diagrams by an arrow labeled "ε". ε-transitions provide a convenient way of modeling 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 5-tuple,
(Q,\Sigma,\delta,q0,F)
Q
\Sigma
\delta:Q x (\Sigma\cup\{\epsilon\}) → l{P}(Q)
q0\inQ
F
F\subseteqQ
Here,
l{P}(Q)
Q
\epsilon
For a state
q\inQ
E(q)
q
\delta
p\inE(q)
q1,...,qk
q1=q
qi+1\in\delta(qi,\varepsilon)
1\lei<k
qk=p
E(q)
q
The ε-closure of a set
P
P
P\subseteqQ
E(P)=cup\limitsq\inE(q)
Similar to NFA without ε-moves, the transition function
\delta
\delta*(q,w)
q\inQ
w\in\Sigma*.
\delta*:Q x \Sigma* → l{P}(Q)
\delta*(q,\varepsilon)=E(q)
q\inQ,
E
Informally: Reading the empty string may drive the automaton from state
q
q.
q\inQ,
w\in\Sigma*
a\in\Sigma.
Informally: Reading the string
w
q
r
\delta*(q,w)
a
r
\delta(r,a).
The automaton is said to accept a string
w
*(q | |
\delta | |
0,w) |
\capF ≠ \emptyset,
w
q0
F.
Let
M
In formal notation, let wherethe transition relation
\delta
M
\{S1,S2\}
\{S3,S4\}
M
(1*01*0)*\cup(0*10*1)*
M
M
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.
Given an NFA with epsilon moves
M=(Q,\Sigma,\delta,q0,F),
M'=(Q,\Sigma,\delta',q0,F'),
F'=\begin{cases}F\cup\{q0\}&ifE(q0)\capF ≠ \{\}\ F&otherwise\ \end{cases}
\delta'(q,a)=\delta*(q,a)
q\inQ
a\in\Sigma,
\delta*
One has to distinguish the transition functions of
M
M',
\delta
\delta',
\delta
\delta'*,
M'
One can prove that
*(q | |
\delta' | |
0,w) |
=
*(q | |
\delta | |
0,w) |
w ≠ \varepsilon
w.
Based on this, one can show that
*(q | |
\delta' | |
0,w) |
\capF' ≠ \{\}
*(q | |
\delta | |
0,w) |
\capF ≠ \{\},
w\in\Sigma*:
w=\varepsilon,
F'.
w=va
v\in\Sigma*
a\in\Sigma.
From
*(q | |
\delta' | |
0,w) |
=
*(q | |
\delta | |
0,w) |
F\subseteqF',
⇒
*(q | |
\delta' | |
0,w) |
F'\setminus\{q0\},
*(q | |
\delta | |
0,w) |
F
*(q | |
\delta' | |
0,w) |
q0,
q0\inF,
*(q | |
\delta | |
0,w) |
F,
q0.
*(q | |
\delta' | |
0,w) |
q0,
q0\not\inF,
q0\inF',
E(q0)\capF
Since NFA is equivalent to DFA, NFA-ε is also equivalent to DFA.
The set of languages recognized by NFAs is closed under the following operations. These closure operations are used in Thompson's construction algorithm, which constructs an NFA from any regular expression. They can also be used to prove that NFAs recognize exactly the regular languages.
Since NFAs are equivalent to nondeterministic finite automaton with ε-moves (NFA-ε), the above closures are proved using closure properties of NFA-ε.
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".[8] 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.