Give a regular expression for the set of strings over {a, b, c} such that the sum of the number of a’s and the number of b’s is equal to 3.
Solution for the regular expression is provided below. If any doubt please comment below.
Need to find the regular expression for which the sum of number of a and number of b is three. The input alphabet is{a, b, c}.
There are 8 possibilities for the sum of number of a and b as 3 (excluding c).
Now include c in all these possibilities. There is no restriction on number of c.
Required regular expression:
c*ac*ac*ac* + c*ac*ac*bc* + c*ac*bc*ac* + c*ac*bc*bc* + c*bc*ac*ac* + c*bc*ac*bc* + c*bc*bc*ac* + c*bc*bc*bc*
Here c* denotes zero or more occurrence of c.
Get Answers For Free
Most questions answered within 1 hours.