Question

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 5, which are neither in rr nor in ss, is _________

Official answer and solution
Official answer
44
From
Official GATE 2024 answer key

Solution

Subtract the number of strings of length ≤5\le 5 in L(r)∪L(s)L(r) \cup L(s) from the total number of binary strings of length ≤5\le 5.

  1. Total binary strings of length ≤5\le 5:

    ∑k=052k=1+2+4+8+16+32=63\sum_{k=0}^{5} 2^k = 1 + 2 + 4 + 8 + 16 + 32 = 63
  2. Count strings in L(r)∪L(s)L(r) \cup L(s) of length k∈{0,1,2,3,4,5}k \in \{0, 1, 2, 3, 4, 5\}:

    • k=0k = 0: ϵ∈L(r)\epsilon \in L(r) →\rightarrow 1 string
    • k=1k = 1: 0, 1 ∈L(r)∪L(s)\in L(r) \cup L(s) →\rightarrow 2 strings
    • k=2k = 2: 00, 11 ∈L(r)\in L(r) and 01, 10 ∈L(s)\in L(s) →\rightarrow 4 strings
    • k=3k = 3: 000, 111 ∈L(r)\in L(r) and 011, 100 ∈L(s)\in L(s) →\rightarrow 4 strings
    • k=4k = 4: 0000, 1111 ∈L(r)\in L(r) and 0111, 1000 ∈L(s)\in L(s) →\rightarrow 4 strings
    • k=5k = 5: 00000, 11111 ∈L(r)\in L(r) and 01111, 10000 ∈L(s)\in L(s) →\rightarrow 4 strings

    Total strings in L(r)∪L(s)L(r) \cup L(s) of length ≤5\le 5 is 1+2+4+4+4+4=191 + 2 + 4 + 4 + 4 + 4 = 19.

  3. Strings in neither rr nor ss:

    63−19=4463 - 19 = 44
Final answer

44

Common trap

Forgetting to include the empty string ϵ\epsilon (of length 0) or double-counting strings of length 1 (0 and 1) that belong to both rr and ss.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 1 (CS1)
Question
61 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.