Constructing an NFA for the Regular Expression (0+1)∗00(0+1)∗(0+1)^*00(0+1)^*

Constructing an NFA for the Regular Expression (0+1)∗00(0+1)∗(0+1)^*00(0+1)^*

Verified Sources
Oct 26, 2026

We want an NFA with ε\varepsilon-moves (if needed) whose language equals the regular expression (0+1)∗00(0+1)∗.(0+1)^*00(0+1)^*.

Intuitively, this language is the set of all binary strings over Σ={0,1}\Sigma=\{0,1\} that contain the substring “00” somewhere. Formally, (0+1)∗(0+1)^* denotes all binary strings, and the concatenation forces an occurrence of 0000 while the starred parts allow any prefix/suffix around it.

A standard way to construct such an NFA from a regular expression is Thompson’s construction producing an equivalent epsilon-NFA. Thompson’s construction is guaranteed to produce an NFA that recognizes the same language as the input regex .

Below we build an ε\varepsilon-NFA directly by composing NFAs for the subexpressions using the Thompson rules for union, concatenation, and Kleene star .

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩ ↩2

Key subexpressions (for reuse)

Let:

  • R=(0+1)∗R=(0+1)^*
  • M=00M=00
  • S=(0+1)∗S=(0+1)^*

Then the full expression is R  M  SR \; M \; S.

We will use Thompson’s construction rules:

  • Union: create a new start/end with ε\varepsilon-branches to both operands.
  • Concatenation: connect final states of the first part to the start of the second via an ε\varepsilon link.
  • Kleene star: add ε\varepsilon transitions that allow skipping the sub-NFA (zero repetitions) and looping for more repetitions.

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩ ↩2 ↩3

Step-by-step Thompson-style construction for $(0+1)^*00(0+1)^*$

  1. 1
    Step 1

    Work over 0˘3a3={0,1}\u03a3=\{0,1\}. Target regex is (0+1)∗00(0+1)∗(0+1)^*00(0+1)^*, i.e., prefix in (0+1)∗(0+1)^*, then “00”, then suffix in (0+1)∗(0+1)^*.

  2. 2
    Step 2

    Create small NFAs for single symbols using Thompson’s base rule: a start state with a transition on that symbol to an end state .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

  3. 3
    Step 3

    Construct union 0+10+1 by adding a new entry state with 0˘3b5\u03b5 transitions to the NFA for 00 and to the NFA for 11, then merge into a new exit state via 0˘3b5\u03b5 transitions .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

  4. 4
    Step 4

    Apply the star rule: add 0˘3b5\u03b5 transitions that allow (i) skipping the starred sub-NFA (for zero repetitions) and (ii) looping from the inner end back to the inner start .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

  5. 5
    Step 5

    Create two single-symbol NFAs for ‘0’, then concatenate them by connecting the first’s end to the second’s start via an 0˘3b5\u03b5 transition .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

  6. 6
    Step 6

    Take the NFA for (0+1)∗(0+1)^*, connect its unique accept state to the start of the 0000 NFA with an 0˘3b5\u03b5 transition, then connect the accept state of 0000 to the start of the final (0+1)∗(0+1)^* NFA with an 0˘3b5\u03b5 transition (concatenation rule) .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

  7. 7
    Step 7

    Rename states to avoid collisions when assembling the three big pieces. Then specify δ(q,a)\delta(q,a) (for a∈{0,1}a\in\{0,1\}) and δ(q,0˘3b5)\delta(q,\u03b5). The resulting NFA is equivalent to the original regex by Thompson’s construction correctness guarantee .

    Footnotes

    1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

Concrete ε\varepsilon-NFA

We present one explicit construction with states:

  • q0q_0 start
  • q1,…,q14q_1,\dots,q_{14} internal
  • q15q_{15} accept

All transitions not mentioned go to ∅\emptyset.

