Let be the language represented by the regular expression and , where denotes the length of string . The number of strings in which are also in is ______.
GATE 2024 CS2 Q.62: solution and answer
Answer and solution
ANSWER
The number of strings of length at most 4 in is 15.
Official answer: 15Source: Official answer key, GATE 2024 CS2 (IISc Bengaluru)
Read the expression . The first part contains exactly one . Each repetition of adds exactly two more 's. The 's can sit anywhere between the 's.
So every string in has an odd number of 's, which means at least one. Conversely, take any string with an odd number of 's. Its first is matched by the leading part, and the remaining 's pair up in order. The 's between them are absorbed by the parts. Hence .
For , exactly half of the strings of length have an odd number of 's. To see this, flip the first symbol between and . This pairs each even-parity string with an odd-parity one. So the count is .
For , the empty string has zero 's, so it is not in . The count is .
: ; : ; : ; : .
Total .
KEY IDEA
The expression generates exactly the strings with an odd number of 's. Among strings of each length , half have odd parity, so count per length.
WATCH OUT FOR
Counting the empty string, or counting only strings with exactly one or only some of the odd- strings. Forgetting that the parts let the 's go anywhere is the usual cause.
From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 18 Finite automata questions, with notes
More Finite automata questions
- GATE 2023 CS Q.19 · MCQ · 1 markConsider the following definition of a lexical token id for an identifier in a programming language, using…
- GATE 2023 CS Q.63 · NAT · 2 marksConsider the language L over the alphabet 0, 1, given below: L = w 0,1^* w does not contain three or more…
- GATE 2022 CS Q.12 · MCQ · 1 markWhich one of the following regular expressions correctly represents the language of the finite automaton…
- GATE 2020 CS Q.7 · MCQ · 1 markWhich one of the following regular expressions represents the set of all binary strings with an odd number…
