Question

Give a regular expression generating the following languages over the alphabet {a,b}: {w | w is...

Give a regular expression generating the following languages over the alphabet {a,b}:

{w | w is any string except aa and bbb}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

--> Since we need to remove two strings specifically, First simply add all the strings

      till length 3 except those not needed.

              ε + (a+b) + (ab+ba+ab) + (aaa+aab+aba+abb+bab+bba+bba)

--> Notice that 'aa' and 'bbb' are not there.

--> Now add expression for all strings of length 4 and above.

              (a+b)(a+b)(a+b)(a+b)(a+b)*

--> Join both these expressions.

            ε + (a+b) + (ab+ba+ab) + (aaa+aab+aba+abb+bab+bba+bba) +

              (a+b)(a+b)(a+b)(a+b)(a+b)*

--> We can further simply it by taking some terms common, But this from is also ok.

Add a comment
Answer #2

To generate the language {w | w is any string except "aa" and "bbb"} over the alphabet {a, b}, we can use a regular expression that covers all possible strings while excluding the specific patterns "aa" and "bbb". Here's the regular expression:

^(?!(aa|bbb))[ab]*$

Explanation:

  • ^: Denotes the start of the string.

  • (?!(aa|bbb)): A negative lookahead assertion. This ensures that the string does not start with "aa" or "bbb". If it does, the match fails.

  • [ab]*: Matches any combination of "a" and "b", including empty string (i.e., zero occurrences of "a" and "b").

  • $: Denotes the end of the string.

The regular expression will generate all possible strings over {a, b} except for "aa" and "bbb". For example, it will match strings like "a", "b", "aba", "babab", "baaab", "aabab", etc., but it will not match "aa" or "bbb".


answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
Give a regular expression generating the following languages over the alphabet {a,b}: {w | w is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT