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 ______.
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 ______.
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)
Count all strings over of length to : .
Strings in are together with the all-0 strings and all-1 strings. Each length to gives such strings, so .
Strings in of length at most are , one per length, so strings. Strings in are , also strings.
The two parts of start with different symbols, so they share no string and .
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 .
.
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