A non-deterministic finite (state) automaton (NFA) is an extension of its deterministic version, allowing it to choose between multiple paths. It does this using the epsilon transitions. In a sense, an NFA is more powerful version of a DFA because the epsilon transitions allows it to run paths in parallel.
Definition
Non-deterministic Finite Automata (NFA) ^definition-dfa
An NFA is defined to contain
- An input alphabet,
- A set of states,
- An initial state,
- A state transition function, which takes the current state and the next character of the input string, and instead of returning a state, returns a set of possible states.:
- A set of accept states,
NFAs are essentially the same as DFA, except for the transition function.
Epsilon Closure ^definition-epsilon-closure
Let be an NFA. Let , be any subset of states of . Then the epsilon-closure (or -closure) of a state is given by:
In other words, if we start at the state , and follow a computation path from to some other state by only taking epsilon transitions, then we add to .
The epsilon closure of a set is then the union of the -closures of its elements:
Note the similarity between epsilon-closure and transitive closure of a graph.
Epsilon Transitions
NFAs introduce a new type of transition known as epsilon transitions or -transitions. These transitions do not consume input characters from the input string.
For example, take the NFA below:
%%🖋 Edit in Excalidraw, and the dark exported image%%
This NFA has two epsilon transitions (in bold), which means when given an input string, it can ‘jump’ from A, going to B or C if possible. It could also not take the transitions, staying in A.
Epsilon-transitions have some key properties:
- Any DFA containing an -transition becomes an NFA.
- Any state connected to an initial state via an epsilon transition becomes an initial state
Theorems
T1: Theorem of Equivalence ^t1
Every NFA has an equivalent DFA. Let be an NFA. Then, there exists a DFA , such that:
and are equivalent. #TODO proof
Examples
1: NFA to equivalent DFA
Convert the NFA given below to an equivalent DFA:
%%🖋 Edit in Excalidraw, and the dark exported image%%
The main procedure is to look at all sets of states that we can transition to for a given input:
- First, we look at all the initial states. Recall that any state connected to an initial state by an epsilon-transition also becomes an initial state. So we have (as 3 is connected to 1 via -transition). Let’s call it .
- From :
- If we encounter a , we can’t do anything (since there is no transition in 1 or 3 that require a . This is notated as the empty set, .
- If we decide to take the
- If we encounter an , however, we can go to the set of states . Let’s call this new set
- From :
- If we encounter an :
- If we take the
- If we encounter an :