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
This explanation is contributed by Vineet Purswani.
Quiz of this Question
Recommended Posts:
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 59
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 58
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 57
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 56
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 55
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 54
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 53
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 52
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 60
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 61
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 65
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 64
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 63
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 62
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 51
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 50
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 49
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 38
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 37
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 36

