I am trying to draw a DFA that accepts the following language:
$L=\{a^{2i+5j} : i , j \geq 0\}$
I started out by drawing an NFA, which I can then convert to a DFA but I am not sure if my NFA is correct.
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityI am trying to draw a DFA that accepts the following language:
$L=\{a^{2i+5j} : i , j \geq 0\}$
I started out by drawing an NFA, which I can then convert to a DFA but I am not sure if my NFA is correct.
I'm not sure if this NFA is correct since both outgoing options from q0 are 'a', which means that you would not know to which node to go to. Wikipedia also defines an NFA as an FA when "each of its transitions is uniquely determined by its source state and input symbol", and less relevant "reading an input symbol is required for each state transition". The transistions of node q0 are not uniquely defined in this case.
Furthermore, even if two outgoing 'a's are allowed, once you have gone to q2, no multiples of 2 are possible anymore in your NFA.
That said, I do not know if you can really draw a good NFA since your definition of L allows for quite some correct multiples of a. You could start by making a list of all possible options: $$[0,2,4,6,8,10] \;for\; (i \geq 0 , j= 0)\\ [0,5,10,15,20] \;for\; (i=0,j\geq 0) \\ [7,9,11,13,15] \;for\; (i\geq1, j=1)\\$$ From which you can quickly deduce that after 4, every even and uneven numbers are possible. Which gives the following NFA:
But I'm actually guessing you just wish to parse every multiple of 5 or 2, with tokens of either "aa" or "aaaaa". In which case you need the following NFA:
This works, since a parser would restart after 5 'a' s since no other state can be reached. Furthermore, it can parse "aaaa", since it remembers the last accepting state, which would be q2, and starts over with the 'leftover' bit of "aa". Which it can parse again.
Normally you would also have to take into account the fact that a parser is greedy, however, this parser is rather simple, as such this is not a problem. However, in long strings of 'a' you would only get tokens of "aaaaa" until the end. At that point it might parse tokens of 2 in the case of leftover strings of "aa" or "aaaa".
SIDENOTE: Do not start your NFA with an accepting state of q0, since that means you could have infinitely many empty tokens.
All natural numbers are expressible in the form $2x+5y$, except for $1,3$. You can check this directly, of use the solutino of the Frobenius problem for two denominations. Therefore another way to write your language (assuming the alphabet is $\{a\}$) is $$ \overline{\{a,a^3\}}. $$ You can construct a DFA for this language using 5 states, that count up to 4 and then saturate.
If you want to implement the constraint $2x+5y$ directly as an NFA (which is more economical for larger values of $2,5$), then you construct the following NFA:
In words, there is a 2-cycle and a 5-cycle sharing a vertex $q_0$, which is also the initial state and the unique final state.
Yes, the NFA looks correct to me.