CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 1 · Finite Automata

Lesson 1.2.3 · Item 22 of 91

Subset construction and the 2ⁿ blow-up

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. What is ECLOSE(q)?
    Stuck? Peek at 1.2.2 ε-NFA and ε-closure
    • ε-NFA: δ : Q × (Σ ∪ {ε}) → P(Q).
    • ECLOSE(q) = ε-reachable states incl. q (graph reachability on ε-edges).
    • Run: start ECLOSE(q₀); each symbol: move, then ECLOSE. Accept iff final set ∩ F ≠ ∅.
    • Same power as DFA/NFA; great for wiring machines together.

    Read lesson 1.2.2

  2. When does an NFA accept?
    Stuck? Peek at 1.2.1 Nondeterminism and the NFA
    • NFA: δ : Q × Σ → P(Q); moves may be 0, 1, many.
    • Accept iff some path ends in F ⇔ δ̂(q₀, w) ∩ F ≠ ∅. Track the set of active states.
    • DFA ⊆ NFA; NFAs accept exactly the regular languages.
    • No dead state needed. Swapping F does NOT complement an NFA.

    Read lesson 1.2.1

  3. How many subsets does a 4-element set have?
    Stuck? Peek at 0.2.1 Sets
    • x ∈ A (element) vs X ⊆ A (subset). ∅ ⊆ every set. A = B ⇔ A ⊆ B and B ⊆ A.
    • A ∪ B, A ∩ B, A − B = A ∩ B̅, A̅ = U − A. De Morgan: (A∪B)̅ = A̅∩B̅, (A∩B)̅ = A̅∪B̅.
    • |A ∪ B| = |A| + |B| − |A ∩ B|. |A × B| = |A|·|B|. |P(A)| = 2^|A|.
    • |∅| = 0, |{∅}| = 1, P(∅) = {∅}.

    Read lesson 0.2.1

The Hook

Real hardware can’t clone itself at every fork, so an NFA can’t run as-is on a chip. But look at how we traced NFAs: we kept the set of active states. There are only finitely many such sets. So make each set a single state of a new machine — and that machine is deterministic. This conversion is called the subset construction, and GATE asks you to run it or to count its states.

Predict First

An NFA has 3 states. At most how many states can the DFA produced by the subset construction have?

Core Concept

Prediction check

Answer: 2³ = 8 — one per subset of {q0, q1, q2}, including ∅ (which plays the role of the dead state). Usually far fewer are reachable.

Every DFA state is a corner of the subset cube. Drag to rotate.
Every DFA state is a corner of the subset cube. Drag to rotate.

The construction (NFA → DFA)

Given NFA N = (Q, Σ, δ, q₀, F), build DFA D:
  • States: subsets of Q (only the reachable ones, in practice).
  • Start: {q₀} (for an ε-NFA: ECLOSE(q₀)).
  • δ_D(S, a) = ⋃_{q∈S} δ(q, a) (for an ε-NFA: then take ECLOSE).
  • Accepting: every subset S with S ∩ F ≠ ∅.

Proof idea: by induction on |w|, δ̂_D({q₀}, w) is exactly the active set of N after w. So D accepts w iff N’s active set contains an accepting state iff N accepts w.

steps illustration
Lazy subset construction, one row at a time.

Doing it by hand (lazy construction)

  1. Write the start set. Put it in a worklist.
  2. Take a set S from the worklist; for each symbol, compute the target set. Any new set goes into the worklist.
  3. Repeat until no new sets appear.
  4. Mark sets containing an NFA accepting state.
  5. If ∅ appears, it is the dead state (it maps to itself).
flowplay illustration
The by-hand procedure.

ε-NFA → NFA (removing ε-moves)

Keep the same states. New δ'(q, a) = ECLOSE( ⋃_{p ∈ ECLOSE(q)} δ(p, a) ). New accepting set F' = { q | ECLOSE(q) ∩ F ≠ ∅ } — the start state can become accepting this way. The number of states does not change.

stateECLOSEδ′ on aδ′ on baccepting?
p{p, q}{p, q}{q}yes (closure meets F)
q{q}∅{q}yes
ε-removal for a*b*: same states, new arrows; p becomes accepting.

