Question:

Consider the following two regular expressions over the alphabet \(\{0,1\}\): \[ r = 0^* + 1^* \quad \text{and} \quad s = 01^* + 10^*. \] The total number of strings of length less than or equal to 5, which are neither in \( r \) nor in \( s \), is \_\_\_\_\_\_.

Updated On: Jan 22, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Given: \[ r = 0^* + 1^* \quad \text{(either all zeros or all ones)}, \] \[ s = 0 \, 1^* + 1 \, 0^* \quad \text{(start with zero, then all ones, or start with one, then all zeros)}. \] Alphabet: \[ \Sigma = \{0, 1\}. \] For all strings of length \( n \), we have: \( 2 \) strings from \( r \) (all zeros or all ones), \( 2 \) strings from \( s \) (strings starting with \( 0 \) followed by ones, or starting with \( 1 \) followed by zeros). For \( \Sigma^2 \): \[ \text{\# strings not in \( r \) and \( s \)} = 2^2 - 4 = 4 - 4 = 0. \] For \( \Sigma^3 \): \[ \text{\# strings not in \( r \) and \( s \)} = 2^3 - 4 = 8 - 4 = 4. \] For \( \Sigma^4 \): \[ \text{\# strings not in \( r \) and \( s \)} = 2^4 - 4 = 16 - 4 = 12. \] For \( \Sigma^5 \): \[ \text{\# strings not in \( r \) and \( s \)} = 2^5 - 4 = 32 - 4 = 28. \] Total number of strings not in \( r \) and not in \( s \) for string lengths less than or equal to 5: \[ = (2^2 - 4) + (2^3 - 4) + (2^4 - 4) + (2^5 - 4). \] \[ = (4 - 4) + (8 - 4) + (16 - 4) + (32 - 4). \] \[ = 0 + 4 + 12 + 28 = 44. \] Final Answer: \[ \boxed{44} \]
Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions