Non Deterministic Finite Automata (NDFA)
If, for each pair of states and possible input chars, there is a unique next state (as specificed by the transitions), then the FA is deterministic (DFA). Otherwise, the FA is non deterministic finite automata (NDFA).
What does it mean for an FA to have more than one transition from a given state on the same input symbol? How do we translate such an FA into a program? How can we “goto” more than one place at a time?
Conceptually, a nondeterministic FA can follow many paths simultaneously. If any series of valid transitions reaches an accepting state, they we say the FA accepts the input. It’s as if we allow the FA to “guess” which of several transitions to take from a given state, and the FA always guesses right.
We won’t attempt to translate an NDFA into a program, so we don’t have to answer the question “how can we goto more than one place at a time”. Instead, we can prove that every NDFA has a corresponding DFA, and there is a straightforward process for translating an NDFA into a DFA. So, when given an NDFA, we can translate it into a DFA, and then write a program based on the DFA.
Definition of Non Deterministic Finite Automata
NFA is similar to DFA except following additional features:
1. Null (or ε) move is allowed i.e., it can move forward without reading symbols.
2. Ability to transit to any number of states for a particular input.
However, these above features don’t add any power to NFA. If we compare both in terms of power, both are equivalent.
Due to above additional features, NFA has a different transition function, rest is same as DFA.
δ: Transition Function δ: Q X (∑ U ϵ ) --> 2 ^ Q.
As you can see in transition function for any input including null (or &epsilon), NFA can go to any state number of states.
Example of an NDFA
An NDFA to accept strings containing the word “main”:
-> s0 -m-> s1 -a- > s2 -i-> s3 -n-> (s4)
-> s0 -any character-> s0
This is an NDFA because, when in state s0 and seeing an “m”, we can choose to remain in s0 or go to s1. (In effect, we guess whether this “m” is the start of “main” or not.)
If we simulate this NDFA with input “mmainm” we see the NDFA can end up in s0 or s1 after seeing the first “m”. These two states correspond to two different guesses about the input: (1) the “m” represents the start of “main” or (2) the “m” doesn’t represent the start of “main”.
-> s0 -m-> s0 -m-> s1
On seeing the next input character (“m”), one of these guesses is proven wrong, as is there is no transition from s1 for an “m”. That path halts and rejects the input. The other path continues, making a transition from s0 to either s0 or s1, in effect guessing that the second “m” in the input either is or is not the start of the word “main”.
-> s0 -m-> s0 -m-> s0 -m-> s1 -m-> s1
Continuing the simulation, we discover that at the end of the input, the machine can be in state s0 (still looking for the start of “main”), s1 (having seen an “m” and looking for “ain”), or s4 (having seen “main” in the input). Since at least one of these states is an accepting state (s4), the machine accepts the input.
s0 -m-> s0 -m-> s0 -a-> s0 -i-> s0 -n-> s0 -m-> s0 -m-> s1 -m-> s1 -a-> s2 -i-> s3 -n-> s4 -m-> s1