Skip to content
Part IA Michaelmas, Lent Term

The Subset Construction

The Goal

Convert an NFA (or NFA-ε\varepsilon) MM to an equivalent DFA P(M)\mathcal{P}(M) that recognises the same language.

The Construction

Input

NFA-ε\varepsilon M=(Q,Σ,Δ,τ,s,F)M = (Q, \Sigma, \Delta, \tau, s, F)

Output

DFA P(M)=(Q,Σ,δ,s,F)\mathcal{P}(M) = (Q', \Sigma, \delta', s', F')

States

Q=P(Q)={S:SQ}Q' = \mathcal{P}(Q) = \{S : S \subseteq Q\}

Each DFA state is a set of NFA states.

Start State

s=E(s)={q:sεq}s' = E(s) = \{q' : s \xrightarrow{\varepsilon^*} q'\}

The ε\varepsilon-closure of the NFA’s start state.

Accepting States

F={SQ:SF}F' = \{S \subseteq Q : S \cap F \neq \emptyset\}

A DFA state is accepting if it contains at least one NFA accepting state.

Transition Function

For SQS \subseteq Q and aΣa \in \Sigma:

δ(S,a)=qS{q:qaqεq for some q}\delta'(S, a) = \bigcup_{q \in S} \{q' : q \xrightarrow{a} q'' \xrightarrow{\varepsilon^*} q' \text{ for some } q''\}

Equivalently: the set of all states reachable from SS on symbol aa, followed by any number of ε\varepsilon-transitions.

Algorithm Summary

  1. Start with ε\varepsilon-closure of {s}\{s\}
  2. For each reachable set SS and symbol aa, compute δ(S,a)\delta'(S, a)
  3. Add newly discovered states to worklist
  4. Repeat until no new states

Example

NFA

NFA for subset construction example

MM: Q={q0,q1,q2}Q = \{q_0, q_1, q_2\}, s=q0s = q_0, F={q2}F = \{q_2\}

Transitions:

  • q0aq0q_0 \xrightarrow{a} q_0, q0aq1q_0 \xrightarrow{a} q_1
  • q1bq2q_1 \xrightarrow{b} q_2

DFA Construction

Start: s=E(q0)={q0}s' = E(q_0) = \{q_0\}

Compute transitions:

DFA Stateaabb
{q0}\{q_0\}{q0,q1}\{q_0, q_1\}\emptyset
{q0,q1}\{q_0, q_1\}{q0,q1}\{q_0, q_1\}{q2}\{q_2\}
{q2}\{q_2\}\emptyset\emptyset
\emptyset\emptyset\emptyset

Accepting: F={{q2}}F' = \{\{q_2\}\} (states containing q2q_2)

Resulting DFA

DFA from subset construction

Size

Worst Case

The DFA can have up to 2Q2^{|Q|} states.

Typical Case

Many subsets may be unreachable, so the actual DFA is often smaller.

Exponential Blowup

Some NFAs require exponentially many DFA states. Example: language of strings where the nn-th symbol from the end is aa requires Ω(2n)\Omega(2^n) DFA states but only n+1n+1 NFA states.

Key Intuition

The DFA simulates “all possible computations” of the NFA simultaneously.

  • DFA state == set of NFA states that could be active
  • Transition == move all active states, take ε\varepsilon-closures
  • Accepting == any active state is an NFA accept state

Summary

  • Subset construction: NFA state \mapsto DFA state = set of NFA states
  • DFA simulates all NFA computations in parallel
  • Start state = ε\varepsilon-closure of NFA start
  • Accept if intersection with FF is non-empty
  • Worst case: exponential blowup in state count