# Design a DFA to check whether the Given Number is Even

I have the following question

I have designed the following

A Binary String is even if it is ending with 0 and odd if its ending with 1.I have applied this.Im i right ?

UPDATE:

• First, this isn’t a DFA: there’s no $0$ transition from $q_2$. Secondly, it accepts the input $1$, which is odd. – Brian M. Scott Dec 2 '15 at 12:47
• @BrianM.Scott Okay.So for a DFA there should be a transition from every state for each input symbol. – techno Dec 2 '15 at 12:48
• Yes, that’s correct. – Brian M. Scott Dec 2 '15 at 12:48
• @BrianM.Scott well i made a blunder.I thought it should end with a 1 to be even when creating the DFA in that case is the diagram partially correct. – techno Dec 2 '15 at 12:50
• But if you’re testing for even numbers, you want to accept the inputs that end in $0$, not $1$. – Brian M. Scott Dec 2 '15 at 12:53

Your answer is incorrect. It rejects strings that are even and therefore should be accepted, like $1100$, and accepts strings that are odd and therefore should be rejected, like $1$.
The correct automaton needs to remember whether the last character read was $1$ or $0$, so we need two states: the initial state and an accepting state. When a $0$ is read, transfer to the accepting state or remain there if we were in the accepting state already. When a $1$ is read, transfer to the initial state or remain there if we were in the initial state already.
When the entire string has been read, if the last character was $0$, we'll be in the accepting state and we'll accept the string as even. If the last character was $1$, we'll be in the initial state and reject the string as odd.