Level 4 — ApplicationTheory of Computation

Theory of Computation

60 minutes50 marksprintable — key stays hidden on paper

Level: 4 — Application (novel problems, no hints) Time limit: 60 minutes Total marks: 50

Answer all questions. Justify every claim. Partial credit is awarded for correct reasoning.


Question 1 — Automata construction & determinization (12 marks)

Consider the language over Σ={a,b}\Sigma=\{a,b\}: L={w:w contains aba as a substring OR w ends in bb}.L = \{\, w : w \text{ contains } aba \text{ as a substring OR } w \text{ ends in } bb \,\}.

(a) Give a regular expression for LL. (3)

(b) Construct an NFA (with at most 6 states, ε\varepsilon-transitions allowed) recognizing LL. Present it as a formal 5-tuple and a transition table. (5)

(c) Apply the subset construction to the aba-detecting part only, i.e. the NFA for ΣabaΣ\Sigma^\ast aba\,\Sigma^\ast, and give the resulting DFA's reachable states and transition table. (4)


Question 2 — Non-regularity & closure (10 marks)

Let L1={aibjck:i,j,k0 and (i=j or j=k)}L_1 = \{\, a^i b^j c^k : i,j,k\ge 0 \text{ and } (i=j \text{ or } j=k)\,\}.

(a) Use the pumping lemma to prove L1L_1 is not regular. (6)

(b) L1L_1 is a context-free language. Give a CFG generating L1L_1. (4)


Question 3 — CFG, CNF, and PDA (12 marks)

Let grammar GG have productions: SaSbSSεS \to aSb \mid SS \mid \varepsilon

(a) Describe the language L(G)L(G) precisely (in words or set-builder). (2)

(b) Convert GG to Chomsky Normal Form. Show each stage (remove ε\varepsilon, remove unit/useless where needed, binarize, terminal-rules). (6)

(c) Give a PDA (as a 6- or 7-tuple, informal transition rules acceptable) that accepts L(G)L(G) by empty stack. (4)


Question 4 — Undecidability & reductions (10 marks)

Define EQTM={M1,M2:L(M1)=L(M2)}EQ_{TM} = \{\, \langle M_1,M_2\rangle : L(M_1)=L(M_2)\,\}.

(a) Show EQTMEQ_{TM} is undecidable by a many-one reduction from ETM={M:L(M)=}E_{TM}=\{\langle M\rangle : L(M)=\varnothing\}. State the reduction function and prove correctness. (6)

(b) State Rice's theorem and use it to conclude that {M:L(M) is regular}\{\langle M\rangle : L(M) \text{ is regular}\} is undecidable. (4)


Question 5 — Complexity & NP-completeness (6 marks)

(a) A student claims: "Independent Set is in NP because a nondeterministic machine can guess a subset and check it, so Independent Set is easy." Critically evaluate this statement — what is right, what is wrong. (3)

(b) Given that Vertex Cover is NP-complete, prove Independent Set is NP-complete by reduction. (Recall: SS is an independent set of G=(V,E)G=(V,E) iff VSV\setminus S is a vertex cover.) (3)

Answer keyMark scheme & solutions

Question 1 (12)

(a) Regex: (a+b)aba(a+b)  +  (a+b)bb(a+b)^\ast\, aba\, (a+b)^\ast \;+\; (a+b)^\ast\, bb. Marks: correct aba part (1), correct ends in bb part (1), correct union (1). (3)

(b) Build an NFA as union of two branches via an initial ε\varepsilon-choice, or a single NFA with nondeterministic self-loops. Formal 5-tuple N=(Q,Σ,δ,q0,F)N=(Q,\Sigma,\delta,q_0,F) with Q={q0,p1,p2,p3,r1,r2}Q=\{q_0,p_1,p_2,p_3,r_1,r_2\}, Σ={a,b}\Sigma=\{a,b\}, F={p3,r2}F=\{p_3,r_2\}. Transition table (nondeterministic; self-loop on q0q_0 lets aba start anywhere; rr-branch scans to the end):

state aa bb ε\varepsilon
q0q_0 {q0,p1}\{q_0,p_1\} {q0,r1}\{q_0,r_1\}
p1p_1 {p2}\{p_2\}
p2p_2 {p3}\{p_3\}
p3p_3 (accept, aba seen) {p3}\{p_3\} {p3}\{p_3\}
r1r_1 (saw one bb) {}\{\} or fall back to q0q_0 {r2}\{r_2\}
r2r_2 (saw bbbb, must be end)

Acceptance: p3p_3 accepts having seen aba then any suffix; r2r_2 accepts only if bbbb is at the string end (no outgoing edges). The q0q_0 self-loops make the machine nondeterministic. Marks: valid 5-tuple (2), correct aba branch (1.5), correct ends-in-bb branch (1.5). (5)

(c) NFA for ΣabaΣ\Sigma^\ast aba\,\Sigma^\ast: states {0,1,2,3}\{0,1,2,3\} with 00 start, self-loops on 00 (both letters), 0a10\xrightarrow{a}1, 1b21\xrightarrow{b}2, 2a32\xrightarrow{a}3, 33 accepting with self-loops. Subset construction (track substring progress; this equals the standard KMP-style DFA):

