Theory of Computation · Conversions between FA and RE
Conversion of Regular Expressions to Finite Automata (State Creation Method)
Overview
The state creation method converts any regular expression (RE) into a finite automaton (FA) by building small FA blocks for the primitive regular expressions and composing them for complex REs.
It matters because it shows that every RE defines a regular language, and together with the reverse conversion it proves that REs and FAs have equal power.
Key concepts
- State creation method: the technique of building an FA for an RE by composing blocks for the primitive REs, adding states as needed to break strings into single input symbols.
- Primitive regular expressions: the building blocks are ∅ (empty language, "accept nothing"), a single symbol A, A + B (union), A · B (concatenation), and A* (Kleene star).
- ∅ block: an FA with no final state. Any FA with no final state accepts nothing, so its language is ∅.
- Single-symbol block: a start state with a transition on A to a single final state.
- Union block (A + B): the FA for A and the FA for B combined so that either A or B is accepted — a new start state branches into the two sub-automata, and their final states are made accepting.
- Concatenation block (A · B): the FA for A followed by the FA for B — the final state of A is connected to the start of B.
- Kleene star block (A*): after seeing A, a transition goes back to the start of the A-block so A can repeat; ε is accepted by going directly to the final state.
- Restriction on transition labels: a transition of an FA may be labelled only by a single input symbol, never by a string. Strings such as AB, BA, AC must be split into single-symbol transitions by adding states.
- Equivalence of power: every RE can be converted to an FA, and every FA can be converted to an RE, so regular expressions and finite automata are equivalent in power — neither is more powerful than the other.
How it works
- ∅: build an FA with no final state; it accepts nothing, so the language is ∅.
- Single symbol A: use a start state with a transition on A to a single final state.
- A + B (union): build the FA for A and the FA for B; add a new start state that branches on A into the A-block and on B into the B-block, and make the final states of both blocks accepting.
- A · B (concatenation): place the A-block before the B-block, connecting the final state of A to the start of B.
- A* (Kleene star): from the start state, transition on A into the A-block; from the end of the A-block, loop back to the start of the A-block so A can repeat.
Acceptance is possible directly (ε only), or after one A, two A's, three A's, and so on, so all are accepted. - Complex REs: compose the primitive blocks by the same method. For simple expressions, intuition may replace the mechanical rules.
- Splitting strings: whenever a subexpression is a string rather than an input symbol (e.g. AB in (AB)*), do not label an edge with the string; add states so each edge carries one input symbol (read A, then come back on B), and loop so the string can repeat.
Formulas
-
— the FA for ∅ has no final state and accepts nothing.
-
— one transition on the symbol from the start state to the final state.
-
— union: either or is accepted.
-
— concatenation: then .
-
— Kleene star: ε, A, AA, AAA, …
-
— AB split into a transition on A then a transition on B, with a loop.
-
— each string split into single-symbol transitions by adding one more state per string.
-
Kleene star block for A*
Drawing the diagram…
-
Shows the A construction where the A-block loops back to its start for repetition and epsilon goes directly to the final state.*
-
Splitting AB into single symbols
Drawing the diagram…
- Shows how the string AB is split into a transition on A then a transition on B with a loop, instead of labelling an edge with AB.
Worked examples
Example 1: RE = ∅
- States: one start state q0, no final state.
- Transition: none needed.
- Accepted language: ∅ (nothing is accepted).
Example 2: RE = A (single symbol)
- States: q0 (start), q1 (final).
- Transition: (q0, A) → q1.
- Accepted language: { A }.
Example 3: RE = A + B
- Union of the FA for A and the FA for B: a new start state branches on A into the A-block and on B into the B-block; the final states of both blocks are accepting.
- Accepted language: { A, B }.
Example 4: RE = A · B
- Concatenation: the A-block is followed by the B-block (final state of A leads into the start of B).
- Accepted language: { AB }.
Example 5: RE = A*
- Start state with a transition on A into the A-block; from the end of the A-block a transition goes back to the start of the A-block (loop for repetition).
- Acceptance: go directly to the final state to accept ε; or accept after 1 A, 2 A's, 3 A's, …
- Accepted language: { ε, A, AA, AAA, … } = { | n ≥ 0 }.
Example 6: RE = (AB)*
- AB is not an input symbol, so no edge is labelled AB. Instead: read A, then come back on B (split AB into two single-symbol transitions using intermediate states), and loop so that AB can repeat any number of times.
- Accepted language: { | n ≥ 0 }.
Example 7: RE = (AC)*
- Same treatment as Example 6: split AC into a transition on A followed by a transition on C, with a loop for repetition.
Example 8: RE = (AB + BA)*
- Must accept AB, BA, and repetitions of them.
- Since AB and BA are strings, not input symbols, add one more state for each string so that each edge carries a single input symbol (A then B for the AB branch; B then A for the BA branch), and loop back so the whole thing repeats.
- Accepted language: { | n ≥ 0 }.
Comparison
| Aspect | Regular Expression | Finite Automaton |
|---|---|---|
| Conversion | Every RE can be converted to an FA (state creation method) | Every FA can be converted to an RE (next method) |
| Power | Equivalent in power | Equivalent in power |
Revision summary
- The state creation method composes blocks for exactly five primitives: ∅, A, A + B, A · B, A*.
- ∅ is realised by an FA with no final state — it accepts nothing.
- A + B is union (either accepted); A · B is concatenation (A then B).
- A* loops back after A so A repeats any number of times; ε is accepted by going directly to the final state.
- Transitions may be labelled only by input symbols, never by strings — split AB, BA, AC into single-symbol transitions by adding states.
- For simple expressions, intuition can replace the mechanical rules.
- REs and FAs are equivalent in power: neither is more powerful than the other.
Previous-year exam insights
- Thompson's construction is the standard exam version of the state-creation method: every operator (union, concatenation, star) is glued with ε-transitions, so the resulting NFA with ε-moves has at most 2·|RE| states (each symbol and each operator contributes at most 2 states); this NFA can then be converted to a DFA by subset construction and minimised.
Asked inGATE 2015GATE 2007GATE 2004UGC NET 2019 - To find the minimal DFA for an RE, do not count the NFA states: build the ε-NFA, remove ε-transitions, determinize and minimise (merge equivalent states); the count is the number of distinct residual languages, not the number of symbols in the RE. The minimal complete DFA for a*b(a+b) has 4 states (start, after b, accepting after the last symbol, dead; 3 if the dead state is omitted), and for (0+1)*10 it has 3 states.
Asked inGATE 2015UGC NET 2019 - An NFA with ε-transitions accepts a string if some path labelled by the string (ignoring ε-edges) ends in a final state; ε-closure(q) is the set of states reachable from q using ε-edges only, and the start state of the equivalent DFA is ε-closure(q0).
Asked inGATE 2023GATE 2008GATE 2007 - Converting an FA to an RE: eliminate states one at a time using the rule R(i,j) := R(i,j) + R(i,k)·R(k,k)*·R(k,j), or read off the language as the union over all paths from start to final states;
generalised NFAs with RE-labelled edges make this mechanical.
Asked inGATE 2022GATE 2014GATE 2008 - A regular grammar G = (V, Σ, R, S) converts to an FA with states = non-terminals (plus a final state), start = S, and for each rule A → aB a transition A --a--> B;
for each rule A → a a transition A --a--> final;
for A → ε, A is final.
Conversely, an FA gives a right-linear grammar by the same correspondence.
Asked inGATE 2015GATE 2005GATE 2004 - Extended regular expressions used for lexical tokens (e.g. letter → [A–Za–z], digit → [0–9], id → letter(letter|digit)*) are just shorthand: a character class is a union of single symbols, and the FA must have one edge per symbol, never an edge labelled by a class or a string.
Asked inGATE 2023