Let sigma = {a,b,c}. How do I generate a language L that does not containg abc? Any guidance is appreciated!
2 Answers
Design a DFA that recognizes "abc" (make sure to include all transitions). Complement it (make accepting states non-accepting, and make non-accepting states accepting) in order to get a DFA for $L = \Sigma^* \setminus \{ abc \}$. Finally, write down the regular expression of the complemented DFA.
As a brute force solution that does not use DFAs: write a regular expression for all words of lengths 0, 1, 2, and more than 3. This should be easy. Then write, a regular expression for all words of length 3 except abc. For example: $(b+c)(a+b+c)^2 + ab(a+b) + a(a+c)(a+b+c)$
Take the union of all the above REs.
- 29,724
- 2
- 29
- 49
The language of all words not containing $abc$ as a subword can be handled by focussing on the letter $b$. Whenever it occurs in the string we should check that one of the following conditions hold:
- it is the first letter of the string
- it is directly after another $b$ or after a $c$, or symmetrically
- it is directly before ...
- it is the last letter of the string
If that is true, I think it can be handled efficiently with a regular expression.
Be safe, all!
- 31,459
- 1
- 54
- 109