GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length 9 over {a, b} satisfy (n_a − n_b) ≡ 0 (mod 3) AND contain no bb as a substring?

  1. A. 170
  2. B. 36
  3. C. 89
  4. D. 30

Correct answer: B. 36

With n_a + n_b = 9, n_a − n_b = 9 − 2n_b ≡ 0 (mod 3) ⇔ n_b ≡ 0 (mod 3). No bb means the b's are separated: choose n_b of the 10 gaps around the n_a a's, C(n_a + 1, n_b). n_b = 0: C(10,0) = 1; n_b = 3: C(7,3) = 35; n_b = 6: C(4,6) = 0. Total 36 (170 ignores bb, 89 ignores the mod condition).

More Theory of Computation questions

Exams that ask this topic