NFA Definition and Acceptance
When you first met the DFA, every input letter pushed the machine to exactly one next state — life was deterministic, almost boring. The NFA breaks that rule on purpose: on a single letter, the machine may branch into several possible futures at once, and it succeeds the moment any one of those futures lands in a final state. That single change unlocks far shorter machine designs and is one of the most elegant ideas in the entire Theory of Computation syllabus for GATE CSE.
Definition: A Nondeterministic Finite Automaton (NFA) is a 5-tuple M = (Q, Σ, δ, q0, F), where Q is a finite set of states, Σ is a finite input alphabet, q0 ∈ Q is the start state, F ⊆ Q is the set of final (accepting) states, and the transition function is δ: Q × Σ → 2^Q. That last piece is the heart of it — δ now returns a set of states, possibly empty, rather than a single state.
Definition: An ε-NFA (or NFA with epsilon moves) is an NFA whose transition function is extended to δ: Q × (Σ ∪ {ε}) → 2^Q, allowing the machine to change state without consuming any input symbol.
Definition: A string w ∈ Σ* is accepted by an NFA iff there exists at least one computation path from q0, consuming exactly the symbols of w, that ends in a state belonging to F. Acceptance is by existence.
What "nondeterminism" really means
A DFA, given a state and an input symbol, has one and only one move. An NFA, in the same situation, may have zero moves, one move, or several moves. Picture it like this: at every step the machine "splits" into all the threads it can take. The string w is accepted if just one of those threads, running in parallel in our imagination, ends in F when the input is exhausted. If every single thread dies (no transition available) or ends in a non-final state, the string is rejected.
This is sometimes called the angelic interpretation of nondeterminism — the machine is allowed to magically choose the right path if one exists. You can think of an NFA as a "guess-and-check" device: it guesses which path to take and accepts if the guess can work out. Memory aid: NFA = guess and check — accept if any guess works.
ε-transitions and ε-closure
ε-moves let the machine slide from one state to another for free — without reading any input. This is great for gluing sub-automata together in constructions like Thompson's construction for regular expressions.
Definition: The ε-closure of a state q, written ECLOSE(q), is the set of all states reachable from q using zero or more ε-transitions. For a set S, ECLOSE(S) is the union of ECLOSE(q) for every q ∈ S. The state q itself is always in its own ε-closure.
When you simulate an ε-NFA on the fly, the trick is to keep "current set of states" closed under ε. After every symbol consumed you re-apply ECLOSE so that any state silently reachable is also in your active set. Missing this step is the single most common silly mistake in GATE numerical answer questions on automata simulation.
The big equivalence theorem
Here is the result that often surprises students on first contact: NFAs, ε-NFAs and DFAs all recognise exactly the same class of languages — the regular languages. Nondeterminism does not let an NFA accept anything that some DFA cannot also accept; it only lets the description be more compact.
The constructive proof is the subset construction (also called powerset construction). Given an NFA with n states, you build an equivalent DFA whose states are subsets of the NFA's state set — so up to 2^n states. Each DFA state remembers "the set of NFA states the machine could currently be in." Acceptance in the DFA is: any subset that contains at least one NFA-final state is final.
For ε-NFAs, the construction is the same but with ECLOSE applied at the start state and after every transition.
Why the equivalence matters
It tells us that "regular language" is a robust notion — it does not depend on whether the recognising machine is deterministic or not, or whether it can take silent steps. This robustness is exactly why regular languages are also captured by regular expressions and by right-linear grammars. The cost we pay is size: the equivalent DFA can be exponentially larger than the original NFA. There is a classical family of languages L_n (strings whose nth-last symbol is 1) for which any NFA needs n+1 states but every DFA needs 2^n states.
Real-world example
Inside grep, egrep, lexical analysers in compilers (lex / flex), and string-matching libraries, regular expressions are first compiled into an ε-NFA via Thompson's construction, then converted to a DFA via subset construction, and finally minimised. The NFA is small and easy to build; the DFA is fast to run. You are using this exact pipeline every time you write a regex in Python, Java or while filtering log files on a Linux server.
Common misconception
Misconception: "An NFA is more powerful than a DFA because it can do more." Correction: An NFA is more convenient, not more powerful. Power, in formal language theory, means "the class of languages recognised." NFAs and DFAs recognise the exact same class — the regular languages. The difference is succinctness of the description, not strength.
A second classic confusion: "If the NFA has no transition on some symbol from the current state, the machine crashes and the whole computation fails." Not quite — only that particular thread dies. Other live threads keep running, and the string is still accepted if any thread eventually reaches F.
Worked example
Question: Let N be an NFA over Σ = {a, b} with states {q0, q1, q2}, start state q0, final state {q2}, and transitions δ(q0,a) = {q0, q1}, δ(q0,b) = {q0}, δ(q1,b) = {q2}, δ(q2,a)=δ(q2,b)={q2}. Does N accept the string "aab"?
Solution:
Step 1: Start with the active set {q0}.
Step 2: Read 'a'. New active set = δ(q0,a) = {q0, q1}.
Step 3: Read 'a'. From q0 on 'a' → {q0, q1}; from q1 on 'a' there is no transition, so that thread dies. New active set = {q0, q1}.
Step 4: Read 'b'. From q0 on 'b' → {q0}; from q1 on 'b' → {q2}. New active set = {q0, q2}.
Step 5: Input exhausted. Active set {q0, q2} contains the final state q2.
Conclusion: At least one computation path ends in F, so "aab" is accepted.
Notice the language being recognised: any string that has "ab" anywhere as a substring. The same language needs a 3-state DFA — same size here, but for n-th-from-last patterns the DFA blows up exponentially.
| Feature | DFA | NFA | ε-NFA |
|---|---|---|---|
| δ returns | exactly one state | a set of states | a set of states |
| ε-moves allowed | No | No | Yes |
| Acceptance criterion | unique path ends in F | some path ends in F | some path ends in F |
| Languages recognised | Regular | Regular | Regular |
| Worst-case states for the same language | 2^n | n | n |
| Easy to simulate by hand | Yes | Track a set of states | Also track ECLOSE |
- ✓- An NFA is M = (Q, Σ, δ, q0, F) with δ: Q × Σ → 2^Q returning a set of states.
- ✓- An ε-NFA adds ε-moves: free transitions that consume no input symbol.
- ✓- A string is accepted iff at least one computation path ends in a final state — acceptance is by existence.
- ✓- ε-closure of a state set = all states reachable using only ε-moves; always re-apply after every symbol.
- ✓- DFA, NFA and ε-NFA are equivalent in language-recognising power; all capture exactly the regular languages.
- ✓- The subset construction converts an NFA with n states into a DFA with up to 2^n states.
- ✓- NFAs gain succinctness, not power; the size blow-up is the price of determinisation.
"Guess, branch, check — accept if any branch survives." For ε-NFAs add: "Free moves first, then read the letter, then free moves again" — i.e., always wrap your transitions in ε-closure on both sides.
- ✓- NFA = nondeterministic finite automaton with set-valued δ; ε-NFA additionally allows silent ε-moves.
- ✓- Acceptance is existential: one good path is enough.
- ✓- DFA ≡ NFA ≡ ε-NFA in language power; subset construction proves it constructively.
- ✓- Nondeterminism buys compactness, not new languages.
Subset Construction (NFA → DFA)
Every NFA looks like it has a magical power — it can "choose" the right transition out of several possibilities. But computers don't guess. To actually run an NFA on a machine, we convert it into an equivalent DFA where every step is deterministic. The trick that makes this work is one of the most elegant ideas in automata theory: the subset construction.
Definition: Subset construction (also called the powerset construction) is the algorithm that takes any NFA with n states and produces an equivalent DFA whose states are subsets of the NFA's state set.
Definition: ε-closure of a state q is the set of all NFA states reachable from q by following zero or more ε-transitions (including q itself).
The core idea — simulating "all possibilities at once"
When an NFA reads an input, it might be in several states simultaneously because of non-determinism and ε-moves. The DFA we build keeps track of the entire set of NFA states the machine could currently be in. Each DFA state is literally a label like {q0, q2, q5} — a snapshot of "where could the NFA be right now?"
So if the NFA has n states, the DFA could in principle have one state for every subset of those n states. Since a set of n elements has 2^n subsets, the upper bound on the number of DFA states is 2^n. This includes the empty set ∅, which represents the situation where the NFA cannot be in any valid state — a dead state from which no acceptance is possible.
The algorithm — step by step
The construction is mechanical once you internalise three ingredients:
Step 1: Start state. The DFA's start state is the ε-closure of the NFA's start state, i.e., ε-closure({q0}).
Step 2: Transition function. For a DFA state S and an input symbol a:
δ_DFA(S, a) = ε-closure( ∪ { δ(q, a) : q ∈ S } )
In words: from every NFA state in S, take all a-transitions, union the results, then take the ε-closure of that union.
Step 3: Accepting states. A DFA state S is accepting iff S contains at least one NFA final state.
Step 4: Build only reachable subsets. Start from the initial DFA state and expand outwards by computing transitions. Add a new subset only when it actually appears as a destination. This is why real DFAs are usually much smaller than 2^n — most subsets are unreachable.
Why it matters
Subset construction is the bridge between the expressive world of NFAs (easy to design, ε-moves, multiple branches) and the executable world of DFAs (linear-time simulation, one path through the input). Every regex-to-DFA compiler — grep, lex, flex, JavaScript regex engines — uses this idea under the hood. In GATE CSE, this topic is a perennial favourite: questions ask you to either run the construction by hand or count DFA states for a given NFA.
Worst case: the 2^n bound is tight
Usually we say "in practice the DFA is small". But there are languages where the bound truly is exponential. The classic example is the language
L_n = { w ∈ {0,1}* : the n-th symbol from the right end of w is 1 }
An NFA for L_n needs only n+1 states (a simple chain that guesses where the n-th-last symbol is). But any DFA accepting L_n must have at least 2^n states, because the DFA has to remember the last n input symbols, and there are 2^n possible n-bit windows. This is one of the cleanest demonstrations that non-determinism truly compresses information.
Real-world example: Consider an Indian PAN-card validator. The pattern "5 letters, 4 digits, 1 letter" can be written as a tiny NFA with a few states. When a fintech firm bakes this into a high-throughput compliance pipeline, it first compiles the regex to an NFA, then runs subset construction to obtain a DFA that validates millions of PAN strings per second — each character causing exactly one DFA transition, no backtracking, no branching.
Common misconception: Students often think the DFA produced by subset construction is automatically minimal. It is not. Subset construction can leave equivalent states that should be merged. You apply the DFA minimisation algorithm (Hopcroft / partition refinement) afterwards to obtain the unique minimal DFA. The two algorithms are siblings, not the same algorithm.
A worked example
Question: Convert the NFA below into a DFA.
States: {A, B, C}, alphabet {0,1}, start A, final C.
Transitions: δ(A,0)={A,B}, δ(A,1)={A}, δ(B,1)={C}.
Solution:
Step 1: Start state = {A} (no ε-moves here, so ε-closure({A}) = {A}).
Step 2: From {A} on 0: δ(A,0) = {A,B} → new DFA state {A,B}. On 1: δ(A,1) = {A} → stays at {A}.
Step 3: From {A,B} on 0: δ(A,0) ∪ δ(B,0) = {A,B} ∪ ∅ = {A,B}. On 1: δ(A,1) ∪ δ(B,1) = {A} ∪ {C} = {A,C} → new DFA state.
Step 4: From {A,C} on 0: {A,B} ∪ ∅ = {A,B}. On 1: {A} ∪ ∅ = {A}.
Step 5: No new subsets appear. Mark every DFA state that contains C as accepting → {A,C}.
Conclusion: The reachable DFA has just 3 states — {A}, {A,B}, {A,C} — far fewer than the 2^3 = 8 upper bound, because we only enumerated reachable subsets.
Handling ε-NFA carefully
When the NFA has ε-moves, you must take the ε-closure at three places:
- The start state — ε-closure({q0}).
- Every transition result — after computing the union of δ(q,a) for q in S, wrap it in ε-closure.
- Nowhere else — ε is not an input symbol; the DFA's input alphabet is the original alphabet without ε.
Forgetting the closure on transitions is the single most common mistake in GATE-style problems and produces a DFA that quietly rejects strings it should accept.
| Aspect | NFA | DFA after subset construction |
|---|---|---|
| State count | n | up to 2^n (often far fewer) |
| Transitions per (state, symbol) | 0, 1 or many | exactly 1 |
| ε-moves | allowed | none |
| Simulation cost on input of length m | O(n²·m) | O(m) |
| Ease of design | high | lower |
- ✓- DFA states are subsets of NFA states; upper bound is 2^n.
- ✓- Start state = ε-closure of the NFA start state.
- ✓- Transition: union of NFA transitions, then ε-closure.
- ✓- A DFA state is accepting iff it contains an NFA final state.
- ✓- Always build only reachable subsets — don't list all 2^n.
- ✓- ∅ acts as a dead state (no NFA state is "alive").
- ✓- Worst-case 2^n is tight for languages like "n-th symbol from the end".
- ✓- Subset construction does not minimise — apply DFA minimisation afterwards.
Remember the four C's: Closure on start, union, Closure on transitions, Contains-final means accept, Carry only reachable subsets forward.
- ✓- Subset construction makes the non-deterministic NFA executable as a DFA.
- ✓- The DFA tracks the set of all NFA states the machine could currently be in.
- ✓- Worst-case blow-up is exponential but usually polynomial in practice.
- ✓- Apply minimisation separately to get the smallest equivalent DFA.
Example: The 2^n blow-up language
Language L_k = strings over {0,1} whose k-th symbol from the END is 1. An NFA recognizes L_k with k+1 states (guess the position, then count k-1 more). But the MINIMAL DFA needs exactly 2^k states because it must remember the last k symbols seen. This is the classic example proving the subset-construction 2^n upper bound is tight. For k=2: NFA has 3 states, minimal DFA has 4 states. Memory aid: 'NFA guesses where; DFA must remember everything.' GATE frequently asks for DFA state counts of such 'from-the-end' languages.
NFA, ε-NFA and Subset Construction — Flashcards
Cover the answer, recall, then check. 12 cards on NFAs and ε-NFAs.
Q1. How does an NFA's transition function differ from a DFA's?
A1. δ: Q×Σ → 2^Q (maps to a set of states, possibly empty), so 0, 1 or many moves per symbol.
Q2. How does an ε-NFA extend an ordinary NFA?
A2. δ: Q×(Σ∪{ε}) → 2^Q — it may change state on ε (empty input), reading nothing.
Q3. When does an NFA accept string w?
A3. If at least one computation path from q0 on w ends in an accepting state (existential acceptance).
Q4. Are NFA, ε-NFA and DFA equal in power?
A4. Yes — all three recognize exactly the regular languages. ε-moves and non-determinism add convenience, not power.
Q5. Define ε-closure(q).
A5. All states reachable from q via zero or more ε-edges, including q itself.
Q6. In subset construction with ε-moves, the DFA start state is?
A6. ε-closure(q0).
Q7. Best-case state savings: NFA vs DFA for "ends with the k-th-from-last symbol = 1"?
A7. NFA ≈ k+1 states; DFA = 2^k states — exponential gap.
Q8. Why are NFAs convenient for building automata from regular expressions?
A8. Thompson's construction wires up union/concatenation/star cleanly using ε-transitions, giving an ε-NFA directly.
Q9. How many states does Thompson's construction add per regex operator?
A9. A constant number, so the resulting ε-NFA has O(|regex|) states.
Q10. Does adding non-determinism let an NFA accept a non-regular language?
A10. No. Any NFA/ε-NFA language is regular (subset construction gives an equivalent DFA).
Q11. For subset construction, δ_DFA(S,a) with ε-moves equals?
A11. ε-closure( ∪_{q∈S} δ(q,a) ).
Q12. An NFA with n states — worst-case equivalent DFA size, and is it always that big?
A12. ≤ 2^n; not always — you only build reachable subsets, which is often much smaller.
NFA, ε-NFA and Subset Construction — Summary
A Nondeterministic Finite Automaton (NFA) relaxes the DFA rule: its transition function δ: Q×Σ → 2^Q maps each (state, symbol) to a set of states — zero, one, or many moves. An ε-NFA goes further, allowing moves on ε (reading no input): δ: Q×(Σ∪{ε}) → 2^Q. Acceptance is existential — a string is accepted if at least one computation path ends in an accepting state. Despite the extra freedom, all three models — DFA, NFA, ε-NFA — recognize exactly the regular languages.
ε-closure and subset construction
The bridge to a DFA is the subset construction, built on the ε-closure: ε-closure(q) is every state reachable from q by zero or more ε-edges (q included).
- Start: ε-closure(q0).
- Move: δ_DFA(S, a) = ε-closure( ∪_{q∈S} δ(q, a) ).
- Accept: any subset containing a final state.
Only reachable subsets are built; the empty set is the dead state.
Why non-determinism matters in practice
NFAs and ε-NFAs are the natural target of Thompson's construction, which turns a regular expression into an ε-NFA of size O(|regex|) by wiring operators together with ε-edges. This makes NFAs the standard intermediate form in regex → DFA pipelines.
The three models compared
| Model | δ signature | ε-moves | States for regex R | Power |
|---|---|---|---|---|
| DFA | Q×Σ → Q | no | up to 2^(O( | R |
| NFA | Q×Σ → 2^Q | no | O( | R |
| ε-NFA | Q×(Σ∪{ε}) → 2^Q | yes | O( | R |
The state count can differ exponentially, but the language class never does.
Exam Tricks & Tips
- 🎯 NFA = DFA = ε-NFA in power — any "is L regular?" question is unaffected by which model recognizes it.
- 🎯 Existential acceptance: one accepting path is enough; to show rejection you must rule out all paths.
- 🎯 ε-closure twice in subset construction — on the start state and after each symbol move.
- 🎯 k-th-from-end is the canonical exponential-savings example (NFA k+1 vs DFA 2^k states).
- 🎯 Thompson's construction ⇒ O(|regex|) ε-NFA states — memorise this for regex-to-automaton size questions.
- ❌ Common mistake: thinking non-determinism or ε-moves increase expressive power — they only reduce state count.
Expected exam pattern
1–2 marks. Typical stems: count NFA vs DFA states for a language, compute an ε-closure, identify the DFA start/dead state, or a true/false comparing NFA and DFA power.
Quick recap
NFA: sets of moves, existential acceptance. ε-NFA: also moves on ε. Subset construction (with ε-closure on start and after each move) converts either to a DFA of ≤ 2^n states. All three recognize the same regular languages; non-determinism buys conciseness, not power.