The 2ⁿ blow-up is real

Language L_k = “the k-th symbol from the end is 1”. NFA: k + 1 states. Any DFA: at least 2ᵏ states. Reason: take two different strings x, y of length k. They differ at some position i; append enough symbols so that position lands exactly k-th from the end: one becomes accepted, the other not. So all 2ᵏ strings of length k need different states.

So: NFA with n states ⇒ equivalent DFA with ≤ 2ⁿ states, and this bound can be (nearly) reached. NFAs can be exponentially more compact.

pairseparating suffix zxzyz
00 vs 10ε00 ✗10 ✓
00 vs 010000 ✗010 ✓
01 vs 11ε01 ✗11 ✓
10 vs 110100 ✗110 ✓
“2nd symbol from the end is 1”: every pair of length-2 strings is separated, so any DFA needs 2² = 4 states. The same argument gives 2ᵏ.

Counting DFA states in GATE questions

  • “Subset construction on this NFA gives how many states?” — run the lazy construction; count only reachable sets; include ∅ if it appears.
  • “Minimum DFA states for k-th from end is 1 over {0,1}” — 2ᵏ.
  • “k-th from the start” — only k + 2 (Lesson 1.1.3). Don’t mix them up.
“3rd from the end is 1”: the NFA states 1, 2, 3 record which of the last three symbols were 1.
“3rd from the end is 1”: the NFA states 1, 2, 3 record which of the last three symbols were 1.

Putting it together

  • Subset construction: a DFA state = a set of NFA states; accepting iff it meets F; ∅ is the dead state.
  • At most 2ⁿ states; count only reachable sets.
  • k-th from the end needs 2ᵏ DFA states; k-th from the start only k + 2.

Visual

NFA ends-with-ab:  q0 —a,b→ q0,  q0 —a→ q1,  q1 —b→ q2 (final)
writing states as numbers {0},{0,1},... :

 set S        on a                 on b
→{0}          {0,1}                {0}
 {0,1}        {0,1}                {0,2}
*{0,2}        {0,1}                {0}       ← contains 2 (final)
 3 reachable sets out of 2³ = 8 possible; ∅ never appears (q0 always active)
DFA from subset construction: ends with ab

States: {0}, {0,1}, {0,2}

Transitions: {0}>{0}: b; {0}>{0,1}: a; {0,1}>{0,1}: a; {0,1}>{0,2}: b; {0,2}>{0,1}: a; {0,2}>{0}: b

3rd-from-end NFA (q0..q3)  → reachable sets: every {0} ∪ X with X ⊆ {1,2,3}  = 2³ = 8 DFA states
each set records which of the last 3 symbols were 1:   {0,1,3} after ...1?1 etc.

Worked Examples

Easy

NFA over {a}: q0 ─a→ q1, q1 ─a→ q0, q1 ─a→ q1; F = {q1}. Run the subset construction.

Show the full solution

{q0} ─a→ {q1}; {q1} ─a→ {q0, q1}; {q0,q1} ─a→ {q1} ∪ {q0,q1} = {q0,q1}. States: {q0}, {q1}*, {q0,q1}*. 3 states. Language: aⁿ, n ≥ 1. (Minimizing would merge the last two → 2 states.)

Medium

Remove ε-moves from the a*b* ε-NFA (p ─a→ p, p ─ε→ q, q ─b→ q, F = {q}).

Show the full solution

ECLOSE(p) = {p,q}, ECLOSE(q) = {q}. δ'(p,a) = ECLOSE(δ(p,a) ∪ δ(q,a)) = ECLOSE({p}) = {p,q}. δ'(p,b) = ECLOSE({q}) = {q}. δ'(q,a) = ∅, δ'(q,b) = {q}. F' = {p, q} (ECLOSE(p) contains q). Check ε is still accepted: p ∈ F' ✓; “ba”: p ─b→ q ─a→ ∅ reject ✓.

GATE-level

NFA over {0,1}: A ─0→ {A,B}, A ─1→ {A}, B ─0→ {C}, B ─1→ {C}, C has no moves, F = {C}. How many states does the subset-construction DFA have, and what is the language?

