Introduction

A nondeterministic finite automaton (NFA) may have zero, one or many next states for a given state and symbol. It accepts a string if some sequence of choices leads to an accepting state. Allowing ε\varepsilon-transitions (moves without reading input) gives an ε\varepsilon-NFA. Despite the extra freedom, NFAs and ε\varepsilon-NFAs recognize exactly the same languages as DFAs: the regular languages.

The constructive proof is the subset construction (powerset construction): each DFA state is a set of NFA states, recording every place the NFA could be. The working skills are (a) drawing a small NFA, (b) building the subset DFA, and (c) knowing that the DFA may need up to 2n2^n states for an nn-state NFA.

Prerequisites

Core concepts

NFA without ε\varepsilon

An NFA is N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) where δ:Q×Σ→2Q\delta: Q \times \Sigma \to 2^Q (the power set of QQ). From state qq on symbol aa, the machine may move to any state in δ(q,a)\delta(q,a). If δ(q,a)=∅\delta(q,a) = \emptyset, that branch dies.

Acceptance. Extend δ\delta to sets of states and to strings: the NFA accepts ww if there exists a sequence of states q0,q1,…,q∣w∣q_0, q_1, \ldots, q_{|w|} with qi+1∈δ(qi,wi+1)q_{i+1} \in \delta(q_i, w_{i+1}) and q∣w∣∈Fq_{|w|} \in F. Equivalently, δ^(q0,w)∩F≠∅\hat{\delta}(q_0, w) \cap F \neq \emptyset.

NFA versus DFA. Every DFA is an NFA whose δ\delta values are always singletons. The converse simulation needs the subset construction.

ε\varepsilon-NFA

An ε\varepsilon-NFA allows transitions on ε\varepsilon as well: δ:Q×(Σ∪{ε})→2Q\delta: Q \times (\Sigma \cup \{\varepsilon\}) \to 2^Q.

The ε\varepsilon-closure ε-closure(S)\varepsilon\text{-closure}(S) of a set of states SS is the set of states reachable from SS by zero or more ε\varepsilon-moves (including the states in SS themselves). For an epsilon-closed current set SS, reading a symbol aa goes to the expression below; for arbitrary SS, first take its epsilon-closure:

ε-closure(⋃q∈Sδ(q,a)).\varepsilon\text{-closure}\bigl(\bigcup_{q \in S} \delta(q,a)\bigr).

Acceptance: after processing ww, the resulting ε\varepsilon-closed set intersects FF.

Why nondeterminism helps design

To accept strings ending with 01, an NFA can stay in a looping start state on 00 and 11, and also "guess" that the current 00 starts the final 01 by moving to a progress state. Here the saving is nothing (the minimal DFA also has 3 states), but for "the nn-th symbol from the end is 1" the NFA has n+1n+1 states and the minimal DFA 2n2^n.

How it works

Subset construction (no ε\varepsilon)

Input: NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F).

Output: DFA M=(QD,Σ,δD,qD,FD)M = (Q_D, \Sigma, \delta_D, q_D, F_D).

  1. States of MM are subsets of QQ. Only reachable subsets from {q0}\{q_0\} are needed.
  2. Start state qD={q0}q_D = \{q_0\}.
  3. δD(S,a)=⋃q∈Sδ(q,a)\delta_D(S, a) = \bigcup_{q \in S} \delta(q,a).
  4. SS is accepting iff S∩F≠∅S \cap F \neq \emptyset.

At most 2∣Q∣2^{|Q|} DFA states; many are often unreachable.

Subset construction with ε\varepsilon

Same, but the start state is ε-closure({q0})\varepsilon\text{-closure}(\{q_0\}), and

δD(S,a)=ε-closure(⋃q∈Sδ(q,a)).\delta_D(S,a) = \varepsilon\text{-closure}\Bigl(\bigcup_{q \in S} \delta(q,a)\Bigr).

Eliminating ε\varepsilon-transitions alone

