r/AskComputerScience • u/Quick-Fee-3508 • Feb 11 '26
Doubt regarding Theory of Computation
So our college just started with the course of Theory of Computation and here's the question that I'm confused about:
Q) Find regular expression for the language of all string that starts with aab over alphabet
Σ = {a,b}.
My answer was (aab)* (a|b)*
Now I do know that the expression (aab)* also includes null string but what if we assume it doesn't include the Null String then an answer like aabaab can also be valid
Considering string "aabaab" also starts with "aab"
9
Upvotes
View all comments
Show parent comment
3
u/lfdfq Feb 11 '26
Let's make a new regex operator "+", where
E+ = E E*(i.e. "one or more of")Then your answer of
(aab)+ (a|b)*is actually a correct regex, it's just not the "best" regex because the (a|b)* already covers any later sequences of aab. So this regex is the same as(aab) (a|b)*which is just a better answer.If his explanation is as you say, then it does not seem entirely correct: your answer would have been correct if * did not contain the empty string.
I cannot speak for your professor, but trying to solve it with repitition on aab at all implies a misunderstanding of either * or the question, so perhaps he was simply trying to make you think about the more-than-one case as well as the zero case.