ab if the number of apples and bananas are even a if the number of apples is even but bananas are odd b if the number of apples is odd and bananas are even ϵ if the number of apples and bananas are both odd
Thanks
Asked By : George Robinson
Answered By : Nik Bougalis
- $1$ is the state denoting an even number of apples and bananas. This is our start state.
- $2$ is the state denoting an odd number of apples and an even number of bananas.
- $3$ is the state denoting an even number of apples and an odd number of bananas.
- $4$ is the state denoting an odd number of apples and an odd number of bananas.
Now, let’s see how we move between states. For the moment, let’s ignore the possibility of $varepsilon$ for the input. From state $1$ ($a$=even, $b$=even):
- If we get an $a$, go to state $2$. Eat the apple and output nothing.
- If we get a $b$, go to state $3$. Eat the banana and output nothing.
From state $2$ ($a$=odd, $b$=even):
- If we get an $a$, we go to state $1$. Eat the apple and output nothing.
- If we get a $b$, we go to state $4$. Eat the banana and output nothing.
From state $3$ ($a$=even, $b$=odd):
- If we get an $a$, we go to state $4$. Eat the apple and output nothing.
- If we get a $b$, we go to state $1$. Eat the banana and output nothing.
From state $4$ ($a$=odd, $b$=odd):
- If we get an $a$, we go to state $3$. Eat the apple and output nothing.
- If we get a $b$, we go to state $2$. Eat the banana and output nothing.
At this point we are pretty full and sick of apples and bananas. So let’s consider what happens when we run out of food. It should be clear that we are going to be in one of the four states above. So let’s augment each of them with an additional rule each: The rule is simple: when the input for any one of those states is $varepsilon$, output the correct sequence of characters for that state and then go to a $halt$ state. I hope this helps!
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/12200