IAE Academy

GATE 2024 CS1 Q.61: solution and answer

GATE 2024 · CS1Q.61 · 2 marks · NAT

Consider the following two regular expressions over the alphabet :

The total number of strings of length less than or equal to 5, which are neither in nor in , is ______.

See the question in the paper

Answer and solution

ANSWER

The number of strings of length at most 5 that are in neither nor is 44.

Official answer: 44Source: Official answer key, GATE 2024 CS1 (IISc Bengaluru)

  1. Count all strings over of length to : .

  2. Strings in are together with the all-0 strings and all-1 strings. Each length to gives such strings, so .

  3. Strings in of length at most are , one per length, so strings. Strings in are , also strings.

  4. The two parts of start with different symbols, so they share no string and .

  5. Overlap of with : a string of lies in only if it uses a single symbol. In that is only , and in only . Every other string of contains both and . So .

  6. .

  7. Strings of length at most in neither nor : .

KEY IDEA

Count the complement. Take all strings of length at most and subtract , using inclusion-exclusion with the overlap .

WATCH OUT FOR

Forgetting in , or forgetting that and belong to both and . This counts those two strings twice and gives , so the answer comes out .

From the GATE 2024 CS1 paper. Every question of this paper · Download the full paper · All 18 Finite automata questions, with notes

More Finite automata questions