All Exams Test series for 1 year @ ₹349 only
Question

Which of the following string is not generated by the grammar : $S \rightarrow SaSbS \mid \epsilon$ ?

The correct answer is
$aaabb$

Grammar String Generation Analysis

The given grammar is $S \rightarrow SaSbS \mid \epsilon$. This grammar generates strings based on recursive rules. A key property of strings generated by this grammar is that they must contain an equal number of 'a's and 'b's.

Let's analyze why:

  • The base case is $S \rightarrow \epsilon$, which generates the empty string (0 'a's, 0 'b's).
  • The recursive step is $S \rightarrow SaSbS$. If we assume that the strings generated by the three $S$ instances within this rule ($S_1, S_2, S_3$ in $S \rightarrow S_1 a S_2 b S_3$) have an equal number of 'a's and 'b's, then the resulting string $S_1 a S_2 b S_3$ adds one 'a' and one 'b'. Thus, the total number of 'a's and 'b's remains equal.

Therefore, any string generated by this grammar must satisfy $n_a(string) = n_b(string)$, where $n_a$ is the count of 'a's and $n_b$ is the count of 'b's.

Checking String Options

We will now check the number of 'a's and 'b's for each option:

  • Option 1: $aabb$ - Contains 2 'a's and 2 'b's. The counts are equal.
  • Option 2: $abab$ - Contains 2 'a's and 2 'b's. The counts are equal.
  • Option 3: $aababb$ - Contains 3 'a's and 3 'b's. The counts are equal.
  • Option 4: $aaabb$ - Contains 3 'a's and 2 'b's. The counts are not equal.

Conclusion on Derivability

Since the string $aaabb$ does not have an equal number of 'a's and 'b's, it cannot be generated by the grammar $S \rightarrow SaSbS \mid \epsilon$. The other options can be derived:

  • $aabb$: $S \Rightarrow SaSbS \Rightarrow \epsilon a (SaSbS) b \epsilon \Rightarrow a(SaSbS)b \Rightarrow a(\epsilon a \epsilon b \epsilon)b \Rightarrow aabb$.
  • $abab$: $S \Rightarrow SaSbS \Rightarrow \epsilon a \epsilon b (SaSbS) \Rightarrow ab(SaSbS) \Rightarrow ab(\epsilon a \epsilon b \epsilon) \Rightarrow abab$.
  • $aababb$: $S \Rightarrow SaSbS \Rightarrow \epsilon a S b S \Rightarrow a S b S \Rightarrow a (SaSbS) b S \Rightarrow a S a S b S b S \Rightarrow a \epsilon a \epsilon b S b \Rightarrow aab S b \Rightarrow aab (SaSbS) b \Rightarrow aab (a \epsilon b \epsilon) b \Rightarrow aababb$.

The string that is not generated by the grammar is $aaabb$.

Was this answer helpful?

Important Questions from Miscellaneous

  1. Which of the following scheduler/schedulers is/are also called CPU scheduler ?
    (A). Short Term Scheduler
    (B). Long Term Scheduler
    (C). Medium Term Scheduler
    (D). Asymmetric Scheduler
    Choose the correct answer from the options given below:
  2. A situation where two or more processes are blocked, waiting for resources held by each other is called:
  3. External fragmentation occurs ________.
  4. Which disk scheduling algorithm looks for the track closest to the current head position?
  5. Which CPU scheduling algorithm prefers the process with the shortest burst time?
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App