0

I am brand new to DFA's and my first exercise requires me to create a DFA instance such that the number of a's in the string is a multiple of 3. We only have two types of symbols: a, b. To my understanding something like "aaabbaaa" would work but "aabbb" would not. Any help or hints would be greatly appreciated

David Richerby
  • 82,470
  • 26
  • 145
  • 239
wonggr
  • 165
  • 1
  • 1
  • 3

2 Answers2

3

The key idea here is to make a ring of three states, $q_0, q_1, q_2$ with $a$ transitions $$\begin{align} q_0 & \stackrel{a}{\rightarrow}q_1\\ q_1 & \stackrel{a}{\rightarrow}q_2\\ q_2 & \stackrel{a}{\rightarrow}q_0 \end{align}$$ On input $aaa$, for example, you'll start in state $q_0$ and pass to state $q_1$ on the first $a$, $q_2$ on the second, and back to $q_0$ on the third $a$. Clearly, any multiple of three $a$s will leave you in state $q_0$, so we make that a final state.

What to do about $b$s in the input? They don't have any effect on the number of $a$s, so include transitions $$\begin{align} q_0 & \stackrel{b}{\rightarrow}q_0\\ q_1 & \stackrel{b}{\rightarrow}q_1\\ q_2 & \stackrel{b}{\rightarrow}q_2 \end{align}$$ and you're done. In fancier terms, we're $q_n$ to "remember" whether the number of $a$s seen so far was congruent to $n\pmod{3}$. This idiom, using the states to remember certain situations, is fundamental when designing FAs.

Rick Decker
  • 15,016
  • 5
  • 43
  • 54
1

We need that the number of $a$'s will be only multiple of $3$, e.g words like $aaa,baaab,bababa,bbbbaaaaaa,\dots$ ets, so we will put the accept state on place such that the number of $a$'s $\mod(3)=0$ e.g $0\mod(3)=0,3\mod(3)=0,6\mod(3)=0,\dots$

Try this DFA:enter image description here