Theory of Computation
Time limit: 90 minutes Total marks: 60 Instructions: Answer all three questions. Rigour, precision of definitions, and completeness of proofs are assessed. You may use standard closure results if stated explicitly.
Question 1 — Automata, Subset Construction & Non-Regularity (20 marks)
Consider the language over the alphabet :
(a) Design an NFA (with -transitions permitted but not required) accepting . Give it as a formal 5-tuple and draw its state diagram. (4 marks)
(b) Apply the subset construction to convert your NFA to a DFA. Show the reachable subset table and give the final DFA's state diagram. (6 marks)
(c) Write a regular expression for and justify (briefly) why it is equivalent to your automaton. (3 marks)
(d) Now define . Prove that is not regular using the pumping lemma. State the lemma precisely and justify your choice of pumped string. (7 marks)
Question 2 — Grammars, CNF & the CFL Pumping Lemma (20 marks)
(a) Give a context-free grammar generating . Show a leftmost derivation of and of . (5 marks)
(b) Convert the grammar into Chomsky Normal Form. Show every intermediate step (removal of , unit productions, terminals, long RHS). (7 marks)
(c) Prove that is not context-free using the pumping lemma for CFLs. State the lemma with pumping length and analyse all cases of the decomposition . (8 marks)
Question 3 — Computability, Reductions & Complexity (20 marks)
(a) State the Halting Problem as a language and prove it is undecidable by diagonalization. Make the contradiction machine explicit. (7 marks)
(b) State Rice's theorem precisely (semantic, non-trivial property). Use it to show that is undecidable, or explain precisely why Rice's theorem does not directly settle it — whichever is correct. (5 marks)
(c) Define a many-one (mapping) reduction . Prove: if and is decidable, then is decidable. State the contrapositive form used to prove undecidability. (4 marks)
(d) State what it means for a language to be NP-complete. Given that 3-SAT is NP-complete, outline the reduction : describe the graph construction and state (with brief justification) the correctness equivalence. (4 marks)
Answer keyMark scheme & solutions
Question 1
(a) (4 marks) NFA: , , start , . Idea: stay in (self-loop on ) guessing where starts; after , after , after then loop. Marks: correct states/start/final (2), transitions realizing "contains " (2).
(b) (6 marks) Subset construction from start :
| Subset | on | on |
|---|---|---|
Accepting DFA states = those containing : . Start . Marks: correct start & closure procedure (2), correct table (3), correct accepting set (1). (Once reached, all reachable subsets contain — a dead-accepting sink region, as expected for "contains substring.")
(c) (3 marks) . Justification: before and after matches arbitrary prefix/suffix; the literal forces the required substring — exactly the strings containing . Kleene's theorem guarantees RE ⇔ FA equivalence. Marks: RE (2), justification (1).
(d) (7 marks) Pumping lemma (regular): If is regular, s.t. every with can be written with (i) , (ii) , (iii) for all . (2 marks)
Assume regular with pumping length . Choose , . (1) By (i)–(ii), lies within the first symbols, all 's, so with , and is a prefix-block of the first . (2) Pump : . Now the count of leading 's is (since ), while the trailing block is still ; a member of requires the first and last blocks equal to the middle-count . Hence . (2) Contradiction ⇒ is not regular. (Deduct if wrong string chosen, e.g. one that pumps within a single equal block trivially.)
Question 2
(a) (5 marks) Grammar (union of two CFLs): Here gives (with free via ), gives (with free via ). (3 marks for correct grammar)
Leftmost derivation of (use , ): (1)
Leftmost derivation of (use , , wait need ; here ? : , so fails; use with , ): (1)
(b) (7 marks) . Step 1 — Nullable: is nullable. Add new start ; remove from : from removing nullable gives . So , . (2) Step 2 — Unit productions: replaced by 's bodies: . Keep only on start (allowed). (2) Step 3 — Terminals to variables: , . Rewrite: , . (1) Step 4 — Break long RHS ( length 3): introduce : , , , , . (2) This is CNF (each production: variable→two variables, or variable→terminal, plus ).
(c) (8 marks) Pumping lemma (CFL): if is context-free, s.t. every , , factors as with (i) , (ii) , (iii) for all . (2)
Take , . Since , the window spans at most two of the three symbol-blocks (it cannot touch both the -block and -block, which are apart). (2) Case analysis on pump (or ): (3)
- contains only 's and/or 's (no ): pumping changes and/or counts but -count stays ; equality of all three counts breaks.
- contains only 's and/or 's (no ): -count stays while others change — breaks.
- or straddles a boundary and contains two distinct letters: has letters out of order ( or ), leaving — not in . In every case , contradicting (iii). (1) Hence is not context-free.
Question 3
(a) (7 marks) . (1) Proof: suppose decider decides : accepts iff halts on , rejects otherwise (always halts). (1) Build on input : run ; if says " halts on ", then loops forever; if says "does not halt", then halts. (2) Now run on : (2)
- If halts on , then reported "halts", so by construction loops — contradiction.
- If loops on , then reported "does not halt", so halts — contradiction. Both cases contradictory ⇒ no such exists ⇒ undecidable. (1)
(b) (5 marks) Rice's theorem: Let be any property of the languages recognized by TMs (a semantic property: depends only on , not on 's encoding) that is non-trivial (some TM's language has , some doesn't). Then is undecidable. (2) Application: "" is a semantic property (depends only on ) and non-trivial (some machines recognize , others recognize ). Hence by Rice's theorem is undecidable. (3) (Note: ; Rice applies since the property is semantic & non-trivial — full credit for correctly invoking it. It is in fact co-recognizable but not decidable.)
(c) (4 marks) : there is a total computable with for all . (1.5) Proof: if decidable by and computable, then decide by: on , compute , run , and accept iff it accepts. This halts (both stages halt) and is correct by the reduction property. So decidable. (1.5) Contrapositive used for undecidability: if and is undecidable, then is undecidable. (1)
(d) (4 marks) NP-complete: is NP-complete if (1) and (2) every satisfies (polynomial-time many-one reduction). (1) : Given a 3-CNF with clauses, build graph : for each clause create 3 vertices, one per literal. Put an edge between two vertices iff they are in different clauses and their literals are not complementary (not and ). Set . (2) Correctness: satisfiable has a -clique. A satisfying assignment picks one true literal per clause; these literals are pairwise non-contradictory and in distinct clauses ⇒ pairwise adjacent ⇒ -clique. Conversely a clique of size must use exactly one vertex from each clause (edges only cross clauses) with mutually consistent literals, yielding a satisfying assignment. Construction is polynomial. (1)
[
{"claim":"Q1 NFA subset construction: transitions from B={q0,q1} on b give C={q0,q2}",
"code":"B={'q0','q1'}\ndelta={('q0','a'):{'q0','q1'},('q0','b'):{'q0'},('q1','b'):{'q2'}}\nres=set()\nfor s in B:\n res|=delta.get((s,'b'),set())\nresult = res=={'q0','q2'}"},
{"claim":"Q1(d) pumping: p=3 sample, pumping y=a^k in first block breaks a-count equality",
"code":"p=3; k=1\nfirst=p+k; middle_b=p; last=p\nresult = (first!=p) and (first!=last)"},
{"claim":"Q2 CNF: number of variables after conversion of S->aSb|eps is 5 (S0,S,C,A,B)",
"code":"vars={'S0','S','C','A','B'}\nresult = len(vars)==5"},
{"claim