GATE Computer ScienceVery hardGATE CS (PYQ pattern)

How many strings of length 10 over {a, b, c} contain neither ab nor ba as a substring?

  1. A. 8119
  2. B. 57001
  3. C. 8631
  4. D. 5120

Correct answer: A. 8119

Count with a 3-state machine (last symbol a, b or c). Transitions: a→{a, c}, b→{b, c}, c→{a, b, c}; summing the path counts for 10 steps gives 8119.

More Theory of Computation questions

Exams that ask this topic