DFA/NDFA problems confirmation

425 Views Asked by At

Im studying for a test on my own and have been working through some previous test questions. Can anyone help me confirm that the answers I've gotten for the problems below are correct or not. If there not an explanation why would be much appreciated.

1) $(ab),(a^4b),(a^7b),(ab^4),(ab^7),(a^4b^4)$.

2) $L_1$(G) = (a mod 3 = 1) + b + (b mod 3 = 0)

3)The DFA I made to accept $L_1$ was the same as the NDFA but adding a dead state and having the states that were missing an a or b go to that state. It seems to me like this accepts $L_1$.

4) The only strings which I can see that are accepted would be $(a^2b^2), (a^1b^3), (a^3b^1)$. Since the length has to be less than or equal to 5 the only way to get remainder 1 is having n + m = 1 or 4. Having n+m = 1 would mean either one would be 0 meaning n + m has to equal 4.

5) I am not completely sure about this problem but in the question it says to construct a finite state automaton, but doesnt specify if it has to be DFA or NDFA. Therefore I thought this could be done reasonably easily with an NDFA.

1

There are 1 best solutions below

2
On BEST ANSWER

Your first answer is now correct.

Your second shows that you understand what the language is, but your notation is incorrect. $L_1$ is a set of words; your expression is not a set, and it uses the symbol $b$ both for the letter in $\Sigma$ and for the number of times it appears in a word. I would write

$$L_1=\left\{a^{3m+1}b^{3n+1}:m,n\ge 0\right\}\;;$$

if you want a correct version closer in style to what you wrote, you could use

$$L_1=\{a^mb^n:m\bmod 3=n\bmod 3=1\}\;.$$

Your third and fourth answers are correct, including the reasoning in the fourth answer.

Your NDFA for the fifth question isn’t right: it accepts $a$ and $b$, neither of which is in $L_2$. In fact, it accepts $a^n$ and $b^n$ for any $n\ge 1$, and none of those words is in $L_2$. If you removed the transitions $1\overset{a,b}\longrightarrow 1$ it would almost work: it would accept the language

$$L_3=\left\{a^mb^n:(m+n)\bmod 3=1\right\}=L_2\cup\left\{a^{3n+1}:n\ge 0\right\}\cup\left\{b^{3n+1}:n\ge 0\right\}\;.$$

Corrected. To get rid of the unwanted words, it’s probably easiest to start over. Keep states $1$ and $2$, but have only a transition $1\overset{a}\longrightarrow 2$: you don’t want to accept anything that starts with $b$. You also don’t want to accept $a$, so state $2$ cannot be an acceptor state.

Now make a $3$-state loop,

$$2\overset{a}\longrightarrow 3\overset{a}\longrightarrow 4\overset{a}\longrightarrow 2\;;$$

this lets you keep track of $m\bmod 3$, where $m$ is the number of $a$s that you’ve read so far. For instance, whenever $m\bmod 3=2$ you’re in state $3$. None of these states can be an acceptor state, since you need to get a $b$ before the word is ‘live’.

Add states $2',3'$, and $4'$, and make a parallel $3$-state loop

$$2'\overset{b}\longrightarrow 3'\overset{b}\longrightarrow 4'\overset{b}\longrightarrow 2'$$

to keep track of $(m+n)\bmod 3$, where $n$ is the total number of $b$s read. We can set it up to match the first loop, so that you’re in state $2'$ when $(m+n)\bmod 3=1$, in state $3'$ when $(m+n)\bmod 3=2$, and in state $4'$ when $(m+n)\bmod 3=0$. Clearly you want state $2'$ to be the acceptor state.

All that remains is to add the appropriate $b$ transitions from the $2,3,4$ loop to the $2',3',4'$ loop. I’ll let you try to work out what they should be, but the answer is in the spoiler-protected block below; mouse-over to see it.

$2\overset{b}\longrightarrow 3'$, $3\overset{b}\longrightarrow 4'$, and $4\overset{b}\longrightarrow 2'$.