NFA for $L = \{ w \in \{a,b,c\}^* : \text{at least one symbol appears only once in }w \}$

1.6k Views Asked by At

Write an NFA to recognize the language $$L = \{ w \in \{a,b,c\}^* : \text{at least one symbol appears only once in }w \}.$$

I'm not quite sure how to do this question. I don't know how to keep track of the number of times each letter appears in the string.

2

There are 2 best solutions below

0
On

You do not have to keep track of the number of times a letter appears. You just need to remember if you have seen the letter or not.

For example a language in the binary case with alphabet $\{a,b\}$ that accepts a string if and only if each letter appears at least once needs 4 states $S_0, S_a, S_b$, and $S_{a,b}$ where $S_0$ is the start state and $S_{a,b}$ is the accept state. From the start state $S_0$ transition to $S_a$ on an $a$ and to $S_b$ on a $b$. When in $S_a$ loop on any $a$ and only transition to $S_{a,b}$ on a $b$. Similarly for $S_b$. Once you read $S_{a,b}$ you loop until the end of the string.

Sorry I do not have time to draw this machine. Hopefully this idea makes sense and can help you in the ternary $\{a,b,c\}$ case. Note this is different from your problem, but easier to explain with out a picture of the machine.

0
On

Hint. An NFA which recognises all words in which $a$ occurs only once is given by the following table. $$\matrix{&a&b&c\cr q_1&q_2&q_2&q_2\cr q_2&\hbox{none}&q_2&q_2\cr}$$ The initial state is $q_1$ and both states are accepting. (Note that, strictly speaking, "only once" means "once or not at all". If the question was supposed to be that at least one symbol occurs exactly once, make the accepting state $q_2$ only.)

If you are using the version of NFAs in which more than one initial state is permitted, you should now be able to finish the job. Good luck!