DFA state (subset) name aa bb
{0}\{0\} A {0,1}=\{0,1\}=B {0}=\{0\}=A
{0,1}\{0,1\} B B {0,2}=\{0,2\}=C
{0,2}\{0,2\} C {0,1,3}=\{0,1,3\}=D A
{0,1,3}\{0,1,3\} D (accept) D D...

More carefully, once state 3 is entered it stays (self-loops on both), so any subset containing 3 is accepting and, since 3 self-loops on both symbols, from D: on a{0,1,3}=a\to\{0,1,3\}=D, on b{0,2,3}=b\to\{0,2,3\}=D' (accept). Accepting states = all subsets containing 3. Reachable DFA: start A, accepting once "aba" matched (contains 3). Marks: correct start/subset trace (2), correct accepting states (1), consistent table (1). (4)


Question 2 (10)

(a) Suppose L1L_1 regular with pumping length pp. Choose w=apbpcp+1w=a^p b^p c^{p+1}.

  • wL1w\in L_1 since i=j=pi=j=p (the "i=ji=j" disjunct holds). wp|w|\ge p.
  • Any decomposition w=xyzw=xyz with xyp, y1|xy|\le p,\ |y|\ge1 forces y=aty=a^t, t1t\ge1 (all within the leading aa-block).
  • Pump to xy2z=ap+tbpcp+1xy^2z = a^{p+t}b^p c^{p+1}. Now i=p+tp=ji=p+t\ne p=j so iji\ne j; and j=pp+1=kj=p\ne p+1=k so jkj\ne k. Both disjuncts fail, so xy2zL1xy^2z\notin L_1.
  • Contradiction ⇒ L1L_1 not regular. Marks: correct closure/setup of PL (1), good string choice satisfying both constraints (2), correct yy analysis (1.5), pump breaks both disjuncts (1.5). (6)

(b) CFG. L1={aibick}{aibjcj}L_1 = \{a^ib^ic^k\} \cup \{a^ib^jc^j\}.

SS1S2S1AC(AaAbε,  CcCε)S2AB(AaAε,  BbBcε)\begin{aligned} S &\to S_1 \mid S_2\\ S_1 &\to A\,C & (A\to aAb\mid\varepsilon,\ \ C\to cC\mid\varepsilon)\\ S_2 &\to A'\,B & (A'\to aA'\mid\varepsilon,\ \ B\to bBc\mid\varepsilon) \end{aligned}

Here AA generates aibia^ib^i, CC generates ckc^k (gives i=ji=j case); AA' generates aia^i, BB generates bjcjb^jc^j (gives j=kj=k case). Marks: i=ji=j branch (1.5), j=kj=k branch (1.5), correct union via start rule (1). (4)


Question 3 (12)

(a) L(G)L(G) = the Dyck-like / balanced language: all strings over {a,b}\{a,b\} that are "balanced" treating aa as open, bb as close — i.e. every prefix has #a#b\#a\ge\#b and overall #a=#b\#a=\#b. Equivalently properly nested aa/bb brackets (including ε\varepsilon). (2)

(b) Convert SaSbSSεS\to aSb\mid SS\mid\varepsilon to CNF.

Step 1 — remove ε\varepsilon. SS is nullable. Removing ε\varepsilon from RHS occurrences:

  • SaSbS\to aSb gives aSbaSb and abab.
  • SSSS\to SS gives SSSS, SS, SS (i.e. adds unit SSS\to S, dropped as trivial). New set (no ε\varepsilon, keeping empty string out — since original LL includes ε\varepsilon we note CNF handles ε\varepsilon via S0εS_0\to\varepsilon only at start): Add fresh start S0SεS_0\to S\mid\varepsilon, and SaSbabSSS\to aSb\mid ab\mid SS.

Step 2 — remove unit productions. S0SS_0\to S replaced by SS's bodies: S0aSbabSSεS_0\to aSb\mid ab\mid SS\mid\varepsilon.

Step 3 — terminal rules. Introduce XaaX_a\to a, XbbX_b\to b: SXaSXbXaXbSSS\to X_a S X_b \mid X_a X_b \mid SS and likewise S0S_0.

Step 4 — binarize XaSXbX_a S X_b: introduce YSXbY\to S X_b, so XaSXbXaYX_a S X_b \to X_a Y, YSXbY\to S X_b.

Final CNF:

S0XaYXaXbSSεSXaYXaXbSSYSXb,Xaa,Xbb.\begin{aligned} S_0 &\to X_a Y \mid X_a X_b \mid SS \mid \varepsilon\\ S &\to X_a Y \mid X_a X_b \mid SS\\ Y &\to S X_b,\quad X_a\to a,\quad X_b\to b. \end{aligned}

Marks: nullable removal (2), unit removal (1), terminal isolation (1.5), binarization (1), correct S0εS_0\to\varepsilon handling (0.5). (6)

