Blog
Theory of Automata Final Past Paper 2015 – UOS Main Campus
University of Sargodha main campus Theory of Automata final paper held on 17 February 2015 (60 marks, 120 minutes). Retyped from the original paper, with solved answers below.
Solved answers
Q1 – Short answers (20)
a) S → aS | Sb | a | b generates a*b* − {Λ} = a⁺b* + a*b⁺: any number of a’s followed by any number of b’s, at least one letter.
b) CFLs are not closed under intersection. L₁ = {aⁿbⁿcᵐ} and L₂ = {aᵐbⁿcⁿ} are both CFLs, but L₁ ∩ L₂ = {aⁿbⁿcⁿ} is not a CFL. On the other hand, L ∩ L = L is a CFL. So the intersection may or may not be a CFL.
c) CFLs are not closed under complement. Example 1: if complement were always a CFL, then L₁ ∩ L₂ = (L₁’ ∪ L₂’)’ would be a CFL for all CFLs, contradicting (b). Example 2: the complement of {ww | w ∈ {a,b}*} is a CFL, but {ww} itself is not a CFL. (Also: {aⁿbⁿcⁿ}’ is a CFL while {aⁿbⁿcⁿ} is not.)
d) False. (a + b)* is regular, but its subset {aⁿbⁿ | n ≥ 0} is not regular. (Some subsets are regular, e.g. {ab} ⊂ (a + b)*, but not every subset.)
e) Every regular language has a CFG (a regular grammar), but some CFLs are not regular. Example: S → aSb | Λ generates {aⁿbⁿ}, which no FA can accept (an FA cannot count unboundedly). So CFGs are strictly more powerful than FAs.
Q2 – CFGs (10)
a) No substring bbb: S → aS | baS | bbaS | Λ | b | bb.
b) {aⁱbʲ | i ≠ j}: S → A | B; A → aA | aC (more a’s); B → Bb | Cb (more b’s); C → aCb | Λ. (A produces aᵏ·aⁿbⁿ with k ≥ 1; B produces aⁿbⁿ·bᵏ with k ≥ 1.)
Q3 – PDA (8+2)
a) L = {aⁱb²ⁱ | i > 0}: for every a read, PUSH two X’s on the stack. When b’s start, for every b POP one X. Accept when the input ends and the stack is empty (back to the bottom symbol); reject if a b appears with an empty stack, an a appears after b, or X’s remain. Example: aabbbb pushes 4 X’s and pops 4 → accept.
b) For L₁ ∪ L₂, make a new START state with Λ-transitions (non-deterministic branches) to the start states of PDA₁ and PDA₂. A word is accepted if either branch accepts, so the new PDA accepts all the words of both languages.
Q4 (a) – Pumping lemma for {aⁿb²aⁿ⁺¹} (7)
Assume L is regular with pumping length p. Take w = aᵖ bb aᵖ⁺¹ ∈ L. For any split w = xyz with |xy| ≤ p and |y| ≥ 1, y consists only of a’s from the first block: y = aᵏ, k ≥ 1. Pump: xy²z = aᵖ⁺ᵏ bb aᵖ⁺¹. Now the first block has p + k a’s and the last has p + 1, but it should have (p + k) + 1. Since k ≥ 1, xy²z ∉ L — a contradiction. So L is not regular. ∎
b) Ambiguous grammar (3): a CFG is ambiguous if some word has two different derivation trees (or two different leftmost derivations). Example: S → S + S | S * S | a gives two trees for a + a * a.
Q5 – Turing machine for half-equal (10)
Language: number of a’s = half the number of b’s (#b = 2·#a). Idea: repeatedly cross off one a and two b’s.
- Scan right from the left end to the first uncrossed a; replace it with X. If there is no a, go to step 4.
- Return to the left end and scan for the first uncrossed b; replace it with Y. If none, reject.
- Again find another uncrossed b; replace with Y. If none, reject. Go back to the left end and repeat from step 1.
- No a’s are left: scan the tape; if any uncrossed b remains, reject; otherwise (only X, Y and blanks) accept.
Example: abb → XYY → accept; aabbb → after one round XaYYb, second round needs two b’s but only one is left → reject.
