1.

Which of the following regular expression identities are true1. (r + s)* = r* s*2. (r + s)* = r* + s*3. (r + s)* = (r*s*)*4. r* s* = r* + s*

Answer»

Answer: (r + s)* = (r*s*)*

Explanation.
Let take string” rrssrs”
Take + as either one of the path and * as the loop either 0 or more times.
Option (A)  (r + s)* = r* s*
left side  may be
While()
{
Either r or s
};
Left side realize the string. Where as right side fails to realize the string. Because r* s*=
While()
{r}
While()
{s}.
Option (B) (r + s)* = r* + s*
Left side realize the string where as r* + s* =
If()
{
while()
{r
}
Else
{
while()
{s}
}
So right side fails to realize the string “rrssrs”.
Option (C)    (r + s)* = (r*s*)* .

While()
{
While()
{
R
}
While()
{
S
}
}

Right side also realize the string. Hence the answer.



Discussion

No Comment Found

Related InterviewSolutions