To use the construction in Theorem 3.1 (commonly referring to Thompson's Construction for converting a regular expression to an NFA), we decompose the regular expression and build NFAs for its sub-expressions recursively.
The language is L=(aa∗aa+bba∗ab). This expression is of the form R1+R2, where R1=aa∗aa and R2=bba∗ab.
General Construction Rules (Thompson's):
For a character 'x':
A new start state qi and a new final state qf with a transition .
( )
Step-by-step Construction:
Let's label states systematically, starting with q0 as the global start.
1. Basic Character NFAs:
For 'a': (qA)a
2. NFA for a∗:
Using the Kleene Star rule on N(a):
Start with (q1.
New start , new final .
Transitions:
q3ϵq
(Alternatively, we'll instantiate separate instances to avoid confusion, using new state numbers for each usage.)
3. NFA for aa∗aa (Let's call this N1):
This is .
We need two basic 'a' NFAs and one NFA. The last two 'a's form .
First 'a': (q5)a
Concatenating them:
Start state for N1 is q15, final state for N is .
q15ϵq
4. NFA for bba∗ab (Let's call this N2):
This is .
First 'b': (q17)b
Concatenating them:
Start state for N2 is q29, final state for N is .
q29ϵq
5. NFA for (aa∗aa+bba∗ab):
Using the Union rule for N (start , final ) and (start , final ).
Create a global start state and a global final state .
q0ϵq
The Final NFA (States and Transitions):
Start State:q0 (indicated by an arrow pointing to it)
Final State:qf (indicated by a double circle)
States:q0,qf,q5. (Total 26 states)
Transitions ( δ ):
Overall Union:
δ(q0,ϵ)={q15,q
Visual Representation of the NFA:
Due to the complexity of drawing 26 states and many transitions in text, I will sketch the structure, which clearly shows the application of Thompson's construction. Each box represents a sub-NFA constructed according to the rules.
For R1R2 (Concatenation):
Let N1 be the NFA for R1 with start s1 and final f1.
Let N2 be the NFA for R2 with start s2 and final f2.
The combined NFA has start s1 and final f2. Add an ϵ-transition from f1 to s2.
( N1 (s1…f1) ϵN2 (s2…f2) )
For R1+R2 (Union):
Let N1 be the NFA for R1 with start s1 and final f1.
Let N2 be the NFA for R2 with start s2 and final f2.
Create a new start state s0 and a new final state f0.
Add ϵ-transitions: s0ϵs, s0ϵs, f1ϵf, f2ϵf.
(
s0ϵs0ϵ
)
For R∗ (Kleene Star):
Let NR be the NFA for R with start sR and final fR.
Create a new start state s0 and a new final state f0.
Add ϵ-transitions: s0ϵs, s0ϵf, fRϵs, fRϵf.
(
s0ϵs0ϵffRϵf
)
(
qB
)
For 'b': (qC)b(qD)
)
a
(q2)
q3
q4
1
q3ϵq4
q2ϵq1
q2ϵq4
This NFA for a∗ will be used in both branches of the main expression.
Let Na∗ be this NFA with start q3 and final q4.
N(a)⋅
N(a∗)⋅
N(a)⋅
N(a)
a∗
aa
(
q6
)
NFA for a∗: (q7)ϵ(q8)a(q9)ϵ(q8) and (q7)ϵ(, (q9)ϵ(. (Start q7, final q10).
NFA for aa: (q11)a(q12)ϵ(q13)a(q14). (Start q11, final q14).
1
q16
5
q6ϵq7
q10ϵq11
q14ϵq16
N(b)⋅N(b)⋅N(a∗)⋅N(a)⋅N(b)
(
q18
)
Second 'b': (q19)b(q20)
NFA for a∗ (new instance): (q21)ϵ(q22)a(q23)ϵ(q22) and (q21)ϵ, (q23)ϵ. (Start q21, final q24).
NFA for ab: (q25)a(q26)ϵ(q27)b(q28). (Start q25, final q28).