GATE Computer ScienceVery hardGATE CSE · ISRO
Which regular expression (over {a, b}, + means union) generates exactly the strings with an even number of b's?
- A. (a*ba*b*)*
- B. (a + bb)*
- C. a*(ba*b)*
- D. (a*ba*b)*a*
Correct answer: D. (a*ba*b)*a*
(a*ba*b)*a* groups b's in pairs with arbitrary a's around them, so every even-b string is generated and no odd one is. (a*ba*b*)* equals Σ*, and (a + bb)* misses abab.
More Theory of Computation questions
- The pumping lemma for regular languages states that some length p exists such that every w ∈ L with |w| ≥ p can be split w = xyz with |xy|…
- For a context-free grammar G given as input, how many of the following problems are undecidable? (a) Is L(G) = Σ? (b) Is L(G) regular? (c)…
- A DFA reads a binary string most-significant bit first (leading zeros allowed) and tracks the value so far modulo 12, accepting exactly…
- Let L be the set of strings over {a, b} in which the third symbol from the right is a, or the last symbol is b (strings shorter than 3…
- An NFA over {a, b} has states 0–4, start state 0 and accepting state 4. Transitions: 0 –a→ {0,1}; 0 –b→ {0}; 1 –a,b→ {2}; 2 –a,b→ {3}; 3…
- A DFA over {a, b} has states 0–4, start 0 and accepting states {2, 4}. Transitions (on a, b): 0:(1,2), 1:(2,0), 2:(3,3), 3:(4,1), 4:(4,0)…