1

I have recently learned how to make DFA and NFA. For an assignment, I had the following question:

Draw the state diagram for an automaton accepting language L1 over alphabet A = {a, b} from the previous homework. L1 is the set of all words w ∈ A∗ such that w contains either only a’s or only b’s.

I created this state diagram in Latex. Can you guys see if this is correct? (I have no idea how to add the actual output of this code)

starting state: q0 final state: q4

1: enter image description here

Rushabh Mehta
  • 13,663
ano
  • 37

1 Answers1

1

No, this in incorrect. The language this parses is the language of all strings that end in $b$.

Here's the DFA I'd use (it only has $4$ states, vs your NFA turned DFA would have $32$ states):

$\Sigma=\{a,b\}$

$Q=\mathcal P(\Sigma)$ ($\mathcal P$ is the power set).

$\delta(q,s)=\{s\}\cup q$

$q_0=\varnothing$

$F=\{\varnothing,\{a\},\{b\}\}$.

To check whether this is optimal, consider the regular expression for this language, $a^*+b^*$, and its derivatives.

$$D_\varepsilon(a^*+b^*)=a^*+b^*$$ $$D_a(a^*+b^*)=a^*$$ $$D_b(a^*+b^*)=b^*$$ $$D_{ab}(a^*+b^*)=\varnothing$$

Since there are at least $4$ distinct derivatives, this is optimal.

Edit:

For OP's new question, as I noted above, the presented NFA parses the language of strings ending with $b$.

Here's a DFA that solves the problem (DFAs are also NFAs)

$Q=\{0,a,b\}$

$\delta(q,c)=\begin{cases}a&c=a\\0&c=b\text{ and }q\neq a\\b&c=b\text{ and }q=a\end{cases}$

$q_0=0$

$F=\{b\}$.

Rushabh Mehta
  • 13,663
  • I am SO sorry! I realized I put in the incorrect question. I edited this! My apologies. – ano Feb 29 '20 at 17:13
  • 1
    Editing a question after someone writes up an answer isn't particularly respectful. Also, your answer is still wrong. See the top of my answer. – Rushabh Mehta Feb 29 '20 at 17:14
  • Sorry, I did not realize that was disrespectful, nor did I mean to be. I will check it out and adjust it. Sorry. Thank you for your answer. – ano Feb 29 '20 at 17:16
  • Since it's your first time, I'll edit in an answer. Be careful for next time. – Rushabh Mehta Feb 29 '20 at 17:18