Finite Automata

NFA to DFA: The Subset Construction, Step by Step

Every NFA state becomes a DFA state that is a set of NFA states — the subset construction, worked through on a machine where the blow-up actually shows up.

The subset construction (also called the powerset construction) turns any NFA into an equivalent DFA. The idea: instead of a DFA state standing for "the NFA is in this one state," it stands for "the NFA could be in any of these states" — a whole subset of the original states at once. Since there are finitely many subsets of a finite set, the resulting machine is still a DFA.

The source NFA

The language here is "the second-to-last symbol of the string is 1" over {0, 1} — a good example precisely because a small NFA blows up into a noticeably larger DFA. The NFA guesses, on each 1, whether that symbol is the second-to-last one, then checks it's right by requiring exactly one more symbol before the string ends.

NFA over {0,1}: second-to-last symbol is 1

Running the construction

Start the DFA at the set containing just the NFA's start state, {n0}. For every reachable set and every input symbol, compute the union of where each state in the set can go on that symbol — that union is the next DFA state. Keep going until no new sets appear.

DFA stateon 0on 1accept?
A = {n0}ABno
B = {n0, n1}CDno
C = {n0, n2}AByes (contains n2)
D = {n0, n1, n2}CDyes (contains n2)

Four reachable subsets from a three-state NFA — the DFA is accepting exactly when its current set contains the NFA's accept state n2, since that means at least one guessed path is still alive and correct.

ABCD01

ABDC∈ F

DFA over {0,1}: second-to-last symbol is 1 (subset construction result)

Try 1101 on both machines: the NFA has to consider every guess at once, while the DFA just follows A → B → D → C, landing in C (accept, since the second-to-last symbol is indeed 0... check it against 0110 and 11 as well to see the pattern hold).

Your turn

Exercise

Build a DFA over {0, 1} whose language is exactly: the second-to-last symbol of the string is 1.

InputExpected
10accept
11accept
110accept
011accept
1010accept
0reject
1reject
ε (empty string)reject
00reject
101reject
000reject

Further reading

Introducing the MCP Server
← All lessonsOpen Simulator →
On this page
All lessons