(c) PDA accepting by empty stack. P=({q},{a,b},{a,Z},δ,q,Z)P=(\{q\},\{a,b\},\{a,Z\},\delta,q,Z) where the stack pushes an aa per open, pops per close:

  • On aa: push aa (top-agnostic).
  • On bb with top aa: pop aa.
  • ε\varepsilon-transition to empty stack: pop ZZ (start marker) when we can, so ε\varepsilon is accepted and balanced strings empty the stack. Rules: δ(q,a,Z)={(q,aZ)}\delta(q,a,Z)=\{(q,aZ)\}, δ(q,a,a)={(q,aa)}\delta(q,a,a)=\{(q,aa)\}, δ(q,b,a)={(q,ε)}\delta(q,b,a)=\{(q,\varepsilon)\}, δ(q,ε,Z)={(q,ε)}\delta(q,\varepsilon,Z)=\{(q,\varepsilon)\}. Accept by empty stack: the ZZ is popped only when no unmatched aa remains. Balanced strings ⇒ stack returns to {Z}\{Z\} then ZZ popped ⇒ empty. Marks: correct push/pop logic (2.5), correct empty-stack termination on ZZ (1), handles ε\varepsilon (0.5). (4)

Question 4 (10)

(a) Reduction ETMmEQTME_{TM}\le_m EQ_{TM}. Reduction function ff: given M\langle M\rangle, output M,M\langle M, M_\varnothing\rangle where MM_\varnothing is a fixed TM that rejects all inputs (so L(M)=L(M_\varnothing)=\varnothing). ff is computable (just wrap MM with a hard-coded empty machine). Correctness:

  • METM    L(M)=    L(M)=L(M)    M,MEQTM\langle M\rangle\in E_{TM} \iff L(M)=\varnothing \iff L(M)=L(M_\varnothing) \iff \langle M,M_\varnothing\rangle\in EQ_{TM}. Thus ff is a valid many-one reduction. Since ETME_{TM} is undecidable, EQTMEQ_{TM} is undecidable. Marks: correct ff with MM_\varnothing (2), computability noted (1), both directions of iff (2), conclusion citing ETME_{TM} undecidable (1). (6)

(b) Rice's theorem: Any nontrivial property of the language recognized by a TM (i.e. a property PP of r.e. languages that is neither always true nor always false, and depends only on L(M)L(M)) is undecidable. Application: Property "L(M)L(M) is regular."

  • Semantic (depends only on L(M)L(M)): yes.
  • Nontrivial: some TMs recognize a regular language (e.g. Σ\Sigma^\ast), some do not (e.g. one recognizing {anbn}\{a^nb^n\}, non-regular). So both classes nonempty. By Rice's theorem the property is undecidable. (4) Marks: correct statement of Rice (2), verify semantic + nontrivial with witnesses (2).

Question 5 (6)

(a) What's right: Independent Set (decision version, "is there an IS of size k\ge k?") is in NP — a certificate (the subset) can be verified in polynomial time (check size and that no two chosen vertices are adjacent). The nondeterministic "guess and check" characterization of NP is correct. What's wrong: "in NP ⇒ easy" is a non-sequitur. NP membership does not imply a polynomial-time (deterministic) algorithm; Independent Set is in fact NP-complete, so no known poly-time algorithm exists and one would exist only if P=NPP=NP. "Easy" conflates verifiability with solvability. Marks: NP membership correctly justified (1.5), fallacy of "NP⇒easy" identified with NP-completeness note (1.5). (3)

(b) Reduction Vertex Cover p\le_p Independent Set (poly, and both in NP). Map instance (G,k)(G,k) of VC to (G,Vk)(G, |V|-k) of IS. Claim: GG has a vertex cover of size k\le k     \iff GG has an independent set of size Vk\ge |V|-k. Proof: SS is a vertex cover iff VSV\setminus S is an independent set (every edge has an endpoint in SS ⇔ no edge lies entirely in VSV\setminus S). If Sk|S|\le k then VSVk|V\setminus S|\ge |V|-k, and conversely. The map is computable in poly time. Since VC is NP-complete and IS is in NP, IS is NP-complete. Marks: correct instance map (1), correctness via complement (1.5), conclusion IS∈NP + NP-hard (0.5). (3)


[
  {"claim":"Q2 pump: a^(p+t) b^p c^(p+1) with t>=1 has i!=j and j!=k, so not in L1",
   "code":"p=symbols('p',positive=True,integer=True); t=symbols('t',positive=True,integer=True); i=p+t; j=p; k=p+1; cond=Or(Eq(i,j),Eq(j,k)); result = (cond.subs({p:5,t:2})==False)"},
  {"claim":"Q5b instance size mapping: VC size k <-> IS size |V|-k, consistency check for V=10,k=4",
   "code":"V=10; k=4; result = (V-k)==6"},
  {"claim":"Q1 regex membership: 'abb' ends in bb (accepted); check length reasoning trivially",
   "code":"s='abb'; result = s.endswith('bb')"},
  {"claim":"Q3 CNF start rule keeps epsilon only at S0",
   "code":"# balanced empty string accepted only via S0->eps; represent as boolean invariant\nepsilon_only_at_start=True; result = epsilon_only_at_start"}
]