Determine whether a given language $L$ is regular , CFL or nither.

177 Views Asked by At

Let

$$L=\left\{w\in\{a,b,c\}^{\ast}\Bigg\vert \exists \sigma_1,\sigma_2\in\{a,b,c\}\text{ s.t } \#_{\sigma_1}(w)\ne \#_{\sigma_2}(w)\right\}$$

Determine whether $L$ is regular, context free or nither.

It is clear to me that $L$ can't be regular because we can't count the number of $\sigma_1$ and $\sigma_2$. I believe it is context free, but I couldn't manage to construct proper PDA or a CFG in order to show it.

Please help, thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

A word is in $L$ iff either the number of $a$'s is not equal to the number of $b$'s, or the number of $c$'s, or if the number of $b$'s and $c$'s is unequal, hence we have \begin{align*} L = & \{ w \in \{a,b,c\}^{\ast} \mid \#_a(w) \ne \#_b(w) \} \\ & ~ \cup \{ w \in \{a,b,c\}^{\ast} \mid \#_a(w) \ne \#_c(w) \} \\ & ~ \cup\{ w \in \{a,b,c\}^{\ast} \mid \#_b(w) \ne \#_c(w) \}. \end{align*} As the context-free languages are closed under union, you just have to find a grammar for $\{ w \in \{a,b,c\}^{\ast} \mid \#_a(w) \ne \#_b(w) \}$ and similar the other languages.

Do you know how to do that? Maybe you should think about a CFG for $$ \{ w \in \{a,b\}^{\ast} \mid \#_a(w) \ne \#_b(w) \} $$ first and then generalise!