Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the homework question:

$ \{w \in \{a, b, c\}^* : \text{(no symbol occurs twice in succession in w)}\} $

This is my answer:

$$\{((abc)^*| (acb)^*| (ab)^* | (ac)^*)^* | (bac)^* | (bca)^* | (ba)^* | (bc)^*)^* | ((cab)^* | (cba)^* | (ca)^* | (cb)^*)^* | ((\epsilon +a) | (\epsilon + b) | (\epsilon+c)) \} $$

Is there a way to simplify this expression?

share|cite|improve this question
How did you get the expression? – saadtaame Feb 4 '13 at 22:03
My head. It could be wrong... – jsan Feb 4 '13 at 22:07
I mean, what line of reasoning did you follow? That could help simplify the expression. – saadtaame Feb 4 '13 at 22:08
Well basically it's split in 4 parts. Each part assures that the last letter of each iteration cannot be the the same as the first, so that there could never be an 'aa', 'bb', 'cc'. The last part is a string of length 1 (either a, b, or c). Hope this clarifies, and thanks. – jsan Feb 4 '13 at 22:14
I agree with the above comments: It isn't enough if the result is "right", you must be able to convince your TA (and yourself too) that it is right. The reasoning behind the construction is an integral part of your solution. – vonbrand Feb 4 '13 at 23:10

Let's solve this exercise "by induction". Suppose first that the alphabet is only $a,b$. In this case, the only possible words are $ababab\ldots$ and $bababa\ldots$, and you can write a simple regular expressions for them. Now take such a word over the alphabet $a,b,c$. You can break it apart as $w_1 c w_2 c w_3 c \ldots$, in which $w_i \in \{a,b\}^*$. We already have a regular expression describing the $w_i$, so we can write one for the language in question. This approach is general, and you can apply it to any alphabet size.

share|cite|improve this answer
If the $w_i's$ are allowed to be $\epsilon$, you will get successive $c's$. If not, you can't start your regex with $c$ because it starts with $w_1$ which, in turn, starts with $a$ or $b$! – saadtaame Feb 4 '13 at 23:01
Oh, just allow $c w_1 c w_2 c \ldots$ to start (and for symmetry to end in a $w_n$ or $c$) – vonbrand Feb 4 '13 at 23:07
And BTW, consider that the $a b$ words can end in $a$ or $b$ (they could be even or odd length). – vonbrand Feb 4 '13 at 23:11
@saadtaame You're right, a few details are missing. After all, it's not me who has to write the solution to the exercise. – Yuval Filmus Feb 5 '13 at 0:13
@YuvalFilmus Right. – saadtaame Feb 5 '13 at 0:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.