GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 88

Right-linear grammar counts a modulo three

Theory of Computation · Regular Expressions & Languages · Full GATE CSE 2004 paper

GATE 2004, Q88 2 marks · MCQ
Report issue

Regular Expressions & Languages

Question 88, GATE 2004: Grammar G has S→bS | aA | b; A→bA | aB; B→bB | aS | a. Na(w),Nb(w) count a,b symbols. Which describes L(G) within {a,b}^+ (nonempty words)?
Options:
(A) {w:Na(w)>3Nb(w)}
(B) {w:Nb(w)>3Na(w)}
(C) {w:Na(w)=3k, k∈{0,1,2,…}}
(D) {w:Nb(w)=3k, k∈{0,1,2,…}}
Question 88, GATE 2004: Grammar G has S→bS | aA | b; A→bA | aB; B→bB | aS | a. Na(w),Nb(w) count a,b symbols. Which describes L(G) within {a,b}^+ (nonempty words)?
Options:
(A) {w:Na(w)>3Nb(w)}
(B) {w:Nb(w)>3Na(w)}
(C) {w:Na(w)=3k, k∈{0,1,2,…}}
(D) {w:Nb(w)=3k, k∈{0,1,2,…}}
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Interpret S,A,B as states tracking the number of a symbols modulo 3: a advances S→A→B→S, while b leaves the state unchanged. Terminating production S→b ends with residue 0, and B→a also ends with residue 0.

2. Consequently every generated word has #a divisible by 3. Conversely any nonempty word with that property can be scanned along these transitions; if its last symbol is b it terminates via S→b, and if its last symbol is a it terminates via B→a.

3. Thus L={w in {a,b}^+ : #a(w)≡0 mod3}, option C in the stated positive-word universe.

4. Teaching check: There is no ε production, so the empty word is excluded despite having zero a symbols. The problem explicitly uses {a,b}^+, which resolves that apparent exception. Each a advances one of three residue states while any b preserves it.

Original paper, page 12