Algorithm Search⌘K

Proofs: Subset construction

These are the human proofs of Subset construction, at full length.

The subset construction builds a complete DFA with the language of the NFA full

This proof shows: correctness, termination.

Let N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F) be the input, with δ:Q×(Σ∪{ε})→P(Q)\delta : Q \times (\Sigma \cup \{\varepsilon\}) \to \mathcal{P}(Q). For S⊆QS \subseteq Q, let E(S)E(S) be the set of states rr such that there is a path p0,p1,…,pkp_0, p_1, \ldots, p_k with k≥0k \ge 0, p0∈Sp_0 \in S, pk=rp_k = r and pi∈δ(pi−1,ε)p_i \in \delta(p_{i-1}, \varepsilon) for 1≤i≤k1 \le i \le k. For S⊆QS \subseteq Q and a∈Σa \in \Sigma, let step(S,a)=⋃q∈Sδ(q,a)\mathrm{step}(S, a) = \bigcup_{q \in S} \delta(q, a).

A run of NN on w=a1⋯aℓw = a_1 \cdots a_\ell is a sequence of states joined by moves, which starts in q0q_0, whose labels in order are a1,…,aℓa_1, \ldots, a_\ell with any number of ε\varepsilon labels between them, before them and after them. Let R(w)R(w) be the set of the last states of the runs on ww. By definition, w∈L(N)w \in L(N) if and only if R(w)∩F≠∅R(w) \cap F \ne \emptyset.

Lemma 1 (CLOSE). CLOSE(S)(S) stops and returns E(S)E(S).

Proof. A state enters CC at most once, and it is pushed on KK only when it enters CC, so line L13 runs at most ∣Q∣|Q| times and the loop stops. We show two inclusions for the returned CC.

C⊆E(S)C \subseteq E(S): at line L11, C=S⊆E(S)C = S \subseteq E(S), because a path with k=0k = 0 is allowed. Line L14 adds rr only when r∈δ(q,ε)r \in \delta(q, \varepsilon) for some q∈Cq \in C. If q∈E(S)q \in E(S) by a path ending in qq, then that path followed by rr shows r∈E(S)r \in E(S). So C⊆E(S)C \subseteq E(S) holds after each step.

E(S)⊆CE(S) \subseteq C: each state of CC is pushed once and popped once before the loop ends, and when qq is popped, line L14 adds each element of δ(q,ε)\delta(q, \varepsilon) to CC. So the final CC contains SS and is closed under ε\varepsilon-moves: q∈Cq \in C and r∈δ(q,ε)r \in \delta(q, \varepsilon) give r∈Cr \in C. By induction on kk, the last state of each path p0,…,pkp_0, \ldots, p_k with p0∈Sp_0 \in S lies in CC. □\square

Lemma 2. R(ε)=E({q0})R(\varepsilon) = E(\{q_0\}), and R(wa)=E(step(R(w),a))R(wa) = E(\mathrm{step}(R(w), a)) for each w∈Σ∗w \in \Sigma^* and a∈Σa \in \Sigma.

Proof. A run on ε\varepsilon is a path of ε\varepsilon-moves from q0q_0, so R(ε)=E({q0})R(\varepsilon) = E(\{q_0\}). A run on wawa has exactly one move labelled aa, the last move with a symbol label. Cut the run there. The part before the move is a run on ww, ending in a state q∈R(w)q \in R(w). The move goes to a state p∈δ(q,a)p \in \delta(q, a), so p∈step(R(w),a)p \in \mathrm{step}(R(w), a). The part after the move is a path of ε\varepsilon-moves from pp, so the last state is in E(step(R(w),a))E(\mathrm{step}(R(w), a)). Conversely, each q∈R(w)q \in R(w) with a run on ww, each p∈δ(q,a)p \in \delta(q, a) and each path of ε\varepsilon-moves from pp join into a run on wawa. □\square

Lemma 3 (termination and completeness). The loop of line L3 stops. At the end, δ′(S,a)\delta'(S, a) is defined for each S∈Q′S \in Q' and each a∈Σa \in \Sigma, and δ′(S,a)∈Q′\delta'(S, a) \in Q'.

Proof. A set enters WW only at line L2 or line L7, and only when it is not yet in Q′Q', after which it is in Q′Q'. Sets are never removed from Q′Q'. So each set enters WW at most once, and since Q′⊆P(Q)Q' \subseteq \mathcal{P}(Q), the loop runs at most 2∣Q∣2^{|Q|} times. Each run of the loop removes one set, so the loop stops, and each set of Q′Q' is removed once. When SS is removed, lines L5 to L8 define δ′(S,a)\delta'(S, a) for each a∈Σa \in \Sigma, and line L7 puts the value into Q′Q' before line L8 uses it. □\square

Theorem. The DFA D=(Q′,Σ,δ′,S0,F′)D = (Q', \Sigma, \delta', S_0, F') returned at line L10 is complete, each of its states is reachable from S0S_0, and L(D)=L(N)L(D) = L(N).

Proof. Completeness is Lemma 3. Each set is put into Q′Q' at line L2, as S0S_0, or at line L7 as δ′(S,a)\delta'(S, a) of a set SS already in Q′Q'; by induction on the order of insertion, each set of Q′Q' is reachable from S0S_0.

We prove δ′∗(S0,w)=R(w)\delta'^*(S_0, w) = R(w) by induction on ∣w∣|w|. For w=εw = \varepsilon, $\delta'^*(S_0, \varepsilon) = S_0 = $ CLOSE({q0})=E({q0})=R(ε)(\{q_0\}) = E(\{q_0\}) = R(\varepsilon) by Lemma 1 and Lemma 2. For wawa, let S=δ′∗(S0,w)S = \delta'^*(S_0, w), which equals R(w)R(w) by the induction hypothesis. By line L6 and Lemma 1, δ′(S,a)=E(step(S,a))\delta'(S, a) = E(\mathrm{step}(S, a)), which is R(wa)R(wa) by Lemma 2. So δ′∗(S0,wa)=δ′(S,a)=R(wa)\delta'^*(S_0, wa) = \delta'(S, a) = R(wa).

By line L9, DD accepts ww if and only if δ′∗(S0,w)∩F≠∅\delta'^*(S_0, w) \cap F \ne \emptyset, that is, R(w)∩F≠∅R(w) \cap F \ne \emptyset, that is, w∈L(N)w \in L(N). ■\blacksquare

Back to Subset construction