|
The classic Subset Construction Algorithm takes as input an NFA M and builds a DFA M' recognizing the same language. Each state of M' is identified by a subset of the states in M. Specifically, if the states reachable from the initial state of M by following a sequence of transitions that spell out the string x are precisely those in S = {s1, s2, ..., sk}, then in M' the state S is the one reached by the unique sequence of transitions spelling out x starting at the initial state.
Taking x to be λ, it follows that the initial state of M'
must be the one identified by the singleton (i.e., one-element)
set containing the NFA's initial state.
(For example, if q0 were the NFA's initial state, we would
name the DFA's initial state {q0}.)
Note: If the given NFA has multiple initial states, say those
in the set Q0, then Q0 would be the initial
state in the resulting DFA.
End of note.
Let S = {s1, s2, ..., sn} be the set of states reachable from the initial state of M via transitions spelling out some string x. Suppose further that, for symbol a, the outgoing transitions labeled a from each si went to states qi,1, qi,2, ..., etc. Then, in the DFA, the (lone) outgoing transition labeled a from state S should go to the state identified with the subset containing precisely all the qi,j's, i.e., the set {q1,1, q1,2, ..., q2,1, q2,2, ..., qn,1, qn,2, ... }.
Having established the DFA's initial state, we prepare to continue the construction by placing that state (which, as indicated above, is identified with the set containing the initial state(s) of M) onto a queue.1 Then —as long as the queue is not empty— we repeatedly remove a state from the queue and determine to which state each of its outgoing transitions should go, as described above.
If the target of an outgoing transition is a state not "previously known", it becomes a new state to be added to the DFA, and we place it onto the queue so that, at some later point in time, its outgoing transitions will be determined.
{0} | ||
Original NFA | DFA before first loop iteration | Queue |
---|
{1,2} | ||
Original NFA | DFA after one loop iteration | Queue |
---|
{1,3} {0,2} |
||
Original NFA | DFA after two loop iterations | Queue |
---|
{0,2} {1} |
||
Original NFA | DFA after three loop iterations | Queue |
---|
{1} {1,2,3} |
||
Original NFA | DFA after four loop iterations | Queue |
---|
{1,2,3} | ||
Original NFA | DFA after five loop iterations | Queue |
---|
Original NFA | DFA after six loop iterations | Queue |
---|
No new states are discovered during iteration 6 (hence none are placed onto the queue), and so afterwards the queue is empty. This signals termination of the loop; the constructed DFA is complete. Its tabular description follows.
State | δ | |||
---|---|---|---|---|
Initial? | Final? | State ID | a | b |
✓ | {0} | {1,2} | {0} | |
✓ | {1,2} | {1,3} | {0,2} | |
{1,3} | {1} | {0,2} | ||
✓ | {0,2} | {1,2,3} | {0,2} | |
✓ | {1,2,3} | {1,3} | {0,2} | |
{1} | {1} | {0} |