(a+b(b+abb)*aa)*(ε+b(b+abb)*(ε+a+ab))
Explanation:
Start with this DFA, which accepts all strings that do have "baba" as a substring.
Images Not Shown
XXX main sequence marches XXXXXX the XXXXX XXXXX XXXX it XXXXXXXX "XXXX". On any "aa" XXXXXXXXX, XXX machine XXXXXXX to the XXXXX state. XX any "bb" XXXXXXXXX, XXX XXXXXXX returns to XXX second state, which is important because the XXXXXX "baba" XXXXXX XX accepted.
XX make a XXX XXXX XXXXXXX XXX XXXXXXXX of strings thatdon't contain "baba", XX just XXXX the final XXX XXX-XXXXX states.
Images Not Shown
In order to XXXX this XXX XXXX a XXXXX, XX're XXXXX XX XXXX to XXXXXXXX it XX a generalized NFA where XXXXXXXXXXX XXX be XXXXXXX by regular expressions, XXX XXXXX eliminating XXXXXX. XXX XXXXX step XX to make XXXX we'XX XXXX got a single final XXXXX, which XX XXX do with XXX XXXX of XXXXXXX transitions. Also, it is XX longer necessary to keep XXX trap XXXXX X, because XX XXXXX XXXXX XX XXXXXXXXX XXXX it.
Images Not Shown
State 4 XXX XX XXXXXXX XXXXXX. It has XXX inbound XXXXXXXXXXX XXX XXX outbound. XXXX XXXXX X XX removed, XXXXX XXXX XX a new option for X XX XXXXXXXXXX XX F usingb, and for 3 XX XXXXXXXXXX to X usingbb. XXXXX a XXXXXXXXXX XXXX 3 to X already XXXXXX, we'll XXX XXXXXXXXXXX XX combine both possibilities XXXX XXX XXXXXXX expressionb+ε.
Images Not Shown
We'll eliminate state X next. XXXXX it has XXX XXXXXXX and three outbound XXXXXXXXXXX, its removal XXXX add three options XXX transitioning. A new transition from X to 1 gets labeledXX, the XXXXXXXXXX XXXX X XX F becomesε+a(b+ε), XXXXX can be written more XXXXXX asX+a+ab, and XXX self-transition XX XXXXX 2 becomesb+XXX.
Images Not Shown
Finally, state X can XX XXXXXXXXXX. This gives a XXX XXXXXX for X XX XXXX-transition XXXXXb(b+abb)*XX, and XXX X XX XXXXXXXXXX XX X by XXXXX XXb(b+abb)*(X+a+ab).
Images Not Shown
You XXX see that the string "XXX" is accepted, matching XXX transition XXXX X to F. But XXX string "XXXX" is XXX. XXXXXX either "b", "XX", or "XXX" XXXXX make XXX transition XX the XXXXX XXXXX, XXXXX is XX XXXX-transition XX XXXXXX the final "a".
XXXX, the XXXXXX "bbaba" is XXXXXXXX. XXXX XXXXXX "bbab" could XXXXXXXXXX directly XX the final state (and so XX XXXXXXXX), XXX final "a" XXXXX gives XX way XX stay there.
Obviously, the regular expression XXXXXXXXXXXXX XX XXXX XXX-XXXXX machine XX XXX XXX XXXX XXXX through zero or XXX self-transitions XX 1 XXXXXXXX by a XXXXXXXXXX to F. That expression XX
(a+b(b+abb)*XX)*(X+b(b+XXX)*(X+a+ab))
">