GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length 10 over {a, b} have an even number of occurrences of ab AND an even number of occurrences of ba?

  1. A. 272
  2. B. 256
  3. C. 512
  4. D. 136

Correct answer: A. 272

Let r be the number of runs. If the first and last symbols differ, #ab and #ba differ by 1, so one is odd. If they agree, r is odd and #ab = #ba = (r − 1)/2, which must be even: r ≡ 1 (mod 4). Strings of length 10 with r runs: 2·C(9, r − 1). r ∈ {1, 5, 9}: 2(1 + 126 + 9) = 272.

More Theory of Computation questions

Exams that ask this topic