GATE Computer ScienceModerateGATE CS (PYQ pattern)
How many strings of length 6 over {a, b} contain both ab and ba as substrings?
- A. 50
- B. 57
- C. 52
- D. 48
Correct answer: C. 52
Inclusion–exclusion on the complements: strings with no ab are b*a* (7 of length 6), with no ba are a*b* (7), and with neither are aaaaaa and bbbbbb (2). 64 − 7 − 7 + 2 = 52.
More Theory of Computation questions
- How many states does the minimal complete DFA for { w ∈ {a, b} : ab occurs EXACTLY twice as a substring } have?
- L = { w ∈ {a, b} : #ab(w) ≡ #ba(w) (mod 3) }, where #ab and #ba count occurrences of these substrings. How many states does the minimal…
- L = { w ∈ {a, b} : |w| ≥ 2 and the 2nd symbol from the left equals the 2nd symbol from the right }. How many states does the minimal…
- L = { w ∈ {a, b} : na(w) ≡ 1 (mod 3) or w contains bb as a substring }. The minimal complete DFA has how many states?
- L = { w ∈ {a, b} : |w| ≥ 2 and the first symbol differs from the last symbol }. How many states does the minimal complete DFA for L have?
- L = { w ∈ {a, b} : w[i] = w[i+3] for every valid index i } (w is periodic with period 3). How many states does the minimal complete DFA…