Subset construction
Converting an NFA (with or without epsilon moves) into an equivalent DFA: the DFA's states are sets of NFA states, the start set is the epsilon closure of the start state, transitions follow all moves and take closures, a set is accepting if it contains an accepting NFA state; building only the reachable subsets, the dead state, the exponential blow-up (the n-th symbol from the end needs 2^n states), and the fact that the result need not be minimal.
Why it exists
Nondeterministic machines are convenient to design but cannot be run directly by simple hardware or a simple program: a DFA can. The subset construction shows that nothing is lost: every NFA can be converted into a DFA for the same language. It is the algorithm that turns the NFA produced from a regular expression into the DFA of a scanner, and its worst case, an exponential blow-up, is one of the standard facts GATE asks.
Prerequisites
You need the NFA, its epsilon closure and the set simulation (NFA).
Precise definitions
Let be an NFA (it may have edges). The subset construction builds the DFA :
- the states of are sets of states of : ;
- the start state is ;
- for a set and a symbol : (every state of moves on , then the closure is taken);
- is accepting iff .
The empty set is a legitimate state: it is the dead state of (once reached, no computation of survives).
Correctness idea. After reading , the DFA is in the set of all NFA states that some computation on can be in. So accepts iff some computation of accepts .
How it works
The algorithm
- Compute and put it in the list of discovered sets.
- Take the next undiscovered-transition set from the list. For each symbol compute . Record the transition. If is new, add it to the list.
- Stop when every set in the list has all its transitions. Mark as accepting every set that contains a state of .
Only sets reachable from are built, so the DFA usually has far fewer than states.
Example 1: ends with 01
The NFA has states ( loops on ; ; ; accepting). Start: . On : ; on : . From : on : , has no -edge: ; on : , : . From : on : ( has no edges); on : . Three sets, which is the DFA for "ends with " (the contains so it accepts).
Subset construction for the NFA of 'ends with 01': start
Computed by a script, not typed| DFA state (set of NFA states) | on 0 | on 1 | accepting? |
|---|---|---|---|
| {p} | |||
| {p,q} | |||
| {p,r} |
Step 0
Start from {p}. For each set and each symbol take the set of all states reachable by one move; new sets become new DFA states. Only sets that can be reached from {p} are built (3 of the 8 possible subsets).
Example 2: the third symbol from the end is 1
The NFA ( states) leads to reachable subsets; each records which of the last three symbols were (a can be a "guess candidate" at distance , or from the end). The DFA below is the result; run it on and compare with the NFA run of the previous page: the DFA is in one state at a time, which is the set that the NFA had active.
Subset construction when the third symbol from the end is 1: start
Computed by a script, not typed| DFA state (set of NFA states) | on 0 | on 1 | accepting? |
|---|---|---|---|
| {p} | |||
| {p,s1} | |||
| {p,s2} | |||
| {p,s1,s2} | |||
| {p,s3} | |||
| {p,s1,s3} | |||
| {p,s2,s3} | |||
| {p,s1,s2,s3} |
Step 0
The NFA has 4 states (p, s1, s2, s3). The subset construction produces 8 reachable subsets, and all 8 are needed (the DFA is minimal): the DFA must remember the last 3 symbols.
The DFA (8 states) from the subset construction for the same language: start
Simulated, not typedDouble circle = accepting state. Arrow from nowhere = start state.
Step 0
Start in the start state {p}. The machine reads the input from left to right, one symbol at a time, and every symbol moves it along exactly one edge.
The blow-up: is reached
For the language "the -th symbol from the end is " the NFA has states and the subset construction produces states, and no DFA for the language has fewer: the strings of length are pairwise distinguishable (two different ones differ in some position ; appending symbols puts that position at the -th place from the end, accepted after one string and rejected after the other). So the worst case of the construction is exact.
The exponential price of determinism: start
Computed by a script, not typed| n | NFA states | DFA states (subset construction) | states of the minimal DFA | 2^n |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 6 |
Step 0
For each n, the language of the binary strings whose n-th symbol from the end is 1, recognised by an NFA with n + 1 states. Converting to a DFA needs 2^n states, and this cannot be improved.
For a general -state NFA the DFA has at most states, and this bound is reached by the machines above.
Epsilon moves
Take the closure at the start and after every move; the rest is unchanged. For the -NFA for (states with an -loop and an edge to , with a -loop, accepting): the start set is ; on : , closure ; on : ; from on : (dead), on : . Three DFA states: , , , the DFA with a dead state that has the language . (The accepting ones are the first two, since they contain .)
The result need not be minimal
The NFA for "contains or " has states; the subset construction produces reachable sets; two of them, and , behave identically and are merged by minimisation, leaving states (minimisation). A good procedure is: build the subset DFA, then minimise it.
Subset construction for 'contains 00 or 11': a DFA that is not yet minimal: start
Computed by a script, not typed| DFA state (set of NFA states) | on 0 | on 1 | accepting? |
|---|---|---|---|
| {s} | |||
| {a,s} | |||
| {b,s} | |||
| {a,s,t} | |||
| {b,s,t} |
Step 0
The NFA has 4 states. The subset construction builds 5 reachable subsets; two of them are equivalent, so the minimal DFA has only 4 states.
Cost of doing it
The construction takes time proportional to the size of the DFA times times the work to compute a set (about per move with closures): exponential in the worst case. In practice compilers build the DFA lazily, only for the states that the input actually reaches, or minimise the NFA first.
Worked examples
EX 1A two-state NFA
EasyNFA over : , , , ; start , accepting . Subset construction: : on , on . : on : ; on : . : loops. DFA states , (accepting), : states. The language is : the strings that start with , end with and contain no . Check: ends in , accepted; ends in , rejected; goes to , rejected.
EX 2How many states at most
EasyAn NFA with states can give a DFA with at most states (counting the empty set). With moves the bound is the same. The DFA for the example "fifth symbol from the end is " has exactly states.
EX 3Only reachable subsets
MediumFor the NFA of "ends with " the powerset has subsets but only are reachable from (, , ). For the NFA "contains or " the powerset has and are reachable. Always build the table by following transitions from the start set, not by listing all subsets.
EX 4With an epsilon move
MediumNFA: states ; , , ; start , accepting . Start set . On : : (no further from ). On : nothing: . From : on : ; on : . From : on : , on : . DFA states: , (accepting), , : states. The language is . The states and behave alike, so minimisation leaves states.
EX 5Typical questions
GATE level(a) The maximum number of states of the DFA obtained from an -state NFA by the subset construction: . (b) Is the DFA from the subset construction always minimal? No. (c) The minimum number of states of a DFA for the language whose -th symbol from the end is : (the NFA has ). (d) Which subset is the dead state? . (e) Which subsets are accepting? Those that contain at least one accepting NFA state. (f) Is the bound ever reached? Yes: the NFA with states over , edges , , , , start and accepting state , has a minimal DFA with states; for and machines with DFA states also exist (found by search); in general the bound is tight (a result of Moore).
Cheat box
Cheat box
- DFA states = sets of NFA states. Start . . Accepting iff the set meets . is the dead state.
- Build only reachable subsets (follow transitions from the start set).
- At most states. The -th symbol from the end is : NFA states, minimal DFA .
- The result may be non-minimal: minimise afterwards.
- Epsilon NFA: closure at the start and after each move.
Traps and GATE patterns
Connections
Builds on
Across subjects
The construction is the second half of "regular expression to scanner" (lexical analysis); the DFA it produces is then reduced by minimisation; combined with the product it gives the closure of regular languages under complement (closure properties).
PYQs
5 previous year questions from your book. I re-solved each one myself (2 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs
Let M be a nondeterministic finite automaton (NFA) with 6 states over a finite alphabet. Which of the following options CANNOT be the number of states in the minimal deterministic finite automaton (DFA) that is equivalent to M?
- (a). 32
- (b). 65
- (c). 1
- (d).128
A regular language L is accepted by a non-deterministic finite automaton (NFA) with n states. Which of the following statement(s) is/are FALSE?
- (a). L may have an accepting NFA with < n states.
- (b). L may have an accepting DFA with < n states.
- (c). There exists a DFA with ≤ 2n states that accepts L.
- (d). Every DFA that accepts L has > 2n states.
Let N be an NFA with n states. Let k be the number of states of a minimal DFA which is equivalent to N. Which one of the following is necessarily true?
- (a)k ≥ 2n
- (b)k ≥ n
- (c)k ≤ n2
- (d)k ≤ 2n
Which of the following pairs have DIFFERENT expressive power?
- (a)Deterministic finite automata (DFA) and Non- deterministic finite automata (NFA)
- (b). Deterministic push down automata (DPDA) and Non-deterministic push down automata (NPDA)
- (c). Deterministic single-tape Turning machine and Non-deterministic single tape Turning machine
- (d). Single-tape Turning machine and multi-tape Turning machine
Consider the regular grammar:
S → Xa | Ya
X → Za
Z → Sa | ε
Y → Wa
W → Sa
where S is the starting symbol, the set of terminals is
{a} and the set of non-terminals is {S, W, X, Y, Z}. We
wish to construct a deterministic finite automaton
(DFA) to recognize the same language. What is the
minimum number of states required for the DFA?- (a)2
- (b)3
- (c)4
- (d)5 THEORY OF COMPUTATION
Self-check
Question 1
An NFA has states, no edges. What is the maximum number of states in the DFA from the subset construction?
Show answerHide
(including the empty set).
Question 2
In the subset construction for an NFA with accepting state , is accepting?
Show answerHide
Yes: it contains .
Question 3
What is the start state of the DFA built from an -NFA with start ?
Show answerHide
.
Question 4
Why does the DFA for "the th symbol from the end is " need states?
Show answerHide
The strings of length are pairwise distinguishable, so any DFA must be in different states after reading them.
Revision card
One-screen revision
- Sets of NFA states; start closure; move then closure; accept iff meets ; = dead.
- Reachable subsets only; at most ; -th symbol from the end: exactly.
- Not necessarily minimal; minimise next.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Section 1.2 (Theorem 1.39: every NFA has an equivalent DFA)
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 2.3.5 and Section 2.5.5 (the subset construction, eliminating epsilon transitions)
- ·Aho, Lam, Sethi, Ullman, Compilers: Principles, Techniques, and Tools (2nd edition), Section 3.7.1 (conversion of an NFA to a DFA)
Verification
The construction in scripts/toc_lib.py was run on 400 random NFAs (half with epsilon moves): the resulting DFA was complete, had only reachable states and at most 2^n states, was equivalent to the NFA by a search of the product automaton and by comparing acceptance on every string up to length 8. For the n-th symbol from the end the subset construction gave exactly 2^n states and minimisation merged none of them, for n = 1 to 6; the 2^n strings of length n have pairwise different futures, which proves the lower bound for n up to 5. The tables are the output of that construction. For 'contains 00 or 11' the construction gave 5 states and the minimal DFA has 4. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)