GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many strings of length 8 over {a, b} contain aba as a substring but do NOT contain bab?
- A. 46
- B. 72
- C. 128
- D. 40
Correct answer: A. 46
Complementary counting: strings of length 8 with no bab number 114 (DFA/recurrence on the suffix state ε, b, ba); those avoiding both aba and bab are the strings whose internal runs all have length ≥ 2 — 68 of them. 114 − 68 = 46.
More Theory of Computation questions
- How many strings of length 8 over {a, b, c} have no two adjacent equal symbols and also have first symbol ≠ last symbol?
- How many binary strings of length 10 contain no two consecutive 1s and also do not have 1 at both the first and the last position?
- How many strings of length 9 over {a, b} satisfy (na − nb) ≡ 0 (mod 3) AND contain no bb as a substring?
- How many binary strings of length 10 contain 0110 as a substring?
- How many strings of length 7 over {a, b} belong to the language of the regular expression (a + ab + ba)?
- How many strings of length 10 over {a, b} lie in the language of the regular expression abab?