CMPS 260
Transforming an NFA into an Equivalent DFA
Via the Subset Construction Algorithm: An Example

Consider the following NFA, described using both a transition graph and a table. It fails to be a DFA because state 0 has two outgoing transitions on a.
Stateδ
Initial?Final?State IDab
01,20
110
232
312

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.

Prior to First Loop Iteration:

At this point, the initial state of the DFA has been determined and it has been placed into the queue.

{0}
Original NFA DFA before first loop iteration Queue

Loop Iteration 1:

During the first iteration, state {0} is removed from the queue and its outgoing transitions determined. We find that it has a transition to itself on b and to (new) state {1,2} on a. The new state is placed into the queue.

{1,2}
Original NFA DFA after one loop iteration Queue

Loop Iteration 2:

State {1,2} will be taken off the queue and its outgoing transitions determined. In doing so, two "new" states are identified, namely {1,3} and {0,2}, both of which are placed onto the queue.

{1,3}
{0,2}
Original NFA DFA after two loop iterations Queue

Loop Iteration 3:

The state at the front of the queue, {1,3}, is removed and its outgoing transitions determined. As a result we discover state {1}, which is placed onto the queue. We get

{0,2}
{1}
Original NFA DFA after three loop iterations Queue

Loop Iteration 4:

State {0,2} is removed from the queue and its outgoing transitions are determined during this iteration. The new state discovered is {1,2,3}, which gets placed onto the queue (behind {1}). We get

{1}
{1,2,3}
Original NFA DFA after four loop iterations Queue

Loop Iteration 5:

During this iteration, state {1} is removed from the queue and it is determined that its outgoing transitions go to (already existing) states {1} and {0}, respectively.

{1,2,3}
Original NFA DFA after five loop iterations Queue

Loop Iteration 6:

The lone state remaining on the queue is {1,2,3}. Removing it and computing its outgoing edges, we get

 
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 IDab
{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}


Footnotes

[1] The order in which states are removed from the queue is really irrelevant, so it could just as well be a stack or even a set from which items are chosen and removed pseudo-randomly.