Open In App

GATE | GATE-CS-2006 | Question 85

Last Updated : 28 Jun, 2021
Like Article
Like
Save
Share
Report

In the correct grammar of above question, what is the length of the derivation (number of steps starring from S) to generate the string albm with l ≠ m?

(A)

max(l,m) + 2

(B)

l + m + 2

(C)

l + m + 3

(D)

max(l, m) + 3



Answer: (A)

Explanation:

Correct grammar of the last question was (D), which is:

S -> AC|CB
C -> aCb|epsilon
A -> aA|a
B -> Bb|b

Now, the most optimal and intuitive way to generate a string of the form albm would be to first use \”C -> aCb|epsilon\” production rule to get as many a and b as we can, which would be min(l,m). To get the rest of the string, we could just use latter two production rules accordingly. Formally deriving the string of the general format albm from the above grammar –

1.  S -> AC 
2.      -> A(aCb) 
3.      -> …. 
4.      -> ….
5.      -> A(am C bm
6.      -> A(am bm
7.       -> aA(am bm
8.      -> …. 
9.      -> ….
10.    -> a(l-m-1)A(am bm
11.     -> al bm

From above set of derivation steps we can count the total steps as follows:

Production 1 took 1 step          :           1                      [using S->AC]
Production 2-5 took steps      :      min(l,m)              [using C->aCb] 
Production 6 took 1 step         :           1                      [using C->epsilon]
Production 7-11 took steps      : max(l,m)-min(l,m)   [using A -> aA|a or B -> Bb|b]
                        
               Total steps   : max(l,m) + 2     

Hence, answer should be (A): max(l,m) + 2 


Quiz of this Question
Please comment below if you find anything wrong in the above post


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads