IAE Academy

GATE 2024 CS2 Q.62: solution and answer

GATE 2024 · CS2Q.62 · 2 marks · NAT

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 ______.

See the question in the paper

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)

  1. 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.

  2. 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 .

  3. 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 .

  4. For , the empty string has zero 's, so it is not in . The count is .

  5. : ; : ; : ; : .

  6. 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