An ε\varepsilon-NFA converts to an ordinary NFA (still nondeterministic) by: for each state qq and symbol aa, put an aa-transition from qq to every state in ε-closure(δ(ε-closure({q}),a))\varepsilon\text{-closure}(\delta(\varepsilon\text{-closure}(\{q\}), a)) after adjusting acceptance so that qq is accepting if ε-closure({q})\varepsilon\text{-closure}(\{q\}) meets FF. The subset construction already folds this in, so separate elimination is optional.

Algorithms and pseudocode

Text
EPSILON-CLOSURE(N, S)
1  T <- set(S);  stack <- list(S)
2  while stack not empty
3      q <- pop(stack)
4      for each p in N.delta[q][eps]
5          if p not in T
6              add p to T; push p
7  return T

SUBSET-CONSTRUCT(N)
1  qD <- EPSILON-CLOSURE(N, {N.q0})
2  QDmark <- {qD};  work <- queue(qD);  deltaD <- empty map
3  while work not empty
4      S <- dequeue(work)
5      for each a in Sigma
6          T <- EPSILON-CLOSURE(N, union of N.delta[q][a] for q in S)
7          deltaD[S][a] <- T
8          if T not in QDmark
9              add T to QDmark; enqueue T
10 FD <- { S in QDmark | S intersects N.F }
11 return DFA(QDmark, Sigma, deltaD, qD, FD)

Correctness: by induction on ∣w∣|w|, the DFA state after ww equals the set of NFA states reachable on ww. Hence the languages coincide.

Mathematical explanation

Worst-case blow-up

For n≥1n\ge1, the language over {0,1}\{0,1\} whose nn-th symbol from the end is 1 has an n+1n+1-state NFA: a looping start state guesses that 1, then uses nn states to count through the remaining n−1n-1 symbols to acceptance. Its minimal reachable subset DFA has 2n2^n states, remembering the last nn bits (with appropriate leading-zero padding for short strings). This witness proves exponential worst-case growth; the general 2∣Q∣2^{|Q|} subset upper bound remains valid.

Equivalence chain

DFA⊆NFA⊆ε-NFA⊆DFA\mathrm{DFA} \subseteq \mathrm{NFA} \subseteq \varepsilon\text{-NFA} \subseteq \mathrm{DFA}

(the last inclusion via subset construction), so all three models define the regular languages.

Worked examples

Example 1: NFA for strings ending with 01

States q0,q1,q2q_0,q_1,q_2 with q2q_2 accepting.

  • δ(q0,0)={q0,q1}\delta(q_0,0) = \{q_0,q_1\}, δ(q0,1)={q0}\delta(q_0,1) = \{q_0\}.
  • δ(q1,1)={q2}\delta(q_1,1) = \{q_2\}, δ(q1,0)=∅\delta(q_1,0) = \emptyset.
  • δ(q2,0)=δ(q2,1)=∅\delta(q_2,0)=\delta(q_2,1)=\emptyset.

For a cleaner total NFA that continues matching, send q2q_2 on 00 to {q0,q1}\{q_0,q_1\} and on 11 to {q0}\{q_0\}. The extra edges change nothing: q0q_0 is active after every prefix and already offers the same moves.

Example 2: subset construction

Using the NFA above (with or without the continuation edges from q2q_2), the reachable subsets are exactly {q0}\{q_0\}, {q0,q1}\{q_0,q_1\} and {q0,q2}\{q_0,q_2\}. Accepting subsets are those containing q2q_2, here only {q0,q2}\{q_0,q_2\}. The subset {q0,q1,q2}\{q_0,q_1,q_2\} is never reached: the only way into q2q_2 is on 1, and no state moves to q1q_1 on 1. The resulting 3-state DFA is already minimal and accepts exactly the strings ending in 01.

NFA for strings ending with 01 and the DFA from subset construction
Figure 1. Left: NFA with states q0, q1, q2 accepting strings ending in 01. Right: reachable subset DFA with exactly three states, {q0}, {q0,q1} and {q0,q2}; the subset {q0,q1,q2} is never reached, and the accepting subset is {q0,q2}.

