GATE Computer ScienceHardGATE CS (PYQ pattern)

How many binary strings of length 12 contain neither 000 nor 111 as a substring?

  1. A. 466
  2. B. 288
  3. C. 754
  4. D. 1705

Correct answer: A. 466

Strings whose runs all have length 1 or 2 are counted by f(n) = f(n−1) + f(n−2) for each starting bit, so the total is 2·F(n+1); for n = 12 that is 2·233 = 466. Forbidding only 000 would give 1705.

More Theory of Computation questions

Exams that ask this topic