01 20 Construct DFA for the language accepting strings which contains 001 as substring. (I use $\lambda$ for the empty word you may be used to $\epsilon$ instead. 4 any string not containing 000 as a substring 5 even number of 0 s and even number of 1 s 6 the difference between the number of 0 s and the number of 1 s is a multiple of 3 7 0101 3. Or, if you don’t want to stick to strict regular expressions, The second is generated by $b^*(ab^+)^*ab^*bb$, where I’ve pulled the last $a$ out of the $(ab^+)^*$ repeating block so that I know where the last block of $b$s starts.
The first set is easy: it’s generated by $b^*bb$. One way to handle the problem is to separate the words of the language with no $a$s from those that contain at least one $a$. This is actually a little tricky: a word generated by $b^*(ab^+)^*$ can end in any number of $b$s, including none at all.
Now we just need to make sure that we get $bb$ on the end. Then we can alternate non-empty strings of $b$s with single $a$s as often as we want: $b^*(ab^+)^*$. Clearly a word may start with any number of $b$s, so let’s try starting the regular expression with $b^*$. This pattern finds all of the substrings that do not contain the. Thus, we cannot allow the substring $aa$ at all. Many programming languages include support for regular expressions in the language. This means that if the word contains $aa$, it will necessarily contain $aab$. Since a word in the language must end with $bb$, any $a$ or string of $a$s in the word will eventually be followed by a $b$.