GATE CS 2024 Set 1 — Question 61

NAT+2 / -0MediumRegular ExpressionsFinite Automata & Regular LanguagesTheory of Computation

Theory of Computation → Finite Automata & Regular Languages → Regular Expressions

Last updated

Question

Consider the following two regular expressions over the alphabet {0,1}\{0,1\}:r=0+1r = 0^* + 1^*s=01+10s = 01^* + 10^*The total number of strings of length less than or equal to 5, which are neither in rr nor in ss, is _________

Correct answer

44 to 44

Solution

To find the number of strings of length 5\le 5 that are neither in L(r)L(r) nor in L(s)L(s), we first identify the strings in L(r)L(s)L(r) \cup L(s) for each length n{0,1,2,3,4,5}n \in \{0, 1, 2, 3, 4, 5\}.
1.Regular Expression r=0+1r = 0^* + 1^*:
Strings in L(r)L(r) are of the form 0n0^n or 1n1^n.
  • n=0n=0: ϵ\epsilon (1 string)
  • n=1n=1: 0,10, 1 (2 strings)
  • n=2n=2: 00,1100, 11 (2 strings)
  • n=3n=3: 000,111000, 111 (2 strings)
  • n=4n=4: 0000,11110000, 1111 (2 strings)
  • n=5n=5: 00000,1111100000, 11111 (2 strings)
2. Regular Expression s=01+10s = 01^* + 10^*:
Strings in L(s)L(s) are of the form 01n01^n or 10n10^n.
  • n=0n=0: None (0 strings)
  • n=1n=1: 0,10, 1 (2 strings)
  • n=2n=2: 01,1001, 10 (2 strings)
  • n=3n=3: 011,100011, 100 (2 strings)
  • n=4n=4: 0111,10000111, 1000 (2 strings)
  • n=5n=5: 01111,1000001111, 10000 (2 strings)
3. Union L(r)L(s)L(r) \cup L(s):
  • n=0n=0: {ϵ}\{\epsilon\} (1 string)
  • n=1n=1: {0,1}\{0, 1\} (2 strings)
  • n=2n=2: {00,11,01,10}\{00, 11, 01, 10\} (4 strings)
  • n=3n=3: {000,111,011,100}\{000, 111, 011, 100\} (4 strings)
  • n=4n=4: {0000,1111,0111,1000}\{0000, 1111, 0111, 1000\} (4 strings)
  • n=5n=5: {00000,11111,01111,10000}\{00000, 11111, 01111, 10000\} (4 strings)

Total strings in L(r)L(s)L(r) \cup L(s) of length 5=1+2+4+4+4+4=19\le 5 = 1 + 2 + 4 + 4 + 4 + 4 = 19.
4.Total strings of length 5\le 5 over {0,1}\{0, 1\}:
Total = 20+21+22+23+24+25=1+2+4+8+16+32=632^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 = 1 + 2 + 4 + 8 + 16 + 32 = 63.
5.Strings neither in rr nor in ss:
Count = Total - L(r)L(s)=6319=44|L(r) \cup L(s)| = 63 - 19 = 44.

More questions on Finite Automata & Regular Languages

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free