Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2004 | Question 88
  • Last Updated : 26 Sep, 2014

Consider the following grammar G:

S → bS | aA | b
A → bA | aB
B → bB | aS | a 

Let Na(w) and Nb(w) denote the number of a’s and b’s in a string w respectively. The language L(G) ⊆ {a, b}+ generated by G is
(A) { w | Na(w) > 3Nb(w)}
(B) { w | Nb(w) > 3Nb(w)}
(C) { w | Na(w) = 3k, k ∈ {0, 1, 2, …}}
(D) { w | Nb(w) = 3k, k ∈ {0, 1, 2, …}}


Answer: (C)

Explanation: Here, we have

S → bS
S → baA	     (S → aA)
S → baaB     (A → aB)
S → baaa     (B → a)

Therefore, | Na (w) | = 3.

Also, if we use A → bA instead of A → aB,

S → baA
S → babA

To terminate A, we would have to use A → aB as only B terminates at a (B → a).

S → baA
S → babA
S → babaB
S → babaa

Thus, here also, | Na (w) | = 3.

 
So, C is the correct choice.

 
Please comment below if you find anything wrong in the above post.


Quiz of this Question

sudo-gate-course

My Personal Notes arrow_drop_up
Recommended Articles
Page :