Which one of the following regular expressions over denotes the set of all strings not containing as substring?
View worked solution
Answer: D
To find the regular expression for the set of all strings over that do not contain as a substring:
- Analyze the structure: Any such string can start with any number of s, which is represented by .
- After the first : Once the first appears, we cannot have two consecutive s (i.e., is forbidden after a ). This means every that appears after the first must be immediately preceded by a , forming the block .
- Formulate the suffix: Therefore, the remaining part of the string after the first can only be composed of blocks of and . This is represented by the regular expression .
Combining these two parts, we get the complete regular expression: .
Why other options are incorrect:
- Option A: is equivalent to , which generates all strings, including .
- Option B: is extremely restrictive and cannot generate simple valid strings like .
- Option C: cannot generate valid strings like , which do not contain .
Free practice · Your answers on this page are not saved.
