I am looking at the answer in solution manual which asked , all the words that don't have both substring bba and abb.

and the answer was a*(baa*)*b+b*(a*ab)*a*

and I'm like wait a minute is that right ? but that can't make abb, which is in the language. So it's gotta wrong.

so I came up with my own , would this be all the words that don't have both substring bba and abb ?


^ is an empty string by the way


The textbook's answer does appear to be incorrect, as you note it does not generate $abb$ (and just to rule out an alternative interpretation of the exercise - "all strings that include neither $abb$ nor $bba$ - it does generate $bba$).

However your answer is also incorrect unfortunately - it doesn't generate $bba$.

There are a couple of reasonably sensible ways to get a correct answer (of course there's always many many techniques, and different people prefer different ones).

The first is the "intuition" approach, break the problem into the two parts, "the strings that don't have $bba$" and "the strings that don't have $abb$", then combine. With this method you have to then think about how such strings would look, and convince yourself that you haven't missed any cases.

The very formal method is to construct the expression from smaller, verifiable building blocks. In this case, we can easily construct a DFA for the strings that do contain $abb$ and one for the strings that contain $bba$, then we can use the intersection construction to get a DFA for the intersection of the two languages, take the complement DFA, then convert this to a regular expression.

What they seem to have done, and messed up or made a typo in one part, is the formal-but-not-quite-as-silly-as-option-2 method, where we make the two small DFAs, take their complements separately, convert each to a regular expression, then combine. I'll do the half that they seem to have gotten wrong (the bit that allows $abb$ but not $bba$, which is the first half of their expression).

The initial DFA is:

DFA recognising strings containing "bba"

Taking the complement we get:

DFA recognising strings that don't contain "bba"

This second DFA recognises all the strings that don't contain $bba$. Now we convert this to a regular expression using the normal state elimination algorithm. If you haven't seen this yet, it will appear shortly in whatever course you're studying, or you can look over this explanation, but for the moment (and for the sake of keeping this answer on track!) hopefully it's acceptable that there is an algorithm for doing this conversion. In principle this algorithm can result in slightly different regular expressions depending on the order you eliminate the states, so if you have a go at it, you may not end up with quite the same regular expression (if you try one particular order, you get a real mess).

After all that we get the regular expression: $$ (a+ba)^{\ast}b^{\ast} $$

If we then proceed and do the DFA for strings containing $abb$, take its complement and derive the regular expression, we get (picking the right elimination ordering) the same as their second half, $b^{\ast}(a^{\ast}ab)^{\ast}a^{\ast}$, and combine them and get the final answer: $$ (a+ba)^{\ast}b^{\ast}+b^{\ast}(a^{\ast}ab)^{\ast}a^{\ast} $$


Do not have substrings bba and abb:

Regular Expression= ^+b+ bbb*+(a+ba)(a+ba)*(^+b)

L={^, a, b, aa, ab, ba, bb, aaa, aab, aba, baa, bab, bbb, aaaa, aaab, abaa, baaa, baab, baba, bbbb,...}

  • 2
    $\begingroup$ This regular expression generates strings not containing $a$s. And strings starting with $b$, and at least one $a$ separating additional $b$s, if any. What about, say, $bbab$? $ab$, $abb$? $\endgroup$ – greybeard Aug 21 '20 at 0:23
  • $\begingroup$ Thanks greybeard for pointing out the missing strings. Pl. check the corrected regular expression: Regular Expression= ^+b+ bbb*+(a+ba)(a+ba)*(^+b) L={^, a, b, aa, ab, ba, bb, aaa, aab, aba, baa, bab, bbb, aaaa, aaab, abaa, baaa, baab, baba, bbbb,...} $\endgroup$ – Ankit Rajpal Aug 22 '20 at 6:08
  • $\begingroup$ (I think the list should show abab.) The first part looks redundant - $b^*$ covers strings not containing $a$s* nicely. Same for $(a+ba)(a+ba)^*$: why not allow the empty string once more? Now, I see *strings not containing $a$s*, and *strings not containing $bb$ - what about $abb$ and $bba$ (not containing "the other one")? $\endgroup$ – greybeard Aug 22 '20 at 9:50
  • $\begingroup$ Yes..abab will also be accepted by the given regular expression. I don't see any reason of including empty string again. The question says that both abb and bba should not occur as a substring and the given regular expression is satisfying this requirement. $\endgroup$ – Ankit Rajpal Aug 23 '20 at 10:35
  • $\begingroup$ I am under the impression you read words that don't have both substring $bba$ and $abb$ different from David Richerby(&me): may contain each, but not contain both of $bba$ and $abb$. (So, the list should include each - didn't check the three symbol strings.) $\endgroup$ – greybeard Aug 23 '20 at 10:54

These are incorrect R.E we generate bba from the 2nd part

I think b*+a*(ab)a+a*(ba)a+a*ba(a+ab)a+a*ab(a+ab)a may be correct R.E.

  • $\begingroup$ $bba$ doesn't contain both of $bba$ and $abb$, so it should match the regular expression. I think you've misunderstood the question. $\endgroup$ – David Richerby Feb 23 '17 at 13:07

It is a very simple RE. {a*(ba+a)*(b+^) + (b *) } Where ^ is null. JazakAllah :)

  • $\begingroup$ It is b* in the last. $\endgroup$ – Sheikh Ahsan Ali Dec 4 '19 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.