← back to Theory of Computation

Nondeterminism

Maheshwari & Smid · Ch. 2 · Introduction to Theory of Computation

A nondeterministic finite automaton (NFA) can be in multiple states at once. It guesses which path to take, and accepts if any path reaches an accepting state. NFAs are not more powerful than DFAs: the subset construction converts any NFA to an equivalent DFA.

NFA: multiple paths at once

An NFA is the same 5-tuple as a DFA, except the transition function maps to sets of states: δ : Q × (Σ ∪ {ε}) → P(Q). At each step the machine can follow any transition, including ε-transitions that consume no input.

q0 q1 q2 q3 q1 --> a q2 --> ε q3 --> b q3 --> a NFA: two branches from q0, one via epsilon-transition.

Simulating an NFA

Track all possible states simultaneously. The NFA accepts if the final set of states contains at least one accepting state.

Scheme
Python

Subset construction: NFA to DFA

Every NFA can be converted to a DFA. Each DFA state represents a set of NFA states. The number of DFA states can be exponential (up to 2n), but in practice most subsets are unreachable.

Scheme
Python

NFA = DFA in power

The subset construction proves that NFAs and DFAs recognize the same class of languages: the regular languages. Nondeterminism is a convenience for design, not an increase in power. The trade-off is state count: the DFA may need exponentially more states.

Neighbors