Constructing automata for regular languages

63 Views Asked by At

I have two languages:

  1. $\{a^n b^m \mid n, m > 0, n - m = 0 \pmod 3\}$

  2. $\{a^n b^m \mid n, m > 0, n + m = 0 \pmod 3\}$

and I'm having trouble drawing automata for them.

For the first language, I know that the first valid pairs are ab | aabb | aaaab | aaabbb, but I'm having trouble drawing that and putting it into a general automaton.

I know the for the second language, S ← abb|aab|aaabbb are the first valid pairs, but I again don't know how to put it into a general automaton.

q1:

enter image description here

1

There are 1 best solutions below

10
On BEST ANSWER

In question $1$, you can manipulate the equation a bit and get $n = m \pmod 3$. This isn't vital or very profound, but it may help your thinking.

For both of these, you can take different paths depending on the number of $a$'s you get. The first part that deals with $a$'s will always be the same. You should have three states $X$, $Y$, $YZ$ with the following property: if you're in state $X$, you just read a number of $a$'s congruent to $0 \pmod 3$, if you're in state $Y$, you just read a number of $a$'s congruent to $1 \pmod 3$, if you're in state $Z$, you just read a number of $a$'s congruent to $2 \pmod 3$.

I would make a closed loop of $3$ states for this part.

(Q: Which state should you start in?)

Then, what do you do when you're in one of $X, Y, Z$ and you read a $b$? You move to the next stage, where you find the number of $b$'s $\pmod 3$ and accept only if it matches the value for $a$.

Another closed loop would be appropriate here, since you might need to read an unbounded number of $b$'s. You'll need to rig things up so that you accept only the right thing.

(Hint: You can do this with $12$ states or $6$.)