Show the full solution

{A} ─0→ {A,B}, ─1→ {A}. {A,B} ─0→ {A,B,C}, ─1→ {A,C}. {A,B,C} ─0→ {A,B,C}, ─1→ {A,C}. {A,C} ─0→ {A,B}, ─1→ {A}. Reachable: {A}, {A,B}, {A,B,C}*, {A,C}* = 4 states. Language: second symbol from the end is 0 (2² = 4 ✓).

GATE Traps

  • Count only reachable subsets — not all 2ⁿ.
  • If ∅ appears, it is a real DFA state (the dead state) — count it.
  • A subset is accepting if it contains any NFA accepting state.
  • After removing ε-moves, the start state may become accepting (if ECLOSE(q₀) meets F).
  • k-th symbol from the END: 2ᵏ DFA states; from the START: k + 2.

Memory Hook

Subset construction = a photograph of the whole search party at each moment; the DFA steps from photo to photo.

Connect the Dots

DFA = NFA = ε-NFA in power. The subset construction can produce DFAs with redundant states — like {q1} and {q0,q1} above, which behave identically. Next chapter: how to detect and merge such states to get the minimal DFA, the single most frequent TOC question type in GATE.

Self-Test

  1. NAT

    Minimal DFA states for strings over {0,1} whose 4th symbol from the end is 1?

    Write your answer before opening the key.

  2. NAT

    Minimal DFA states for strings over {0,1} whose 4th symbol from the start is 1?

    Write your answer before opening the key.

  3. MCQ

    In the subset construction, a DFA state S is accepting iff:

    1. S ⊆ F
    2. S ∩ F ≠ ∅
    3. S = F
    4. S contains q₀
  4. MSQ

    An NFA has n states. Which are true?

    1. An equivalent DFA with at most 2ⁿ states exists
    2. Every equivalent DFA has at least 2ⁿ states
    3. Some languages need about 2ⁿ DFA states for an n-state NFA
    4. The subset construction always produces a minimal DFA
  5. NAT

    Subset construction on the ends-with-ab NFA (3 states) yields how many reachable DFA states?

    Write your answer before opening the key.

Rule Card

  • Subset construction: start {q₀} (or ECLOSE(q₀)); δ(S,a) = ⋃ δ(q,a) (then ECLOSE); accept iff S ∩ F ≠ ∅; ∅ = dead state.
  • ≤ 2ⁿ states; count only reachable sets.
  • ε-removal: δ'(q,a) = ECLOSE(δ(ECLOSE(q), a)); F' = {q : ECLOSE(q) ∩ F ≠ ∅}.
  • k-th from end is 1: NFA k+1, DFA 2ᵏ. k-th from start: DFA k+2.
  • DFA ≡ NFA ≡ ε-NFA in power.

Concept Ledger

  • subset construction
  • lazy (reachable-only) construction
  • ε-removal
  • exponential (2ⁿ) blow-up
  • equivalent machines (same language)

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. All states reachable from q by zero or more ε-moves (including q).
  2. When some path for the input ends in an accepting state.
  3. 16.

Self-test answers

  1. 16 — 2⁴.
  2. 6 — k + 2.
  3. B — Some active copy is in an accepting state.
    • A: Too strict.
    • C: Too strict.
    • D: Irrelevant.
  4. AC — Upper bound 2ⁿ; achieved by k-th-from-end languages.
    • B: Often far fewer are needed.
    • D: It can produce equivalent (redundant) states.
  5. 3 — {0}, {0,1}, {0,2}.

Flashcards

  1. Upper bound on DFA states from an n-state NFA?
    Reveal answer2ⁿ
  2. Minimal DFA for “k-th symbol from the end is 1”?
    Reveal answer2ᵏ states.
  3. Which subsets are accepting in the subset construction?
    Reveal answerThose containing at least one NFA accepting state.
  4. What does ∅ become in the subset construction?
    Reveal answerThe dead state.

Exam shortcuts

  • k-th from END → 2ᵏ. k-th from START → k + 2. Write “END = Exponential” on your hand.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.