Consider the following two regular expressions over the alphabet {0,1}: π‘Ÿ =…

2024

Consider the following two regular expressions over the alphabet {0,1}:

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β π‘Ÿ = 0βˆ— + 1βˆ—

                    𝑠 = 01βˆ— + 10βˆ—

The total number of strings of length less than or equal to 5, which are neither in π‘Ÿ nor in 𝑠, is _________

Attempted by 100 students.

Show answer & explanation

Correct answer: 44

Answer: 44

Brief explanation:

  • Total number of binary strings of length ≀ 5 = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 = 63.

  • For length 0: r contains the empty string, s contains none, so union count = 1.

  • For length 1: r contains "0" and "1" (both 0* and 1*), s also contains "0" and "1" (0 1* and 1 0*). The union count for length 1 = 2.

  • For each length n = 2,3,4,5: r contributes two strings (all-0s and all-1s) and s contributes two distinct strings (0 followed by all 1s, and 1 followed by all 0s), with no overlap, so union count per length = 4. Total for these four lengths = 16.

  • Total number of strings that are in r or s for lengths ≀5 = 1 + 2 + 16 = 19. Therefore number of strings of length ≀5 that are neither in r nor in s = 63 - 19 = 44.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir