GATE Computer ScienceHardGATE CS (PYQ pattern)

Let L = { w ∈ {a, b}* : (2·n_a(w) + 4·n_b(w)) mod 6 = 2 }. How many strings of length exactly 7 belong to L?

  1. A. 42
  2. B. 43
  3. C. 21
  4. D. 64

Correct answer: B. 43

2n_a + 4n_b ≡ 2 (mod 6) ⇔ n_a + 2n_b ≡ 1 (mod 3). With n_b = 7 − n_a this is n_a + 14 − 2n_a ≡ 1, i.e. n_a ≡ 13 ≡ 1 (mod 3), so n_a ∈ {1, 4, 7}: C(7,1) + C(7,4) + C(7,7) = 7 + 35 + 1 = 43. (Solving with n_a ≡ 2 gives the trap 42.)

More Theory of Computation questions

Exams that ask this topic