| |||||||||
In the theory of computation, a nondeterministic finite state machine or nondeterministic finite automaton (NFA) is a finite state machine where for each pair of state and input symbol there may be several possible next states.
A NFA is a 5-tuple, (S, Σ, T, s, A), consisting of
where P(S) is the power set of S and ε is the empty string.
Let M be an NFA such that M = (S, Σ, T, s, A), and X be a string over the alphabet Σ that can be written as x1x2 ... xn where each xi ∈ (Σ ∪{ε}). M accepts the string X if a sequence of states, r0,r1, ..., rn, exists in S with the following conditions:
The machine starts in the start state and reads in a string of symbols from its alphabet. It uses the transition relation T to determine the next state(s) using the current state and the symbol just read or the empty string. If, when it has finished reading, it is in an accepting state, it is said to accept the string, otherwise it is said to reject the string. The set of strings it accepts form a language, which is the language the NFA recognises.
Every NFA has an equivalent DFA. Therefore it is possible to convert an existing NFA into a DFA for the purpose of implementing a simpler machine. This can be performed using the powerset construction which may lead to an exponential raise in the number of necessary states. Such determinization however is necessary to build a complement automaton.
The following example explains a NFA M, with a binary alphabet, which determines if the input contains an even number of 0s or an even number of 1s.
M = (S, Σ, T, s, A) where
0
| 1
| ε
| |
S0
| {}
| {}
| {S1, S3}
|
S1
| {S2}
| {S1}
| {}
|
S2
| {S1}
| {S2}
| {}
|
S3
| {S3}
| {S4}
| {}
|
S4
| {S4}
| {S3}
| {}
|
The state diagram for M is:
M can be viewed as the union of two DFAs: one with states {S1, S2} and the other with states {S3, S4}.
The language of M can be described by the regular language given by this regular expression: