Regular Expression to DFA — Direct Conversion and Properties
685 words
3 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Regular Expression to DFA — Direct Conversion and Properties ## 🎯 Learning Objectives - Convert regex to NFA using Thompson construction - Apply Brzozowski's algebraic method - Prove regex identities using algebraic laws - Understand Arden's lemma for solving regex equations * * * ## 1. Thompson Construction (Reg...

Regular Expression to DFA — Direct Conversion and Properties
🎯 Learning Objectives
- Convert regex to NFA using Thompson construction
- Apply Brzozowski's algebraic method
- Prove regex identities using algebraic laws
- Understand Arden's lemma for solving regex equations
1. Thompson Construction (Regex → NFA)
1.1 Base Cases
| Regex | NFA |
|---|---|
| ε | Start → Final (ε-transition) |
| a | Start --a→ Final |
| ∅ | No accepting path |
1.2 Compound Constructions
Union (R|S):
(Diagram)
Concatenation (RS):
(Diagram)
Kleene Star (R):*
(Diagram)
2. Worked Example: (a|b)*abb
Step 1: Thompson construction produces an NFA with ε-transitions.
Step 2: Convert NFA to DFA using subset construction.
Resulting DFA:
| State | on 'a' | on 'b' | Notes |
|---|---|---|---|
| A = ε-closure(start) | B | C | Start |
| B = {states via a} | D | E | |
| C = {states via b} | ... | ... | |
| D, E, ... | ... | ... | |
| Accept states: any containing abb final state |
3. Regular Expression Identities
| Identity | Meaning |
|---|---|
| R | S = S |
| (R | S) |
| (RS)T = R(ST) | Concatenation is associative |
| Rε = εR = R | ε is identity for concatenation |
| R | ∅ = R |
| R∅ = ∅R = ∅ | ∅ is annihilator for concatenation |
| R(S | T) = RS |
| (R*)* = R* | Idempotence of star |
| ε* = ε | Star of ε |
| ∅* = ε | Star of ∅ |
4. Arden's Lemma
Lemma: The equation X = AX ∪ B has solution X = A*B (provided ε ∉ A).
Application: Solve for language of a DFA.
Example: DFA with equations:
- L1 = aL1 ∪ bL2
- L2 = aL3 ∪ bL1
- L3 = aL2 ∪ bL3 ∪ ε Using Arden's lemma iteratively to find L1 (starting language).
5. Common Pitfalls
Pitfall: Forgetting ε in Thompson Construction
The mistake: Not properly handling ε-transitions between components.
Correct approach: ε-transitions are essential — they connect NFAs without consuming input. Every compound construction (union, concatenation, star) uses ε-transitions.
6. Key Concepts Reference
| Concept | Description | Application |
|---|---|---|
| Thompson construction | Regex → NFA with ε | Compiler lexer generation |
| Subset construction | NFA → DFA | Deterministic implementation |
| Arden's lemma | Solve X = AX + B | Language equations |
| Algebraic laws | Regex equivalence | Optimization |
7. 📝 Practice Questions
Q1: Use Arden's lemma: L = aL ∪ b. What is L?Answer: L = ab. Check: b ∈ L (εb), ab ∈ L (a·b), aab ∈ L (aa·b), etc. L = {aⁿb | n ≥ 0}. _Q2: Prove: (R|S) = (R_S)*.**Answer: (R|S)* generates all strings made from R and S in any order. (R_S_)* generates the same — it allows any sequence of R-blocks and S-blocks. To prove equality: (1) Show (R|S)* ⊆ (R_S_): Any string in (R|S) can be written as alternating R and S segments, which is in R_S_R_S_... = (R_S_). (2) Show (R_S*)* ⊆ (R|S): Any string in (R_S*)* consists of strings from R* and S*, each of which is made from R and S — so it's in (R|S)*. Q3: Convert 0_10_ to NFA using Thompson construction.Answer:
- 0*: NFA with loop on 0
- 1: NFA with transition on 1
- 0*: Another NFA with loop on 0
- Concatenate: 0* → ε → 1 → ε → 0*
Final NFA: start→q0—0→q0 (loop), q0—ε→q1—1→q2—ε→q3—0→q3 (loop), q3 final. Q4: Solve using regex identities: R = R|RS. What's R?Answer: R = R(ε|S) = Rε ∪ RS = R ∪ RS. By Arden's lemma: R = (ε)RS? Actually R = R ∪ RS means R = R(ε|S) = RS. So R = RS*, which means R contains S* after prefixes from R. If R is the minimal solution, R = ∅S* = ∅? Wait, R = R ∪ RS means R contains RS for any S. The minimal solution is R = ∅. But if the equation is X = X|XS, factoring: X = X(ε|S) = XS*. For any non-empty X, this implies X = XS* = XS_S_ = ... which is circular. The solution is X = AS* where A is arbitrary. So R = AS* for some A.
8. 🔗 Cross-References
- Week 1 - Finite Automata: NFA/DFA foundations
- Week 2 - Regular Expressions: Regex semantics
- Week 3 - DFA Minimization: Minimizing conversion result Join Discord PreviousRegular Expressions & Pumping LemmaNextDFA Min & Pumping Lemma