Skip to content
Official PYQ · 2024

GATE CS 2024 Set 1 Q51 — Regular Expressions and Finite Automata

Explain with AI
Consider the following two regular expressions over the alphabet {0,1}\{0,1\} :

r=0∗+1∗r= 0^{*}+1^{*}

s=01∗+10∗s = 01^{*} + 10^{*}

The total number of strings of length less than or equal to 55, which are neither in rr nor in ss, is ________.
View worked solution

Answer: 44

We need to find the number of binary strings ww of length ∣w∣≤5|w| \le 5 that are neither in L(r)L(r) nor in L(s)L(s), where:

  • r=0∗+1∗r = 0^* + 1^* (strings consisting of only 00s or only 11s)
  • s=01∗+10∗s = 01^* + 10^* (strings starting with 00 followed by any number of 11s, or starting with 11 followed by any number of 00s)

Let 2n2^n be the total number of binary strings of length nn. We analyze the number of strings of length nn in L(r)∪L(s)L(r) \cup L(s) for each n∈{0,1,2,3,4,5}n \in \{0, 1, 2, 3, 4, 5\}:

Length (nn)Total (2n2^n)L(r)L(r) StringsL(s)L(s) StringsUnion ∣L(r)∪L(s)∣|L(r) \cup L(s)|Neither (2n−∣L(r)∪L(s)∣2^n - |L(r) \cup L(s)|)
01{ϵ}\{\epsilon\} (1)∅\emptyset (0)11−1=01 - 1 = 0
12{0,1}\{0, 1\} (2){0,1}\{0, 1\} (2)22−2=02 - 2 = 0
24{00,11}\{00, 11\} (2){01,10}\{01, 10\} (2)44−4=04 - 4 = 0
38{000,111}\{000, 111\} (2){011,100}\{011, 100\} (2)48−4=48 - 4 = 4
416{0000,1111}\{0000, 1111\} (2){0111,1000}\{0111, 1000\} (2)416−4=1216 - 4 = 12
532{00000,11111}\{00000, 11111\} (2){01111,10000}\{01111, 10000\} (2)432−4=2832 - 4 = 28

Summing the counts of "Neither" for all lengths 0≤n≤50 \le n \le 5:

Total=0+0+0+4+12+28=44\text{Total} = 0 + 0 + 0 + 4 + 12 + 28 = 44

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular Expressions and Finite Automata questions