edited by
316 views
1 votes
1 votes

find regular expression over $\{a,b\}$ corresponding to "set of strings containing Exactly $2a's$.".

I have come up with two answers and are seeming Logically correct to me. Please correct me If I am wrong.

1. $b^* a b^* a b^*$ --- This will have $0$ or any number of $b's$ at start and $0$ or any number of $b's$ in the middle and $0$ or any number of $b's$ at the end .... So it should cover all the Strings in the Language.

2. $a a b^* + a b^* a + b^* a a$ -- This contains the three scenarios where the two $a's$ are at start, one $b$ In the middle of $2 a's$ and $2 a's$ at the end.

I am wondering if both of them are correct.

Thanks in advance.

edited by

1 Answer

Best answer
0 votes
0 votes
  • Regular expression for exactlly two a's is b*ab*ab* is right.

  • Second one is wrong becz it is not gives string like baab,babab.

selected by