ε\varepsilon-transitions

  • From q0q_0: ε\varepsilon to q1q_1 and q12q_{12}
  • Looping structure inside the first (0+1)∗(0+1)^*:
    • q1→εq2q_1 \xrightarrow{\varepsilon} q_2
    • q2→εq3q_2 \xrightarrow{\varepsilon} q_3
    • q6→εq7q_6 \xrightarrow{\varepsilon} q_7
    • q7→εq4q_7 \xrightarrow{\varepsilon} q_4
    • q4→εq5q_4 \xrightarrow{\varepsilon} q_5
  • Connecting between parts:
    • q5→εq8q_5 \xrightarrow{\varepsilon} q_8 (first (0+1)∗(0+1)^* to the 0000 middle)
    • q10→εq13q_{10} \xrightarrow{\varepsilon} q_{13} (finish 0000 to second star)
  • Star exit/skip behavior:
    • q3→εq5q_3 \xrightarrow{\varepsilon} q_5
    • q12→εq13q_{12} \xrightarrow{\varepsilon} q_13
    • q13→εq14q_{13} \xrightarrow{\varepsilon} q_14
    • q14→εq15q_{14} \xrightarrow{\varepsilon} q_{15}
  • Looping structure inside the second (0+1)∗(0+1)^*:
    • q14→εq12q_{14} \xrightarrow{\varepsilon} q_{12} (repeat the “(0+1)(0+1) chunk”)
    • q12→εq14q_{12} \xrightarrow{\varepsilon} q_{14} (alternate path to ensure closure behavior)

Symbol transitions (on input 00 or 11)

  • For the union “0+10+1” chunks (used by both stars):
    • q3→0q4q_3 \xrightarrow{0} q_4
    • q3→1q6q_3 \xrightarrow{1} q_6
  • Continue union/chunk after consuming one symbol:
    • q4→εq5q_4 \xrightarrow{\varepsilon} q_5
    • q6→εq5q_6 \xrightarrow{\varepsilon} q_5

Middle “0000” piece

  • First 0 of the 0000:
    • q8→0q9q_8 \xrightarrow{0} q_9
  • Second 0 of the 0000:
    • q9→0q10q_9 \xrightarrow{0} q_{10}
  • Then ε\varepsilon to connect to second star occurs via:
    • q10→εq13q_{10}\xrightarrow{\varepsilon} q_{13}

Note: This is a valid Thompson-style ε\varepsilon-NFA pattern. Thompson’s construction guarantees language equivalence to the regex ; different state labelings or exact ε\varepsilon wiring that preserves the Thompson-rule structure can yield isomorphic NFAs.

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

Why this NFA matches exactly the “contains 00” language

The two (0+1)∗(0+1)^* components can generate any binary prefix and any binary suffix due to the Kleene-star ε\varepsilon wiring that permits zero or more repetitions . The 0000 segment forces two consecutive 00 symbols through the chained transitions q8→0q9→0q10q_8 \xrightarrow{0} q_9 \xrightarrow{0} q_{10}.

A string is accepted iff there exists a split: x  00  y∈(0+1)∗⋅00⋅(0+1)∗,x \;00\; y \in (0+1)^* \cdot 00 \cdot (0+1)^*, which is exactly “somewhere in the string there is a 0000 substring.”

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

Tip: Verify by reasoning about substrings

Before converting, interpret (0+1)∗00(0+1)∗(0+1)^*00(0+1)^* as “any prefix, then 00, then any suffix”. After building the NFA, check that the only way to reach accept requires consuming two consecutive 0s in the middle.

Warning: Don’t forget ε-closure when simulating

If your NFA has ε-transitions (Thompson’s construction does), acceptance simulation must consider the ε-closure of the current state set before and after consuming each input symbol. Thompson’s construction is defined using ε-transitions .

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

Optional structure map (how the machine is composed)

Each block is itself an ε\varepsilon-NFA built from Thompson rules:

  • union and symbol NFAs for (0+1)(0+1)
  • star wrapper for (0+1)∗(0+1)^*
  • concatenation for placing 0000 between the stars .

Footnotes

  1. Thompson's construction - Wikipedia - Rules for converting regular expressions into equivalent ε-NFAs (union, concatenation, Kleene star) with correctness via structural induction. ↩

Construction roadmap

Parse the regex

1

Identify Kleene stars, union (0+1)(0+1), and concatenation around the fixed substring 0000."

Build base NFAs

2

Create NFAs for symbols 0 and 1, and for union via Thompson’s union rule."

Apply Kleene star

3

Wrap the union NFA with the star rule to get (0+1)∗(0+1)^*."

Concatenate components

4

Place 0000 between two copies of (0+1)∗(0+1)^* using Thompson concatenation links."

Assemble final ε-NFA

5

Rename states to avoid collisions and list transitions; language equivalence follows from Thompson’s construction."

Knowledge Check

Question 1 of 4
Q1Single choice

What language does (0+1)∗00(0+1)∗(0+1)^*00(0+1)^* describe over 0˘3a3={0,1}\u03a3=\{0,1\}?