Example 3: ε\varepsilon-NFA for a+ba+b

Start ss, accept ff. Edges: s→εps \xrightarrow{\varepsilon} p, s→εrs \xrightarrow{\varepsilon} r, p→afp \xrightarrow{a} f, r→bfr \xrightarrow{b} f. Then ε-closure({s})={s,p,r}\varepsilon\text{-closure}(\{s\}) = \{s,p,r\}. On aa the DFA moves to ε-closure({f})\varepsilon\text{-closure}(\{f\}). Language {a,b}\{a,b\}.

Example 4: exponential lower bound sketch for n=2n=2

Language: second bit from the end is 11. NFA with 3 states guesses; minimal DFA needs 4 states (all length-2 binary memories). For general nn, DFA needs 2n2^n states.

Example 5: step-by-step subset table for a 3-state NFA

Take the NFA with transitions from q0 on 0 to {q0,q1}, from q0 on 1 to {q0}, from q1 on 1 to {q2}, and continuation from q2 on 0 to {q0,q1}, from q2 on 1 to {q0}; accept {q2}.

Subset Son 0on 1Accept?
{q0}{q0,q1}{q0}no
{q0,q1}{q0,q1}{q0,q2}no
{q0,q2}{q0,q1}{q0}yes

Start at {q0}. String 01 visits {q0} then {q0,q1} then {q0,q2} (accept). String 010 continues to {q0,q1} (reject). Only these 3 subsets are reachable; a subset such as {q0,q1,q2} can be written down but no input leads to it, so it is not part of the DFA. Listing unreachable subsets gives a wrong state count.

Example 6: subset construction with ε\varepsilon-moves

The ε\varepsilon-NFA has states 0, 1, 2 (only state 2 accepts) with 0→a00 \xrightarrow{a} 0, 0→ε10 \xrightarrow{\varepsilon} 1, 1→b11 \xrightarrow{b} 1, 1→ε21 \xrightarrow{\varepsilon} 2, 2→c22 \xrightarrow{c} 2. It accepts a∗b∗c∗a^* b^* c^*.

Closures first: ε-closure({0})={0,1,2}\varepsilon\text{-closure}(\{0\}) = \{0,1,2\}, ε-closure({1})={1,2}\varepsilon\text{-closure}(\{1\}) = \{1,2\}, ε-closure({2})={2}\varepsilon\text{-closure}(\{2\}) = \{2\}.

DFA stateon aon bon cAccept?
A={0,1,2}A = \{0,1,2\} (start)AABBCCyes
B={1,2}B = \{1,2\}∅\emptysetBBCCyes
C={2}C = \{2\}∅\emptyset∅\emptysetCCyes
∅\emptyset∅\emptyset∅\emptyset∅\emptysetno

Four DFA states including the dead set. The start state accepts because its closure already contains 2, so ε\varepsilon is accepted. abc goes A,A,B,CA, A, B, C and is accepted; ba goes A,B,∅A, B, \emptyset and is rejected.

Example 7: the blow-up family, exactly

Ln={w∈{0,1}∗∣the n-th symbol from the end is 1}L_n = \{ w \in \{0,1\}^* \mid \text{the } n\text{-th symbol from the end is } 1 \}. The NFA loops on q0q_0, guesses the critical 1 by moving to q1q_1, then reads any n−1n-1 symbols through q2,…,qnq_2, \ldots, q_n: n+1n+1 states. Subset construction reaches exactly 2n2^n subsets (each records which of the last nn positions held a 1), and all 2n2^n are pairwise distinguishable: if xx and yy of length nn differ at position ii, append any i−1i-1 symbols and the ii-th position becomes the nn-th from the end. For n=1,2,3,4n = 1, 2, 3, 4: NFA 2, 3, 4, 5 states; minimal DFA 2, 4, 8, 16 states.

Different count: the reverse language. "The nn-th symbol from the start is 1" needs only n+2n+2 DFA states (count to nn, then an accepting sink or a dead state). Reversal can change DFA size exponentially, which is why the reversal construction goes through an NFA.

