130k views
5 votes
For the two regular expressions r1 = a* + b* and r2 = ab* + ba* + b*a + (a*b)*

(a) find a string corresponding to r2 but not to r1 and
(b) find a string corresponding to both r1 and r2.

User Keyah
by
8.7k points

1 Answer

3 votes

Final answer:

For the given regular expressions, "ab" is a string matching r2 but not r1, while "b" is a string that matches both r1 and r2. Regular expressions are used to describe patterns in strings, and understanding them is crucial in various computing tasks.

Step-by-step explanation:

The hand involves finding strings that match certain regular expressions. Regular expressions describe sets of strings according to certain syntax rules and are commonly used in computer science for pattern matching within texts.

(a) A string corresponding to r2 but not to r1 can be "ab". This string matches the pattern "ab*" which is part of r2, indicating a followed by zero or more b's. It does not fit r1 because r1 expects a sequence of a's or a sequence of b's, but not a combination of both.

(b) A string corresponding to both r1 and r2 can be "b". This string conforms to "b*" which is part of both expressions, indicating zero or more b's. The mentioned rule (xa)b = xa.b is a mathematical rule for exponents which suggests that when you raise an exponent to another power, you multiply the exponents. This is related to regular expressions in the way that '*' is seen as a kind of exponentiation operation on a certain character or pattern in the regular expression language.

User Matheus Domingos
by
7.9k points