# Drawing automata for languages

I'm trying to draw two automata for these two languages:

For the first one, I know that the minimum is n = 1, m = 1, but I'm having troubles drawing a NFA for it.

The second one the minimum is n = 2, m = 1, but I still don't know how to start the NFA.

I have this for q2:

• it might help you to realize that n-m = 0 mod 3 if and only if n mod 3 - m mod 3 = 0. So you could store n mod 3 as you loop through the a's, and then resolve the b's differently based on what you get for n mod 3. It works similarly for the second one. – nivekgnay Oct 5 '15 at 4:10
• You might want to ask your computer science questions at Computer Science Stack Exchange. – Joel Reyes Noche Oct 8 '15 at 3:43

Look at small numbers first. For the second language, the first valid $(n,m)$ pairs are $(1,2)$, $(2,1)$, $(3,3)$, and all others are of the form $(3k+n,3l+m)$, where $(n,m)$ is one of the starting pairs.
Hence the language can be described by $S \leftarrow abb|aab|aaabbb|aaaS|Sbbb$. It should be straightforward to draw an automata from this description.