Related material. Alternating finite automata and two-way NFAs also recognize only regular languages; they are not required for GATE CSE.

Important properties and observations

  • Acceptance is existential ("some path"), not universal.
  • ε\varepsilon-closure must be applied after every real symbol move and at the start.
  • Empty transition sets are legal in NFAs; they just kill that branch.
  • The subset DFA may include a sink ∅\emptyset if some NFA moves die.
  • NFAs do not accept "more languages" than DFAs; they accept more succinctly.

Constructions that stay inside NFAs.

OperationNFA constructionExtra states
Union L1∪L2L_1 \cup L_2new start with ε\varepsilon to both starts1
Concatenation L1L2L_1 L_2ε\varepsilon from every accept of N1N_1 to the start of N2N_2; only N2N_2's accepts remain0
Star L∗L^*new accepting start with ε\varepsilon to the old start; ε\varepsilon from old accepts back to the old start1
Reversal LRL^Rreverse every edge, old start becomes the only accept, new start with ε\varepsilon to every old accept1
Complementnot available directly: determinize first, complete, then swapup to 2n2^n
Intersectionproduct of the two NFAs (pairs of states)n1n2n_1 n_2 total

Swapping accept states of an NFA is not complement. Take the 3-state NFA for "ends with 01" and make q0,q1q_0, q_1 accepting and q2q_2 non-accepting. On input 01 the run that stays in q0q_0 still accepts, so the swapped NFA accepts a string that is in LL. It actually accepts every string, since q0q_0 is always active. An NFA accepts if some run accepts; complement needs every run to reject, which only a DFA expresses by a single run.

Star needs a new start state. Making the old start state accepting and adding ε\varepsilon-edges back to it can accept extra strings when the old start has incoming edges. For example, with an NFA for a∗ba^* b whose start state loops on aa, that shortcut accepts a, which is not in (a∗b)∗(a^* b)^*.

NFA versus DFA counts. Same language class; state complexity can differ exponentially.

Common misconceptions.

  • "Nondeterminism means the machine randomly rejects." In language theory it means existence of an accepting computation, not probability.
  • "ε\varepsilon-transitions read the empty symbol as input consuming time." They consume no input symbol.
  • "Subset construction always produces 2n2^n states." Only reachable subsets matter; often far fewer.

GATE examination perspective

  • BUILD THE SUBSET TABLE. Rows = subsets found so far; columns = symbols; close under ε\varepsilon if present.
  • MARK ACCEPTING SUBSETS. Any subset meeting FF, not only {f}\{f\}.
  • EXPONENTIAL EXAMPLE. "nn-th from end is 1" is the standard blow-up witness.
  • DESIGN WITH GUESSING. NFAs for "contain substring ww" or "end with ww" are often easier than DFAs; convert if a DFA is required.
  • DEAD EMPTY SET. If the powerset DFA has ∅\emptyset, it is a rejecting sink, and it counts as a state of the complete DFA.
  • REACHABLE ONLY. "How many states does the subset construction produce" means reachable subsets from the start closure; never answer 2n2^n unless every subset is reached.
  • START CLOSURE. With ε\varepsilon-moves the DFA start is ε-closure({q0})\varepsilon\text{-closure}(\{q_0\}), not {q0}\{q_0\}. If the closure meets FF, ε\varepsilon is accepted.
  • COMPLEMENT TRAP. Flipping accept states of an NFA does not complement it.
  • STATE BOUNDS. NFA to DFA: at most 2n2^n states and the bound is reached; DFA to NFA: no increase.

Summary

Sources

  1. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley, Section 2.3 (nondeterministic finite automata, including 2.3.6 "A Bad Case for the Subset Construction"), Section 2.5 (finite automata with epsilon-transitions, epsilon-closures, eliminating epsilon-transitions).
  2. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 1.2 (nondeterminism, equivalence of NFAs and DFAs, closure under the regular operations).
  3. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning: Sections 2.2 and 2.3 (nondeterministic accepters and their equivalence with deterministic ones).

Next steps