4.6.5 · D3Theory of Computation

Worked examples — Regular expressions — equivalence with finite automata

3,576 words16 min readBack to topic

Before we touch a single example, let us agree on the picture-vocabulary so no symbol appears uninvited.


The scenario matrix

Every problem this topic can throw is one of these cells. The rightmost column names the example that nails it.

# Case class What is tricky about it Hit by
C1 Base / degenerate regex , , single the "zero-input" and "empty" corners people skip Ex 1
C2 Union with different-length branches new start/accept must be fresh Ex 2
C3 Star of a union the loop-back vs skip-edge both needed Ex 3
C4 Concatenation after star gluing a star's accept into a fresh gadget Ex 4
C5 FA → regex, self-loop present the factor actually fires Ex 5
C6 FA → regex, elimination-order twist two orders, same language Ex 6
C7 Limiting/degenerate FA: dead state, no accept machine accepting Ex 7
C8 Real-world word problem (a lexer / grep pattern) translate English → regex → machine Ex 8
C9 Exam twist: "prove two regexes equal" via machines order-independence of the language Ex 9

We now walk C1 → C9.


Ex 1 — C1: the three base cases (the degenerate corner)


Ex 2 — C2: union of unequal-length branches


Ex 3 — C3: star of a union


Ex 4 — C4: concatenation after a star


Ex 5 — C5: FA → regex with a live self-loop


Ex 6 — C6: same FA, opposite elimination order


Ex 7 — C7: the dead / no-accept machine (limiting case)


Ex 8 — C8: real-world word problem (a grep/lexer pattern)


Ex 9 — C9: exam twist — prove by building machines


Recall Quick self-test on the matrix

Which cell handles a self-loop turning into a star? ::: C5 (Ex 5) — the factor. Which cell distinguishes from ? ::: C1 (Ex 1). Why do union and star need FRESH start/accept states? ::: to keep the 1-start/1-accept invariant so induction and gluing stay clean (Ex 2, Ex 3). Does elimination order change the accepted language? ::: No — only the regex text; the language is invariant (Ex 6). What regex describes a machine with no accept state? ::: (Ex 7). Which cell proves two different-looking regexes equal by comparing machines? ::: C9 (Ex 9) — build both NFAs, subset-construct, compare minimal DFAs.


See also the parent topic, and for the limits of what any of these machines can do, Pumping Lemma for Regular Languages.