Give a regular expression for the set of strings over {a, b, c} such that the number of a's equals the number of b's and is equal to 2

1.3k Views Asked by At

How would I describe from finite automata to regular expressions?

I know how I would describe it if there were to be just one or more number of a's and b's using + but I'm not sure how to go about it to make it exactly 2.

So far my thought process has been:

These are the possibilities of the strings with 2 a's and 2 b's: aabb, abab, bbaa, abab, abba, baab. Now I need to add in the c's, but it doesn't matter where it is placed - so it would be c*?

1

There are 1 best solutions below

3
On

To summarise what others have already put in the comments: this regular expression will do the job:

c*ac*ac*bc*bc*|c*ac*bc*ac*bc*|c*bc*ac*ac*bc*|c*ac*bc*bc*ac*|c*bc*ac*bc*ac*|c*bc*bc*ac*ac*