Theory of Automata, Past Papers

Theory of Automata & Formal Languages Past Paper 2025 BSCS UOS

Theory of Automata & Formal Languages Past Paper 2025 BSCS UOS

Download and read Theory of Automata & Formal Languages Past Paper 2025 BSCS UOS

Theory of Automata Past Paper 2025 (text version)

University of Sargodha – BS 5th Semester Examination 2025
Subject: Computer Science · Paper: Theory of Automata / Theory of Automata & Formal Languages (CSCC-301 / CS-3131) · Time: 2:30 hours · Maximum marks: 60
Objective part is compulsory. Attempt any three questions from the subjective part. Illustrate answers with diagrams where needed.

Q.1 Short answers (2 × 12)

  1. State whether R1 = (ab)*a and R2 = a(ba)* are equal.
  2. What are the special features of a Turing machine?
  3. What is a transition graph?
  4. What is a null production?
  5. What is a GTG?
  6. Discuss ambiguity in grammars and languages.
  7. What is a pushdown automaton (PDA)?
  8. Give an example of an application of regular expressions.
  9. How can you prove a language is not regular?
  10. Explain the pumping lemma for context-free languages.
  11. Design a CFG for the language that accepts all strings not ending in a double letter.
  12. Design an RE for the language over {0, 1} with at most one “1”.

Subjective part (3 × 12)

  • Q.2 Construct DFAs: (a) an FA that accepts all words that do not have the substring “aba”; (b) one that accepts only words ending with “baa”.
  • Q.3 Design a PDA for L = {aⁿbᵐ | n, m ≥ 0 and n > m}.
  • Q.4 Using Kleene’s theorem, construct a DFA for FA1 ∩ FA2 where L1 = (a + b)b(a + b)* and L2 = b(a + b)*.
  • Q.5 Discuss the properties of regular languages, including closure and decision properties.
  • Q.6 Define the classes P and NP. Discuss an NP-complete problem and its implications.

Short questions solved

  1. Yes, equal. Both generate a, aba, ababa, … since (ab)ⁿa = a(ba)ⁿ for every n ≥ 0.
  2. Turing machine: an infinite tape, a head that can read and write and move left or right, a finite set of states with halt states – the most powerful model of computation (it recognises recursively enumerable languages).
  3. Transition graph (TG): like an FA, but edges may be labelled with strings (including Λ), there can be several start states, and a state may have zero or many edges for a letter.
  4. Null production: a production of the form A → Λ (A derives the empty string).
  5. GTG (generalized transition graph): a transition graph whose edges are labelled with regular expressions; used in proving Kleene’s theorem (FA → RE).
  6. Ambiguity: a grammar is ambiguous if some string has two different derivation trees (two leftmost derivations). A language is inherently ambiguous if every grammar for it is ambiguous.
  7. PDA: a finite automaton plus a stack (PUSH/POP); it accepts exactly the context-free languages.
  8. Application of RE: lexical analysis in compilers (recognising identifiers and numbers), text search (grep), input validation (e-mail formats).
  9. Use the pumping lemma for regular languages (or Myhill–Nerode): assume the language is regular, pump a long string and show the pumped string leaves the language – a contradiction.
  10. Pumping lemma for CFLs: if L is context-free, there is p such that any w ∈ L with |w| ≥ p can be written w = uvxyz with |vxy| ≤ p, |vy| ≥ 1 and uvⁱxyⁱz ∈ L for all i ≥ 0. Used to prove a language is not context-free (e.g. aⁿbⁿcⁿ).
  11. CFG (alphabet {a, b}): S → Λ | a | b | Xab | Xba; X → aX | bX | Λ. (A string not ending in a double letter is empty, a single letter, or ends in ab or ba.)
  12. RE: 0*(1 + Λ)0*, i.e. 0* + 0*10*.

Solved subjective questions

Q.2(a) No substring “aba” – q0 is the start state; q0, q1, q2 are final; q3 is a dead (trap) state.

StateMeaningab
→ q0 (final)no progressq1q0
q1 (final)ends in aq1q2
q2 (final)ends in abq3q0
q3contains aba (dead)q3q3

Q.2(b) Ends with “baa” – q3 is the only final state.

StateLast letters matchedab
→ q0noneq0q1
q1bq2q1
q2baq3q1
q3 (final)baaq0q1

Q.3 PDA for aⁿbᵐ, n > m – idea: push every a; pop one a for each b; at the end of the input at least one a must remain on the stack.

  1. START → READ letters: on a, PUSH a (stay in the reading-a state).
  2. On b with a on top: POP a and move to the reading-b state; there, each further b also POPs an a. A b with an empty stack → REJECT; an a after a b → REJECT.
  3. On end of input (Δ): POP – if the popped symbol is a, ACCEPT (n − m ≥ 1); if the stack is empty (Δ), REJECT.

This accepts e.g. a, aab, aaab, aaabb and rejects ab, b, aabb.

Q.4 L1 = (a + b)b(a + b)* = words whose second letter is b; L2 = b(a + b)* = words whose first letter is b. Build FA1 and FA2, then apply the product construction (state pairs (x, y), final when both components are final). The result accepts words beginning with bb, i.e. L1 ∩ L2 = bb(a + b)*:

Stateab
→ q0deadq1
q1deadq2
q2 (final)q2q2
deaddeaddead

Q.5 Properties of regular languages. Closure: regular languages are closed under union, concatenation, Kleene star, complement, intersection, difference, reversal and homomorphism. Decision properties (all decidable): membership (run the DFA), emptiness (is a final state reachable?), finiteness (is there a reachable cycle on a path to a final state?) and equivalence (minimise both DFAs and compare, or check the symmetric difference is empty).

Q.6 P and NP. P is the class of decision problems solvable in polynomial time by a deterministic machine (e.g. sorting, shortest path). NP is the class whose solutions can be verified in polynomial time (equivalently, solved by a non-deterministic machine in polynomial time). A problem is NP-complete if it is in NP and every NP problem reduces to it in polynomial time – e.g. SAT (Cook–Levin theorem), 3-SAT, vertex cover, travelling salesman (decision version). Implication: a polynomial algorithm for any NP-complete problem would prove P = NP; since none is known, we use approximation and heuristic algorithms, and much of cryptography relies on such problems being hard.

Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.