Blog
Theory of Automata Mid Past Paper – UOS Main Campus
University of Sargodha main campus Theory of Automata mid-term paper (1 hour). Retyped from the original paper, with solved answers below. Alphabet Σ = {a, b}.
Solved answers
Q1 (a) – Strings that do not end in “ba”
RE: Λ + a + b + (a + b)*(aa + ab + bb) — every string of length ≥ 2 whose last two letters are not “ba”, plus the short strings.
FA (track the last letters): q0 start (also accepting), q1 = “last letter b” (accepting), q2 = “ends in ba” (rejecting).
| State | a | b | Final? |
|---|---|---|---|
| →q0 | q0 | q1 | Yes |
| q1 | q2 | q1 | Yes |
| q2 | q0 | q1 | No |
From q2 an a gives “…aa” (fine, back to q0) and a b gives “…ab” → q1.
Q1 (b) – At least two a’s and at least two b’s
FA: use a 3 × 3 grid of states (i, j), where i = number of a’s seen (0, 1, 2+) and j = number of b’s seen (0, 1, 2+). Start at (0, 0); an a moves right (i + 1, capped at 2), a b moves down (j + 1, capped at 2). The only final state is (2, 2), which loops to itself on a and b. (9 states.)
RE: the sum of all orders in which the first two a’s and two b’s can appear, each separated by (a + b)*. For example: (a+b)*a(a+b)*a(a+b)*b(a+b)*b(a+b)* + (a+b)*a(a+b)*b(a+b)*a(a+b)*b(a+b)* + … covering the 6 arrangements aabb, abab, abba, baab, baba, bbaa.
Q1 (c) – Starts and ends with the same letter
RE: a + b + a(a + b)*a + b(a + b)*b.
FA: start q0; on a go to q1 (accepting: “started with a, last letter a”); on b go to q3 (accepting: “started with b, last letter b”). q1 –a→ q1, q1 –b→ q2 (not final); q2 –a→ q1, q2 –b→ q2. Similarly q3 –b→ q3, q3 –a→ q4 (not final); q4 –b→ q3, q4 –a→ q4. Final states: q1, q3.
Q2 – Symmetric difference is regular (05)
L ⊕ M = (L − M) ∪ (M − L) = (L ∩ M’) ∪ (M ∩ L’). Regular languages are closed under complement (swap final and non-final states of a DFA), under intersection (product construction) and under union. L and M are regular, so M’ and L’ are regular, so L ∩ M’ and M ∩ L’ are regular, and their union is regular. Hence L ⊕ M is regular. ∎ (Directly: run DFAs for L and M in parallel with the product construction and accept a pair (p, q) when exactly one of p, q is final.)
Q3 – Substring “bbb” (03)
FA: q0 (start), q1 (seen b), q2 (seen bb), q3 (seen bbb, final). q0 –a→ q0, q0 –b→ q1; q1 –a→ q0, q1 –b→ q2; q2 –a→ q0, q2 –b→ q3; q3 –a,b→ q3.
Converting to RE (state elimination): before reaching q3, the machine reads any string without bbb that ends just before the three b’s, i.e. (a + ba + bba)*; then bbb; then anything. RE = (a + ba + bba)* bbb (a + b)*.
