The Timpson Lyceum · Computation Theory
Lecture 5 (Computation Theory) Nondeterministic Finite Automata
Nondeterministic Finite Automata – Lecture 5
Overview
This lecture introduces the nondeterministic finite automaton (NFA), the second model of computation in the study of regular languages. Where a deterministic finite automaton (DFA) follows exactly one forced path through its states, an NFA is allowed to branch: from a single state on a single symbol it may move to several states at once, none, or even change state without reading any input at all (an -transition). We build intuition for how an NFA accepts a string, give the formal five-tuple definition, and then prove the central result of the section: every NFA can be converted into an equivalent DFA, so the two models recognize exactly the same class of languages (the regular languages). The payoff is practical — NFAs are often dramatically smaller and clearer to design than the equivalent DFA, even though they are no more powerful.
Key Concepts
Deterministic vs. nondeterministic. In a DFA, the current state plus the input symbol completely determine the next state — exactly one transition out of every state for every alphabet symbol. An NFA relaxes this: for a given state and symbol there may be zero, one, or many possible next states, and the machine may also take -transitions (move without consuming any input).
How an NFA accepts. An NFA accepts a string if there exists at least one path through its states (a sequence of valid transitions) that consumes the whole string and ends in an accept state. Equivalently:
- Think of the machine as exploring all possible paths in parallel — a computation tree. If any leaf lands in an accept state, the string is accepted.
- Or think of it as a machine that may guess which branch to take and is assumed to always guess correctly when acceptance is possible.
- If a branch reaches a state with no valid transition on the next symbol, that branch dies (rejects); other branches may still accept.
-transitions. An edge labeled lets the machine change state without reading a symbol. Reading does not change the underlying string: the string is just the string . So never enters the alphabet of the language — it only appears in the transition rules. These transitions are what make operations like union easy to wire together.
Why NFAs are useful. NFAs frequently express a language far more transparently than a DFA. Example: "the string contains as a substring" is a tiny NFA, but as a DFA the same idea, or "the third-from-last symbol is a ," blows up — tracking the last three symbols needs states. The DFA and NFA are logically equivalent; the NFA is just easier for a human to read.
Formal definition. An NFA is a five-tuple where is a finite set of states, is a finite alphabet, is the start state, and is the set of accept states. The only piece that differs from a DFA is the transition function: where and is the power set of (the set of all subsets of ). So takes a state and either a symbol or , and returns a set of states — possibly empty. For example , while a dead end gives .
Power set. is the set of all subsets of . If then . E.g. has elements, always including . This is exactly the supply of "states" we need when simulating an NFA, because after reading some input the NFA could be in any subset of its states at once.
Formal acceptance. accepts (each ) if there is a sequence of states such that:
- (start in the start state),
- for (every step is a legal transition), and
- (end in an accept state).
Note there is one more state ( of them) than there are input symbols ().
Equivalence of NFAs and DFAs (the subset construction). Every NFA has an equivalent DFA. Given , build a DFA whose states are subsets of 's states — each DFA state records exactly which set of NFA states the machine could currently be in:
- ,
- — accept whenever the current subset contains at least one of 's accept states.
To handle -moves, define the -closure = the set of all states reachable from any state in using zero or more -transitions (including the states of themselves). Then:
- start state ,
- — read from every state you might be in, collect all resulting states, then take the -closure.
Since every DFA is already (trivially) an NFA, the two models recognize the same languages. Corollary: a language is regular if and only if some NFA recognizes it.
Worked Example
Convert the NFA over with states , start state , accept state , and the single -edge , whose transitions are:
Start state. Take the -closure of the NFA start state. The general rule, then the substitution:
A transition. Compute using the subset rule, then substitute:
So from the DFA state , reading returns to . Because contains the NFA accept state , it is an accept state of the DFA (). Continuing this process for every reachable subset and both symbols produces a full DFA over the power set of whose accept states are every subset meeting — and it recognizes exactly the same language as .
Summary
- A DFA has exactly one forced transition per state/symbol; an NFA may branch to several states, none, or move on without reading input.
- An NFA accepts a string if any path through its states consumes the whole string and ends in an accept state — imagine all branches explored in parallel, or a machine that always guesses correctly.
- Formally ; the only change from a DFA is , returning a set of states (possibly ).
- The power set has elements; it supplies the states for simulating an NFA, since the NFA can be in any subset of states at once.
- Subset construction: every NFA converts to an equivalent DFA whose states are subsets of , with start state , transitions , and accept states any subset meeting .
- NFAs and DFAs are therefore equally powerful; a language is regular iff some NFA recognizes it. NFAs are valued for being smaller and clearer to design, not for extra power.