Blog
Theory of Automata Past Paper 2026 – BS CS 4th Semester UOS (CSDC-5101)
University of Sargodha Theory of Automata (CSDC-5101) paper for AD/BS Computer Science 4th semester, 2026 exam (60 marks, 2:30 hours) – one of the newest papers on the site. The paper has been retyped, and solved answers for all 12 short questions and all five long questions are given below.
Solved answers
Q1 – Short answers (12 × 2)
i. What is a regular language? A language that can be described by a regular expression, or equivalently accepted by a finite automaton (DFA/NFA). Example: all strings over {a, b} ending in a.
ii. What is a finite automaton? A machine with a finite set of states that reads the input one symbol at a time and changes state by a transition function: M = (Q, Σ, δ, q0, F). It accepts if it ends in a final state.
iii. Language accepted by a finite automaton: The set of all strings that take the automaton from the start state to some final state: L(M) = {w ∈ Σ* | δ*(q0, w) ∈ F}.
iv. What is a regular expression? A pattern built from symbols, ε and ∅ using union (+), concatenation and Kleene star (*) that describes a regular language, e.g. (a+b)*ab.
v. What is a dead state? A non-final (trap) state from which no final state can be reached; once entered, every input keeps the machine there and the string is rejected.
vi. What is the pumping lemma? For every regular language L there is a length p such that any string s ∈ L with |s| ≥ p can be split s = xyz with |xy| ≤ p, |y| ≥ 1 and xyiz ∈ L for all i ≥ 0. It is used to prove that a language is not regular.
vii. Deterministic vs non-deterministic PDA: A DPDA has at most one move for each (state, input, stack top) and accepts deterministic CFLs (e.g. wcwR); an NPDA may have several choices and accepts all CFLs (e.g. wwR). NPDAs are more powerful.
viii. What is a Moore machine? A finite-state machine with output in which the output depends only on the current state: (Q, Σ, Δ, δ, λ, q0) with λ: Q → Δ. An input of length n gives n + 1 outputs.
ix. What is a transition function? The rule δ that gives the next state: for a DFA δ: Q × Σ → Q, for an NFA δ: Q × (Σ ∪ {ε}) → 2Q.
x. What is an inductive proof? A proof by mathematical induction: prove the statement for the base case (n = 0 or 1), assume it for n = k (inductive hypothesis) and prove it for n = k + 1; then it holds for all n.
xi. Relationship between FA and regular expressions: They are equivalent (Kleene’s theorem): every regular expression can be converted to an FA (Thompson’s construction) and every FA to a regular expression (state elimination). Both describe exactly the regular languages.
xii. What is a pushdown automaton? A finite automaton with an extra stack: M = (Q, Σ, Γ, δ, q0, Z0, F). The stack gives unlimited memory, so PDAs accept context-free languages such as anbn.
Q2 – Strings starting with b and ending with a (12)
Over Σ = {a, b}: b(a + b)*a. The first symbol must be b, the last must be a, and anything can come in between (including nothing), so the shortest string is ba. Examples accepted: ba, baa, bba, babba; rejected: ab, b, bab.
Q3 – Finite automaton for b*a (12)
States: q0 (start), q1 (final), q2 (dead).
| State | a | b |
|---|---|---|
| → q0 | q1 | q0 |
| * q1 | q2 | q2 |
| q2 (dead) | q2 | q2 |
q0 loops on b (any number of b’s), the single a moves to the final state q1, and any symbol after that goes to the dead state. Accepts a, ba, bba, bbba …
Q4 – Finite automaton for (b + a)*ba (12)
The language is all strings ending in “ba”. DFA (q2 is final):
| State | meaning | a | b |
|---|---|---|---|
| → q0 | no useful suffix | q0 | q1 |
| q1 | last symbol b | q2 | q1 |
| * q2 | ends in ba | q0 | q1 |
Trace “abba”: q0 –a→ q0 –b→ q1 –b→ q1 –a→ q2 (accept). Trace “bab”: q0 → q1 → q2 → q1 (reject).
Q5 – Is L = {anbn | n ≥ 1} regular? (12)
No. Proof by pumping lemma: assume L is regular with pumping length p. Take s = apbp ∈ L, |s| ≥ p. For any split s = xyz with |xy| ≤ p and |y| ≥ 1, y lies inside the a’s, so y = ak, k ≥ 1. Pump i = 2: xy2z = ap+kbp, which has more a’s than b’s and is not in L. This contradicts the pumping lemma, so L is not regular. (Intuitively, a finite automaton cannot count an unlimited number of a’s; L is context-free: S → aSb | ab.)
Q6 – CFG for all palindromes over {a, b} (12)
S → aSa | bSb | a | b | ε
aSa and bSb add the same symbol at both ends; a and b give odd-length centres and ε gives even-length palindromes. Derivation of “abba”: S ⇒ aSa ⇒ abSba ⇒ abba. Derivation of “aba”: S ⇒ aSa ⇒ aba.
