4.6.3Theory of Computation

NFA — formal definition, epsilon transitions

2,101 words10 min readdifficulty · medium

1. What is nondeterminism, really?


2. The formal 5-tuple (built from scratch)

We want to nail down "machine with guessing + free moves." What pieces do we minimally need?

  • A finite collection of memory states → call it QQ.
  • The alphabet of input symbols → Σ\Sigma.
  • A rule saying where we can go → the transition function δ\delta.
  • A place to start → q0q_0.
  • A way to say "you win" → accepting states FF.

The only twist vs DFA is the output type of δ\delta.


3. ε-closure (the tool that handles free moves)

Because ε-moves are free, before/after reading a symbol the machine can silently slide along ε-arrows. We must collect everything reachable for free.

Why "including qq itself"? Zero ε-moves is allowed — you can always "stay put for free."


4. Extended transition δ^\hat\delta (running a whole string)

δ\delta handles one symbol. We derive the rule for a full string ww, folding in ε-moves correctly.

Base case: before reading anything, you're wherever ε-moves take you from the start. δ^(q,ε)=ECLOSE(q)\hat\delta(q,\varepsilon)=\text{ECLOSE}(q)

Inductive step: to process w=xaw=xa (string xx then symbol aa):

  1. Let R=δ^(q,x)R=\hat\delta(q,x) — the set of states after reading xx.
  2. From each rRr\in R, read aa: collect rRδ(r,a)\bigcup_{r\in R}\delta(r,a).
  3. Then take ε-closure (free slides after consuming aa).
Figure — NFA — formal definition, epsilon transitions

5. Worked examples


6. Common mistakes (steel-manned)


7. Active recall

Recall Test yourself (hide answers)
  • What is the output type of an NFA's δ\delta? → P(Q)\mathcal{P}(Q), a set of states.
  • What makes an NFA accept ww? → some path: δ^(q0,w)F\hat\delta(q_0,w)\cap F\neq\varnothing.
  • Why include qq in ECLOSE(q)\text{ECLOSE}(q)? → zero ε-moves is allowed.
  • Is εΣ\varepsilon\in\Sigma? → No.
  • Are NFAs more powerful than DFAs? → No; same language class (regular).
What is the formal 5-tuple of an NFA?
(Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F) with δ:Q×(Σ{ε})P(Q)\delta:Q\times(\Sigma\cup\{\varepsilon\})\to\mathcal{P}(Q).
How does an NFA's δ\delta differ from a DFA's?
NFA returns a set (P(Q)\mathcal{P}(Q)) and allows ε\varepsilon in its domain; DFA returns a single state and has no ε\varepsilon.
Define ε-closure of a state qq.
All states reachable from qq by zero or more ε-transitions, including qq itself.
When does an NFA accept a string ww?
When δ^(q0,w)F\hat\delta(q_0,w)\cap F\neq\varnothing — at least one reachable state is accepting.
What is the base case of δ^\hat\delta?
δ^(q,ε)=ECLOSE(q)\hat\delta(q,\varepsilon)=\text{ECLOSE}(q).
Write the inductive step of δ^\hat\delta.
δ^(q,xa)=ECLOSE(rδ^(q,x)δ(r,a))\hat\delta(q,xa)=\text{ECLOSE}\big(\bigcup_{r\in\hat\delta(q,x)}\delta(r,a)\big).
Is ε\varepsilon a member of Σ\Sigma?
No; ε only appears in δ\delta's domain as Σ{ε}\Sigma\cup\{\varepsilon\}.
What does δ(q,a)=\delta(q,a)=\varnothing mean in an NFA?
That branch dies on aa; it is not an error, other branches may still accept.
Are NFAs strictly more powerful than DFAs?
No — both recognize exactly the regular languages.
Recall Feynman: explain to a 12-year-old

Imagine you're playing a maze game and at some doors you can clone yourself and send copies down several hallways at once. Some doors are even secret slides that move a clone instantly without using up a step (that's the ε-move). You win if any copy of you reaches the treasure room. You don't need all of them — just one lucky clone. An NFA is a machine that plays exactly this game with letters of a word as steps.

Connections

  • DFA — formal definition — the deterministic special case (δ\delta returns singletons, no ε).
  • Subset Construction (NFA to DFA) — proves NFA = DFA in power.
  • Regular Languages — exactly the languages NFAs/DFAs accept.
  • Regular Expressions — Thompson's construction builds ε-NFAs from regexes.
  • Closure Properties of Regular Languages — union/concat/star designed easily with ε-NFAs.

Concept Map

relaxed into

based on

power 1

power 2

formalized as

contains

requires output

returns

adds to input

handled by

acceptance rule

equivalent to DFA accepts

DFA rigid one target

NFA nondeterministic

Nondeterminism guessing

Multiple targets set

Epsilon-moves free

Transition function delta

Power set P of Q

5-tuple Q Sigma delta q0 F

Accept if one path wins

Epsilon-closure

Regular languages

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, DFA bahut strict hota hai: har state se, har symbol par, exactly ek hi next state. NFA thoda chill cousin hai — ek state se ek symbol par tum multiple states me ja sakte ho, ya kahin nahi (empty set), ya bina koi symbol padhe hi free me move kar sakte ho. Yeh free move hi epsilon transition hai. Soch lo jaise tum maze me apne clones bana rahe ho aur sab hallways try kar rahe ho — agar koi ek bhi clone treasure (final state) tak pahunch gaya, to string accept ho gayi. Sabhi clones ko pahunchna zaroori nahi.

Formal definition same 5-tuple hai (Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F), bas ek twist: δ\delta ka output ek single state nahi, balki ek set of states (P(Q)\mathcal{P}(Q)) hai, aur input me ε\varepsilon allowed hai. Yahi do changes poora khel hain. Epsilon ko Σ\Sigma ke andar mat daalna — woh sirf δ\delta ke domain me Σ{ε}\Sigma\cup\{\varepsilon\} ke roop me aata hai, kabhi string ka actual symbol nahi banta.

Jab string run karte ho, har symbol padhne ke baad ECLOSE (epsilon-closure) lena nahi bhulna — matlab jitne states free epsilon arrows se reach ho sakte hain, sab add kar do. Yeh step log aksar miss kar dete hain aur galti se reject kar dete hain. Acceptance ka rule: δ^(q0,w)F\hat\delta(q_0,w)\cap F\neq\varnothing — yaani kam se kam ek reachable state final hona chahiye.

Important baat: NFA, DFA se zyada powerful nahi hai. Dono exactly same languages (regular languages) recognize karte hain — subset construction se NFA ko DFA me convert kar sakte ho. NFA ka faayda sirf yeh hai ki design karna aasaan ho jaata hai, especially union, concatenation, aur star jaise operations ke liye epsilon transitions bahut handy hote hain.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections