The number of strings of length 4 that are generated by the regular expression…

2016

The number of strings of length 4 that are generated by the regular expression (0∣ϵ)1+2(3∣ϵ) where | is an alternation character and {+, *} are quantification characters, is :

  1. A.

    08

  2. B.

    10

  3. C.

    11

  4. D.

    12

Attempted by 100 students.

Show answer & explanation

Correct answer: D

Correct Answer is 12.

The expression is: 

(0∣ϵ)1+2∗(3∣ϵ)

Let's break down the components:

  1. Prefix (0∣ϵ): The string can start with a 0 (length 1) or nothing (ϵ, length 0).

  2. Middle 1+: There must be at least one 1 (length ≥ 1).

  3. Middle 2∗: There can be zero or more 2s (length ≥ 0).

  4. Suffix (3∣ϵ): The string can end with a 3 (length 1) or nothing (ϵ, length 0).

To find strings of exactly length 4, we can split the problem into 4 cases based on the choices made for the Prefix and Suffix.

Step-by-Step Calculation

Case 1: Prefix is ϵ and Suffix is ϵ

  • Remaining Expression: 1+2∗

  • Target Length: We need the middle section to have a total length of 4.

  • Combinations: We must have at least one 1. The rest are 2s.

    1. 1111 (Four 1s, zero 2s)

    2. 1112 (Three 1s, one 2)

    3. 1122 (Two 1s, two 2s)

    4. 1222 (One 1, three 2s)

  • Count: 4 strings

Case 2: Prefix is 0 and Suffix is ϵ

  • Remaining Expression: 01+2∗

  • Target Length: The 0 takes up 1 character. We need the 1+2∗ part to have a length of 3.

  • Combinations:

    1. 0 + 111 → 0111

    2. 0 + 112 → 0112

    3. 0 + 122 → 0122

  • Count: 3 strings

Case 3: Prefix is ϵ and Suffix is 3

  • Remaining Expression: 1+2∗3

  • Target Length: The 3 takes up 1 character. We need the 1+2∗ part to have a length of 3.

  • Combinations:

    1. 111 + 3 → 1113

    2. 112 + 3 → 1123

    3. 122 + 3 → 1223

  • Count: 3 strings

Case 4: Prefix is 0 and Suffix is 3

  • Remaining Expression: 01+2∗3

  • Target Length: The 0 and 3 take up 2 characters. We need the 1+2∗ part to have a length of 2.

  • Combinations:

    • 0 + 11 + 3 → 0113

    • 0 + 12 + 3 → 0123

    • (Note: 0223 is not allowed because we must have at least one 1)

  • Count: 2 strings

Total Calculation

Summing up the counts from all cases:

4(Case 1)+3(Case 2)+3(Case 3)+2(Case 4)=12


Explore the full course: Mppsc Assistant Professor