Recall warm-up
- 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.
- Simplify (a*)*a*.
Stuck? Peek at 2.1.2 Writing regexes, identities and equivalence
- ∅ + r = r; ∅r = ∅; εr = r; ∅* = ε* = ε; (r*)* = r*; r*r* = r*; ε + rr* = r*; (rs)*r = r(sr)*.
- (r+s)* = (r*s*)* = (r*+s*)* = r*(sr*)* = (r*s)*r*.
- ≠: (r+s)* vs r*+s* vs r*s*; (rs)* vs r*s*.
- No “aa”: (b+ab)*(ε+a). At most one a: b*(ε+a)b*. Even #0: 1*(01*01*)*.
- Equality: compare shortest strings; counterexample kills; identities or minimal DFAs prove.
- Subset construction upper bound for a 6-state NFA?
Stuck? Peek at 1.2.3 Subset construction and the 2ⁿ blow-up
- 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.
The Hook
Your editor’s search box takes a regex you typed and must turn it into a machine that scans text. It can’t ask a human to design a DFA. It needs a mechanical recipe that works for every regex, by building small machines for small pieces and wiring them together with ε-moves. That recipe is Thompson’s construction, and it proves half of Kleene’s theorem: every regex describes a regular language.
Predict First
You have one machine for r and one for s, each with one start and one accepting state. Using only ε-moves and two new states, how would you build a machine for r + s?
Core Concept
Prediction check
New start state with ε-moves into both starts; both old accepting states get ε-moves to a new single accepting state (and stop being accepting). Exactly 2 new states and 4 ε-moves.
States: s, a1, a2, b1, b2, f
Transitions: s>a1: ε; s>b1: ε; a1>a2: a; b1>b2: b; a2>f: ε; b2>f: ε
The invariant
Every Thompson machine has exactly one start state, exactly one accepting state, no moves into the start, and no moves out of the accepting state. That is what makes the wiring always work.
Base cases
- ∅: start and accept, no move between them.
- ε: start ─ε→ accept.
- a: start ─a→ accept.
States: s, f
Transitions: s>f: a
Inductive cases
- r + s: new start ─ε→ start(r), start(s); accept(r), accept(s) ─ε→ new accept. (+2 states)
- rs: accept(r) ─ε→ start(s); start = start(r), accept = accept(s). (+0 states; many books merge the two states, giving one less)
- r*: new start s′, new accept f′; s′ ─ε→ start(r), s′ ─ε→ f′ (zero repetitions), accept(r) ─ε→ start(r) (repeat), accept(r) ─ε→ f′. (+2 states)
Size
Each symbol occurrence adds 2 states; each + and each * adds 2 more. So the ε-NFA has at most 2 × (number of symbols and operators) states — linear in the regex length. (Then subset construction may blow it up to a DFA, and minimization shrinks it again.)
Smaller hand-built ε-NFAs
In exams you rarely need strict Thompson; any correct ε-NFA is fine. Shortcut constructions: a* = one state with a self-loop that is both start and accepting; ab = a chain; (a+b)* = one state with loops a, b.
Putting it together
- Thompson builds an ε-NFA by induction: base machines, then ε-wiring for +, concatenation and *.
- Each block has one start (no arrows in) and one accept (no arrows out).
- Size ≤ 2 × (symbols + operators); regex ⇒ regular.
Visual
r + s r s r*
ε ┌─[ r ]─┐ ε [ r ] ─ε→ [ s ] ┌──── ε ────┐
○ ─────►┤ ├─────► ◎ ▼ │
ε └─[ s ]─┘ ε ○ ─ε→ [ r ] ─ε→ ◎
└──────── ε ───────►┘ (skip)
States: s, i, a1, a2, b1, b2, j, f, c1, c2
Transitions: s>i: ε; i>a1: ε; i>b1: ε; a1>a2: a; b1>b2: b; a2>j: ε; b2>j: ε; j>i: ε; j>f: ε; s>f: ε; f>c1: ε; c1>c2: b
The machine above is the Thompson ε-NFA for (a+b)*b: a star around a union, concatenated with b. Step through “ab”: the start closure already contains a1, b1 and c1 (zero repetitions).
Worked Examples
Draw a Thompson-style ε-NFA for ab.
Show the full solution
1 ─a→ 2 ─ε→ 3 ─b→ 4, start 1, accept 4. (Merging 2 and 3 gives 1 ─a→ 2 ─b→ 3.) Trace “ab”: {1} → {2,3} → {4} accept; “a”: ends {2,3} reject.
How many states does strict Thompson produce for (a + b)*?
Show the full solution
a: 2, b: 2, union +2 → 6; star +2 → 8.
Strict Thompson (no merging) for (ab + a)*: number of states?
Show the full solution
a: 2, b: 2, ab: 4 (concatenation adds no states); second a: 2; union: 4 + 2 + 2 = 8; star: 10. 10 states. (A hand-built NFA needs only 2: q0 accepting, q0 ─a→ q1, q1 ─b→ q0, q1 ─ε→ q0.)
GATE Traps
- In r*, forgetting the skip edge (start ─ε→ accept) loses ε.
- In r*, the loop must go from accept(r) back to start(r), not from the new accept.
- State counts differ between “strict Thompson” and versions that merge concatenation states — read the question.
Memory Hook
Thompson is Lego with one stud in, one stud out: every block has one start, one end, and ε-bricks snap them together.
Connect the Dots
Regex → ε-NFA → (subset) DFA: every regex is regular. Next: the other direction, DFA → regex, which completes Kleene’s theorem and is a frequent GATE calculation.
Self-Test
- NAT
States in strict Thompson ε-NFA for a + b?
Write your answer before opening the key.
- NAT
States in strict Thompson ε-NFA for a*?
Write your answer before opening the key.
- MCQ
In the Thompson construction for r*, which ε-move makes ε accepted?
- accept(r) → start(r)
- new start → new accept
- new start → start(r)
- accept(r) → new accept
- MSQ
Properties of every Thompson ε-NFA:
- exactly one accepting state
- no transitions into the start state
- no transitions out of the accepting state
- no ε-moves
Rule Card
- Invariant: one start (no in-moves), one accept (no out-moves).
- ∅, ε, a: 2 states. r+s: +2 states, 4 ε. rs: ε from accept(r) to start(s). r*: +2 states, 4 ε (enter, skip, loop back, exit).
- States ≤ 2 × (symbols + operators). Regex → ε-NFA → DFA proves regex ⇒ regular.
Concept Ledger
- Thompson construction
- single start / single accept invariant
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- States reachable from q by ε-moves only, including q.
- a*.
- 2⁶ = 64.
Self-test answers
- 6 — 2 + 2 + 2.
- 4 — 2 + 2.
- B — The skip edge.
- A: That allows repetition.
- C: Enters r.
- D: Exits after at least one pass.
- ABC — The invariant.
- D: It is full of ε-moves.
Flashcards
- Thompson: new states added for r + s and r*?
Reveal answer
2 each. - Thompson r*: the four ε-moves?
Reveal answer
new start→start(r), new start→new accept, accept(r)→start(r), accept(r)→new accept. - Strict Thompson states for (a+b)*?
Reveal answer
8