# DFA for every run of a's=2 or 3

I am trying to create a dfa for L={w: every run of a's has length either two or three}

this is my attempt at the solution..i feel like I am missing something..? • "i feel like I am missing something..?" - What do you feel that you're missing? – Guildenstern Oct 1 '14 at 8:30
• thhis wont accept the string baabbabbab for example, even though it has a run of 2a's – matt mowris Oct 1 '14 at 8:42
• Does every run of $a$s in the empty string have length two or three? – David Richerby Oct 1 '14 at 8:50

Yes, there is something wrong. In your comment you stated that you feel that it should be accepting $baabbabbab$. You are wrong about this.

The language you want is $L=\{w \in \{a,b\}^* | w = ((aa|aaa|\epsilon)b)^*(aa|aaa|\epsilon)\}$

Clearly, $baabbabbab \not\in L$.

Regarding your DFA, I have some excellent news but you'll quiesce in your pants about it. In fact, your DFA accepts any string that ends in a run of a's of length 2 or 3 and contains no runs of length 4 i.e. $L(<your\ DFA>) = \{w \in \{a,b\}^* | w= (ab|aab|aaab|b)^*(aa|aaa)\}$.

HINT

State $q_1$ in your proposed DFA, on $b$, should go to a halting state.

• Personally, I find it much easier to see that $baabbabbab$ is not a string in which every run of $a$s has length two or three than to see that the regular expression $((aa|aaa|\epsilon)b)^*(aa|aaa|\epsilon)$ describes exactly that language and that $baabbabbab$ doesn't match the regular expression! So "Clearly, $baabbabbab\notin L$" doesn't seem to be a very helpful thing to say. – David Richerby Oct 31 '14 at 13:14
• @DavidRickerby Perhaps you are correct sir. But I'd say that it depends on your background. A programmer may be happy with the regex. – d'alar'cop Oct 31 '14 at 13:21
• I don't think it really depends on background. Here's my proof that $baabbabbab$ is not a string in which every run of $a$s has length two or three: the third $a$ is in a run of length one. I'm perfectly happy with regular expressions but the argument via the regular expression involves more complicated concepts (regular expressions versus counting to three) and any argument via that regular expression necessarily includes the argument "... and $baabbabbab$ contains runs of $a$s that don't have length two or three..." – David Richerby Oct 31 '14 at 13:59