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"
8
Upvotes
2
u/lfdfq Feb 11 '26
Is your question about the string 'aabaab'? From the question statement, then 'aabaab' would be a valid word yes (i.e. in the language), since it starts with 'aab'.
As you note, your answer is wrong because (aab)* includes the empty string. Whether * includes empty string, or if you pretend it does not, does not change the language the question is talking about so I'm not sure how it's relevant.
21
u/Ok-Interaction-8891 Feb 11 '26
Your answer is incorrect because such a regex would accept the empty string, which is clearly not a part of the language you are being asked to specify. Furthermore, your expression also accepts things like aaaaa and bbbbb and ababab, which are not a part of the language.
That said, you only need to modify your answer a little bit to make it correct. Simply drop the Kleene star from (aab)* so that your expression reads as (aab)(a|b)* and you’ll be good to go.
With this expression, you reject the empty string and other invalid strings, but still accept all other strings that begin with aab.
5
u/red_sky33 Feb 11 '26
There is an operator similar to * which does not include the empty string. You should know about it, but you don't need to worry about it for this problem.
You know exactly what the first three characters of a passing string are.
It doesn't matter what follows; you don't need to worry about whether those first three characters repeat.
2
u/Sexy_Koala_Juice Feb 12 '26
The answer should be
(aab)(a|b)*
2
u/justaddlava Feb 12 '26
Reading Sipser will help with any confusion. The trick is that a language is a set of strings and a regex defines a language. Add OR remove any string and you have a different language.
0
u/rolfn Feb 11 '26
Your regex would match the string "b" but not "aabc"
1
u/[deleted] Feb 12 '26 edited Feb 12 '26
As a definition, a star ( * ) means zero or more occurrences of a string, and a plus ( + ) means one or more occurrences of that string. So if you want to exclude the null string, you definitely should use (aab)+ rather than (aab)* .
Secondly, your answer (aab)* (a|b)* is incorrect because it includes the null string, which does not begin with aab.
Thirdly, it is obvious the correct answer is aab(a|b)* . It is equivalent (by equivalence I mean the languages described by the regular expressions are the same) to (aab)+ (a|b)* , which does a minor but important modification to your answer.
0
u/These-Maintenance250 Feb 11 '26
aab.*