← 🔤 Regular Expressions & Regular Languages
Subtopic 2 of 5

2.2Regex ⇄ finite automaton

The idea

Regex, NFA and DFA are three descriptions of the same languages, and you can convert between them.

Think of it like this: Three languages for the same recipe: a sentence, a flowchart, and a table.

Why it exists

Conversions let you pick the easiest model for a problem.

How it works

  1. Regex → ε-NFA: Thompson's construction (every symbol, union or star adds a few states).
  2. ε-NFA → DFA: subset construction.
  3. DFA → regex: eliminate states one by one, or solve with Arden's rule R = Q + RP ⇒ R = QP*.
  4. Minimise the DFA to get the smallest machine.

Worked example: (a + b)*abb

Thompson builds 14 states; subset construction gives 5 DFA states; minimisation leaves 4.

Now play with it

  • →Type a regex in the lab, then look at the NFA, DFA and minimal DFA tabs.
  • →Run strings on the DFA and watch the state path.
NFA states14
Transitions16
ε-transitions11
Start / accept6 / 13
fromonto
0a1
2b3
4ε0
4ε2
1ε5
3ε5
6ε4
6ε7
5ε4
5ε7
8a9
7ε8
10b11
9ε10
12b13
11ε12

Thompson: each symbol makes 2 states; each | or * adds 2 more; concatenation adds none. So states ≤ 2 × (symbols + operators).

Check yourself

Arden's theorem says that if R = Q + RP and ε ∉ P then R equals

Remember: Regex ⇔ NFA ⇔ DFA; Arden: R = QP*.
Exam notes (the dense version)

Regex → ε-NFA by Thompson's construction (≤ 2 states per symbol/operator). DFA → regex by state elimination, or by Arden's theorem: if R = Q + RP and ε ∉ P, then R = QP*. All three formalisms describe exactly the regular languages.

Previous year questions: Regular Expressions & Regular Languages (14)

PYQs are grouped by topic, so this is the full set for Regular Expressions & Regular Languages; try the ones that match this subtopic. Open all 14 on the topic page.