Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

(a) Distinguish between a Deterministic Finite Automaton (DFA) and a Non-deterministic Finite Automaton (NFA) with respect to their transition functions and computational power. (4)

(b) Consider the NFA MM over the alphabet Σ={0,1}\Sigma = \{0,1\} with start state q0q_0, accepting state q2q_2, and the following transitions: δ(q0,0)={q0,q1}\delta(q_0,0)=\{q_0,q_1\}, δ(q0,1)={q0}\delta(q_0,1)=\{q_0\}, δ(q1,1)={q2}\delta(q_1,1)=\{q_2\}. Convert MM into an equivalent DFA using the subset construction method, showing the resulting state table and the corresponding state diagram. (8)

(a) DFA vs NFA (4 marks)

AspectDFANFA
Transition functionδ:Q×ΣQ\delta : Q \times \Sigma \to Q — exactly one next state for each (state, symbol) pair.δ:Q×(Σ{ε})2Q\delta : Q \times (\Sigma \cup \{\varepsilon\}) \to 2^Q — a set of next states (possibly empty); may include ε\varepsilon-moves.
DeterminismNo choice; computation is a single path.Multiple choices; computation is a tree of paths.
AcceptanceUnique run; accept if it ends in a final state.Accept if at least one run ends in a final state.
ε\varepsilon-movesNot allowed.Allowed.

Computational power: DFA and NFA are equivalent — they recognize exactly the same class of languages (the regular languages). Every NFA can be converted to an equivalent DFA by subset construction. NFAs are often more compact (an nn-state NFA may need up to 2n2^n DFA states), but they accept no language a DFA cannot.

(b) Subset construction of MM (8 marks)

NFA: states {q0,q1,q2}\{q_0,q_1,q_2\}, start q0q_0, accept q2q_2. δ(q0,0)={q0,q1}\delta(q_0,0)=\{q_0,q_1\}, δ(q0,1)={q0}\delta(q_0,1)=\{q_0\}, δ(q1,1)={q2}\delta(q_1,1)=\{q_2\}. (All other moves ==\emptyset; no ε\varepsilon-moves.)

Start DFA state ={q0}=\{q_0\}. Compute reachable subsets:

DFA stateon 0on 1
{q0}\{q_0\}{q0,q1}\{q_0,q_1\}{q0}\{q_0\}
{q0,q1}\{q_0,q_1\}{q0,q1}\{q_0,q_1\}{q0,q2}\{q_0,q_2\}
{q0,q2}\{q_0,q_2\}{q0,q1}\{q_0,q_1\}{q0}\{q_0\}
  • on 0 from {q0,q1}\{q_0,q_1\}: δ(q0,0)δ(q1,0)={q0,q1}={q0,q1}\delta(q_0,0)\cup\delta(q_1,0)=\{q_0,q_1\}\cup\emptyset=\{q_0,q_1\}.
  • on 1 from {q0,q1}\{q_0,q_1\}: {q0}{q2}={q0,q2}\{q_0\}\cup\{q_2\}=\{q_0,q_2\}.
  • on 1 from {q0,q2}\{q_0,q_2\}: {q0}={q0}\{q_0\}\cup\emptyset=\{q_0\}.

Renaming: A={q0}A=\{q_0\} (start), B={q0,q1}B=\{q_0,q_1\}, C={q0,q2}C=\{q_0,q_2\} (accepting, since it contains q2q_2).

State01Accept?
A\to ABBAAno
BBBBCCno
C*CBBAAyes

State diagram (described): Start at AA. AA loops on 11 and goes to BB on 00. BB loops on 00 and goes to CC on 11. CC (double circle, accepting) goes to BB on 00 and back to AA on 11.

The DFA accepts exactly those strings containing the substring 01 (the NFA's condition for reaching q2q_2), which matches the original NFA.

finite-automatadfa-nfasubset-construction
2long12 marks

(a) Define a Context-Free Grammar (CFG) formally as a 4-tuple. Show that the grammar with productions EE+EEE(E)idE \rightarrow E + E \mid E * E \mid (E) \mid \text{id} is ambiguous by giving two distinct parse trees for the string id+idid\text{id} + \text{id} * \text{id}. (6)

(b) Construct a Pushdown Automaton (PDA) that accepts the language L={anbnn1}L = \{ a^n b^n \mid n \geq 1 \} by final state. Clearly specify the transition function and trace the acceptance of the string aabbaabb. (6)

(a) CFG definition and ambiguity (6 marks)

A Context-Free Grammar is a 4-tuple G=(V,T,P,S)G = (V, T, P, S) where:

  • VV = finite set of variables (non-terminals),
  • TT = finite set of terminals, VT=V \cap T = \emptyset,
  • PP = finite set of productions of the form AαA \to \alpha with AVA \in V and α(VT)\alpha \in (V \cup T)^*,
  • SVS \in V = the start symbol.

Ambiguity: A grammar is ambiguous if some string has two or more distinct parse trees (equivalently, two distinct leftmost derivations).

For EE+EEE(E)idE \to E+E \mid E*E \mid (E) \mid \text{id} and the string id+idid\text{id}+\text{id}*\text{id}:

Parse tree 1+ applied last (groups as id+(idid)\text{id}+(\text{id}*\text{id})):

        E
      / | \
     E  +  E
     |    /|\
    id   E * E
         |   |
        id  id

Parse tree 2* applied last (groups as (id+id)id(\text{id}+\text{id})*\text{id}):

        E
      / | \
     E  *  E
   / |\    |
  E + E   id
  |   |
 id  id

Two different parse trees for the same string \Rightarrow the grammar is ambiguous.

(b) PDA for L={anbnn1}L=\{a^n b^n \mid n\ge 1\} by final state (6 marks)

PDA P=(Q,Σ,Γ,δ,q0,Z0,F)P=(Q,\Sigma,\Gamma,\delta,q_0,Z_0,F) with Q={q0,q1,q2}Q=\{q_0,q_1,q_2\}, Σ={a,b}\Sigma=\{a,b\}, Γ={Z0,A}\Gamma=\{Z_0,A\}, start q0q_0, F={q2}F=\{q_2\}. Idea: push one AA per aa, pop one AA per bb; accept when stack returns to Z0Z_0 after at least one matched pair.

Transitions (form δ(state,input,top)=(state,push)\delta(\text{state},\text{input},\text{top})=(\text{state},\text{push})):

  1. δ(q0,a,Z0)=(q0,AZ0)\delta(q_0,a,Z_0)=(q_0,AZ_0) — first aa.
  2. δ(q0,a,A)=(q0,AA)\delta(q_0,a,A)=(q_0,AA) — subsequent aa's.
  3. δ(q0,b,A)=(q1,ε)\delta(q_0,b,A)=(q_1,\varepsilon) — first bb, start matching.
  4. δ(q1,b,A)=(q1,ε)\delta(q_1,b,A)=(q_1,\varepsilon) — match remaining bb's.
  5. δ(q1,ε,Z0)=(q2,Z0)\delta(q_1,\varepsilon,Z_0)=(q_2,Z_0) — stack empty (of AA's) \Rightarrow accept.

Trace on aabb (config = (state, remaining input, stack), top on left):

StepStateInput leftStackRule
0q0q_0aabbaabbZ0Z_0start
1q0q_0abbabbAZ0AZ_0(1)
2q0q_0bbbbAAZ0AAZ_0(2)
3q1q_1bbAZ0AZ_0(3)
4q1q_1ε\varepsilonZ0Z_0(4)
5q2q_2ε\varepsilonZ0Z_0(5)

Input consumed and PDA is in final state q2q_2 \Rightarrow aabb is accepted.

context-free-grammarambiguitypushdown-automata
3long12 marks

(a) Design a Turing Machine that accepts the language L={w{a,b}w contains an equal number of a’s and b’s}L = \{ w \in \{a,b\}^* \mid w \text{ contains an equal number of } a\text{'s and } b\text{'s} \}. Give the transition table and explain the working of your machine on the input abbaabba. (8)

(b) State the Halting Problem and prove that it is undecidable. (4)

(a) Turing Machine for equal aa's and bb's (8 marks)

Idea: Repeatedly scan the tape, mark one unmatched aa (as XX) and one unmatched bb (as YY) per pass, crossing them off. If the tape becomes all XX/YY/blank (no unmatched aa or bb remains), accept. The empty string is accepted.

States: q0q_0 (find an aa), q1q_1 (move right seeking a bb), q2q_2 (move left to start), qaccq_{acc}, qrejq_{rej}. Symbols a,b,X,Y,a,b,X,Y,\sqcup (X,YX,Y = crossed-out a,ba,b).

StateaabbXXYY\sqcup
q0q_0(q1,X,R)(q_1,X,R)(q3,Y,R)(q_3,Y,R)(q0,X,R)(q_0,X,R)(q0,Y,R)(q_0,Y,R)(qacc,,)(q_{acc},\sqcup,-)
q1q_1(q1,a,R)(q_1,a,R)(q2,Y,L)(q_2,Y,L)(q1,X,R)(q_1,X,R)(q1,Y,R)(q_1,Y,R)(qrej,,)(q_{rej},\sqcup,-)
q3q_3(q2,X,L)(q_2,X,L)(q3,b,R)(q_3,b,R)(q3,X,R)(q_3,X,R)(q3,Y,R)(q_3,Y,R)(qrej,,)(q_{rej},\sqcup,-)
q2q_2(q2,a,L)(q_2,a,L)(q2,b,L)(q_2,b,L)(q2,X,L)(q_2,X,L)(q2,Y,L)(q_2,Y,L)(q0,,R)(q_0,\sqcup,R)

Working: q0q_0 marks the leftmost unmatched aa as XX then in q1q_1 searches right for a bb to mark as YY; or if it first meets a bb it marks it YY and in q3q_3 searches for a matching aa. q2q_2 rewinds to the left end and re-enters q0q_0. When q0q_0 scans the whole tape and reaches \sqcup with no unmatched aa or bb, it accepts.

Run on abba:

  1. q0q_0 at a \to write XX, go q1q_1 right: Xbba.
  2. q1q_1 meets first b \to write YY, go q2q_2 left: XYba.
  3. q2q_2 rewinds to left end, re-enters q0q_0.
  4. q0q_0 skips X,YX,Y, meets b \to write YY, go q3q_3 right: XYYa.
  5. q3q_3 meets a \to write XX, go q2q_2 left: XYYX.
  6. q2q_2 rewinds, q0q_0 scans XYYX then \sqcup: no unmatched symbol \Rightarrow accept. (abba has 2 aa's and 2 bb's.)

(b) Halting Problem and undecidability (4 marks)

Halting Problem: Given the description M\langle M\rangle of a Turing machine MM and an input ww, decide whether MM halts on ww. Formally HALT={M,wM halts on w}HALT=\{\langle M,w\rangle \mid M \text{ halts on } w\}.

Proof of undecidability (diagonalization): Suppose a TM HH decides HALTHALT: H(M,w)H(\langle M,w\rangle) accepts if MM halts on ww, rejects otherwise. Build a TM DD that, on input M\langle M\rangle:

  • runs H(M,M)H(\langle M,\langle M\rangle\rangle);
  • if HH says "halts," then DD loops forever;
  • if HH says "does not halt," then DD halts.

Now run DD on its own description D\langle D\rangle:

  • If DD halts on D\langle D\rangle, then HH reported "halts," so DD loops — contradiction.
  • If DD does not halt on D\langle D\rangle, then HH reported "does not halt," so DD halts — contradiction.

Both cases are contradictory, so HH cannot exist. Therefore the Halting Problem is undecidable. \blacksquare

turing-machinedecidabilityhalting-problem
4long12 marks

(a) State the rules for constructing regular expressions and write a regular expression over Σ={0,1}\Sigma = \{0,1\} for the language of all strings that contain at least two consecutive 00's and end with a 11. (5)

(b) State the Pumping Lemma for regular languages and use it to prove that the language L={anbnn0}L = \{ a^n b^n \mid n \geq 0 \} is not regular. (7)

(a) Regular-expression rules + construction (5 marks)

Inductive rules for regular expressions over alphabet Σ\Sigma:

  1. \emptyset is a RE (denotes {}\{\}), ε\varepsilon is a RE (denotes {ε}\{\varepsilon\}), and each aΣa\in\Sigma is a RE (denotes {a}\{a\}). (Basis)
  2. If rr and ss are REs, then so are: union rsr\mid s, concatenation rsrs, Kleene star rr^*, and parenthesization (r)(r). (Induction)
  3. Nothing else is a RE. Precedence: >concatenation>* > \text{concatenation} > \mid.

Required language: all strings over {0,1}\{0,1\} that contain at least two consecutive 00's (substring 00) and end with 1.

r=(01)00(01)1r = (0\mid 1)^*\,00\,(0\mid 1)^*\,1

This forces an occurrence of 00 somewhere, allows any symbols around it, and ends in 1. (Equivalent forms are acceptable.)

(b) Pumping Lemma and non-regularity of L={anbnn0}L=\{a^n b^n\mid n\ge0\} (7 marks)

Pumping Lemma (regular languages): If LL is regular, there exists a constant p1p\ge1 (the pumping length) such that every string wLw\in L with wp|w|\ge p can be written w=xyzw=xyz with:

  1. y1|y|\ge1,
  2. xyp|xy|\le p,
  3. xyizLxy^iz\in L for all i0i\ge0.

Proof that L={anbn}L=\{a^n b^n\} is not regular (by contradiction):

Assume LL is regular with pumping length pp. Choose w=apbpLw=a^p b^p \in L, w=2pp|w|=2p\ge p. By the lemma, w=xyzw=xyz with xyp|xy|\le p and y1|y|\ge1.

Since xyp|xy|\le p, the first pp symbols of ww are all aa's, so xx and yy consist only of aa's. Write y=aky=a^k with 1kp1\le k\le p.

Pump with i=2i=2: xy2z=ap+kbpxy^2z = a^{p+k}\,b^{p}. This has p+kp+k aa's but only pp bb's, and since k1k\ge1 the counts differ, so xy2zLxy^2z \notin L.

This contradicts condition (3) of the pumping lemma. Hence L={anbnn0}L=\{a^n b^n\mid n\ge0\} is not regular. \blacksquare

regular-expressionspumping-lemmaregular-languages
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
5short7 marks

Design a DFA over the alphabet Σ={0,1}\Sigma = \{0,1\} that accepts all strings in which the number represented by the binary string is divisible by 33 (read most significant bit first). Draw the state diagram and briefly justify each state.

DFA for binary numbers divisible by 3 (MSB first)

Idea: Track the value of the prefix read so far modulo 3. Reading a bit bb updates the running value vv to 2v+b2v+b, so the residue updates as r(2r+b)mod3r \to (2r+b)\bmod 3. Three states represent the three possible remainders.

States: q0q_0 (remainder 0, start and accepting), q1q_1 (remainder 1), q2q_2 (remainder 2).

Transition table (using 2r+bmod32r+b\bmod 3):

State (rem)on 0on 1
q0\to *q_0 (0)q0q_0q1q_1
q1q_1 (1)q2q_2q0q_0
q2q_2 (2)q1q_1q2q_2

Derivations: from q1q_1 on 0: (21+0)mod3=2q2(2\cdot1+0)\bmod3=2\to q_2; on 1: (21+1)mod3=0q0(2\cdot1+1)\bmod3=0\to q_0. From q2q_2 on 0: (4)mod3=1q1(4)\bmod3=1\to q_1; on 1: (5)mod3=2q2(5)\bmod3=2\to q_2. From q0q_0 on 0: 0q00\to q_0; on 1: 1q11\to q_1.

State diagram (described): Three states q0,q1,q2q_0,q_1,q_2. q0q_0 is start and double-circled (accept). Edges as in the table. The empty string and 0 map to q0q_0 (value 0, divisible by 3); e.g. 110 (=6) traces q0q1q0q0q_0\to q_1\to q_0\to q_0, ending accepting.

Justification of states: Each state is the equivalence class of all prefixes whose value \equiv that remainder mod 3; only the remainder matters for future divisibility, so exactly 3 states suffice, and acceptance is exactly remainder 0.

dfa-designfinite-automata
6short7 marks

Convert the regular expression (ab)ab(a \mid b)^* ab into an equivalent NFA with epsilon-transitions using Thompson's construction. Show each step of the construction.

Thompson's construction for (ab)ab(a\mid b)^* ab

Thompson's construction builds an ε\varepsilon-NFA inductively, one operator at a time; each sub-NFA has exactly one start and one accept state.

Step 1 — atoms aa and bb:

  • N(a)N(a): s1af1s_1 \xrightarrow{a} f_1.
  • N(b)N(b): s2bf2s_2 \xrightarrow{b} f_2.

Step 2 — union aba\mid b: add new start s3s_3 and accept f3f_3:

  • s3εs1s_3 \xrightarrow{\varepsilon} s_1, s3εs2s_3 \xrightarrow{\varepsilon} s_2 (choose a branch),
  • f1εf3f_1 \xrightarrow{\varepsilon} f_3, f2εf3f_2 \xrightarrow{\varepsilon} f_3 (rejoin).

Step 3 — Kleene star (ab)(a\mid b)^*: add new start s4s_4 and accept f4f_4:

  • s4εs3s_4 \xrightarrow{\varepsilon} s_3 (enter loop body once),
  • s4εf4s_4 \xrightarrow{\varepsilon} f_4 (skip — accept empty),
  • f3εs3f_3 \xrightarrow{\varepsilon} s_3 (repeat),
  • f3εf4f_3 \xrightarrow{\varepsilon} f_4 (exit).

Step 4 — concatenation with aa then bb:

  • Atom N(a)N(a'): s5af5s_5 \xrightarrow{a} f_5; atom N(b)N(b'): s6bf6s_6 \xrightarrow{b} f_6.
  • Concatenate the star NFA, then aa, then bb by linking accept-to-start with ε\varepsilon (or by merging):
    • f4εs5f_4 \xrightarrow{\varepsilon} s_5,
    • f5εs6f_5 \xrightarrow{\varepsilon} s_6.

Final ε\varepsilon-NFA: start state =s4= s_4, single accept state =f6= f_6.

             ε        ε  a  ε
 s4 ---ε---> s3 region (a|b)* ---ε---> f4 ---ε---> s5 --a--> f5 ---ε---> s6 --b--> f6 (accept)
  \
   ---ε--> f4   (skip loop)

Where the (ab)(a\mid b) block inside the star is: s3ε{s1,s2}s_3\xrightarrow{\varepsilon}\{s_1,s_2\}, s1af1s_1\xrightarrow{a}f_1, s2bf2s_2\xrightarrow{b}f_2, f1,f2εf3f_1,f_2\xrightarrow{\varepsilon}f_3, with the star back-edge f3εs3f_3\xrightarrow{\varepsilon}s_3 and exit f3εf4f_3\xrightarrow{\varepsilon}f_4.

The resulting NFA accepts any number of aa/bb symbols (the star) followed by the literal ab.

regular-expressionsfinite-automata
7short6 marks

Convert the following context-free grammar into Chomsky Normal Form (CNF):

SASAaBS \rightarrow ASA \mid aB

ABSA \rightarrow B \mid S

BbεB \rightarrow b \mid \varepsilon

Convert to Chomsky Normal Form

Grammar: SASAaBS\to ASA\mid aB, ABSA\to B\mid S, BbεB\to b\mid\varepsilon.

Step 1 — add new start symbol S0S_0: S0SS_0\to S.

Step 2 — remove ε\varepsilon-productions. Nullable: BB (from BεB\to\varepsilon), and AA (since ABA\to B). Remove BεB\to\varepsilon and add versions of productions with nullable symbols omitted.

  • SASAS\to ASA gives (drop each nullable AA): ASA, SA, AS, SASA,\ SA,\ AS,\ S.
  • SaBS\to aB gives: aB, aaB,\ a.
  • ABA\to B stays (but BB now non-nullable form); ASA\to S stays. Remove AεA\to\varepsilon if introduced — AA was nullable only via BB, so no AεA\to\varepsilon unit.
  • BbB\to b stays.

Now: S0SS_0\to S; SASASAASSaBaS\to ASA\mid SA\mid AS\mid S\mid aB\mid a; ABSA\to B\mid S; BbB\to b.

Step 3 — remove unit productions. Unit pairs: SSS\to S (drop, trivial), S0SS_0\to S, ABA\to B, ASA\to S.

  • S0SS_0\to S: S0ASASAASaBaS_0\to ASA\mid SA\mid AS\mid aB\mid a.
  • ABA\to B: AbA\to b. ASA\to S: AASASAASaBaA\to ASA\mid SA\mid AS\mid aB\mid a.
  • Drop SSS\to S.

Now: S0ASASAASaBaS_0\to ASA\mid SA\mid AS\mid aB\mid a SASASAASaBaS\to ASA\mid SA\mid AS\mid aB\mid a AbASASAASaBaA\to b\mid ASA\mid SA\mid AS\mid aB\mid a BbB\to b

Step 4 — replace terminals in long bodies. Introduce TaaT_a\to a. Replace aa in aBaB: aBTaBaB\to T_aB.

Step 5 — break bodies longer than 2. ASAASA has length 3; introduce CSAC\to SA, so ASAACASA\to A\,C where CSAC\to SA.

Resulting CNF grammar:

S0ACSAASTaBaSACSAASTaBaAACSAASTaBabBbCSATaa\begin{aligned} S_0 &\to AC \mid SA \mid AS \mid T_aB \mid a\\ S &\to AC \mid SA \mid AS \mid T_aB \mid a\\ A &\to AC \mid SA \mid AS \mid T_aB \mid a \mid b\\ B &\to b\\ C &\to SA\\ T_a &\to a \end{aligned}

Every production is now of the form XYZX\to YZ (two variables) or XaX\to a (single terminal), i.e. valid CNF.

context-free-grammarchomsky-normal-form
8short7 marks

Differentiate between deterministic and non-deterministic pushdown automata. Construct a PDA equivalent to the grammar SaSbεS \rightarrow aSb \mid \varepsilon and explain why this language cannot be accepted by any finite automaton.

Deterministic vs Non-deterministic PDA

AspectDPDANPDA (NDPDA)
TransitionAt most one applicable move per (state, input, stack-top); ε\varepsilon-moves restricted so no choice.May have several applicable moves; explores all in parallel.
PowerAccept exactly the deterministic CFLs (a proper subset).Accept all context-free languages.
Example gapCannot accept {wwR}\{ww^R\} (even-length palindromes).Can accept {wwR}\{ww^R\}.

So NPDAs are strictly more powerful than DPDAs (unlike finite automata, where NFA = DFA). Every DPDA language is context-free, but not every CFL is a DPDA language.

PDA equivalent to SaSbεS\to aSb\mid\varepsilon

This grammar generates L={anbnn0}L=\{a^n b^n\mid n\ge0\}. Construct a PDA (acceptance by empty stack), P=({q},{a,b},{Z0,A},δ,q,Z0)P=(\{q\},\{a,b\},\{Z_0,A\},\delta,q,Z_0):

  1. δ(q,a,Z0)=(q,AZ0)\delta(q,a,Z_0)=(q,AZ_0) — push AA on first aa.
  2. δ(q,a,A)=(q,AA)\delta(q,a,A)=(q,AA) — push AA for each further aa.
  3. δ(q,b,A)=(q,ε)\delta(q,b,A)=(q,\varepsilon) — pop one AA per bb.
  4. δ(q,ε,Z0)=(q,ε)\delta(q,\varepsilon,Z_0)=(q,\varepsilon) — empty stack to accept (handles n=0n=0 and the matched case).

Trace aabb: (q,aabb,Z0)(q,abb,AZ0)(q,bb,AAZ0)(q,b,AZ0)(q,ε,Z0)(q,ε,ε)(q,aabb,Z_0)\vdash(q,abb,AZ_0)\vdash(q,bb,AAZ_0)\vdash(q,b,AZ_0)\vdash(q,\varepsilon,Z_0)\vdash(q,\varepsilon,\varepsilon) — accepted. The empty string is accepted directly by rule 4.

Why no finite automaton accepts LL

L={anbn}L=\{a^n b^n\} requires counting an unbounded number of aa's to match the same number of bb's. A finite automaton has only finitely many states and no memory (no stack), so it cannot distinguish among the infinitely many prefixes ana^n. By the pumping lemma for regular languages, pumping apbpa^p b^p unbalances the counts, proving LL is not regular. The PDA's stack supplies exactly the unbounded counting memory an FA lacks.

pushdown-automatacfg-to-pda
9short6 marks

(a) Explain the formal definition of a standard (single-tape) Turing Machine as a 7-tuple. (3)

(b) Briefly describe a multi-tape Turing Machine and state whether it is more powerful than a single-tape Turing Machine, justifying your answer. (3)

(a) Standard Turing Machine as a 7-tuple (3 marks)

A (deterministic, single-tape) Turing Machine is M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M=(Q,\Sigma,\Gamma,\delta,q_0,q_{accept},q_{reject}) where:

  • QQ = finite set of states;
  • Σ\Sigma = input alphabet, with blank Σ\sqcup\notin\Sigma;
  • Γ\Gamma = tape alphabet, ΣΓ\Sigma\subseteq\Gamma and Γ\sqcup\in\Gamma;
  • δ:Q×ΓQ×Γ×{L,R}\delta : Q\times\Gamma \to Q\times\Gamma\times\{L,R\} = transition function (read symbol, write symbol, move head Left/Right);
  • q0Qq_0\in Q = start state;
  • qacceptQq_{accept}\in Q = accept state;
  • qrejectQq_{reject}\in Q = reject state (qacceptqrejectq_{accept}\neq q_{reject}).

(b) Multi-tape Turing Machine (3 marks)

A multi-tape TM has k2k\ge2 tapes, each with its own independent read/write head. Its transition function reads the kk symbols under the heads at once and writes kk symbols, moving each head independently:

δ:Q×ΓkQ×Γk×{L,R,S}k.\delta : Q\times\Gamma^k \to Q\times\Gamma^k\times\{L,R,S\}^k.

The input starts on tape 1; the other tapes start blank and serve as scratch memory.

Is it more powerful? No — it is equally powerful in terms of the languages it recognizes. Every multi-tape TM can be simulated by a single-tape TM (store the kk tapes' contents interleaved on one tape, marking head positions, and sweep the tape to simulate each step). Both models recognize exactly the recursively enumerable languages, confirming the Church–Turing thesis. The only difference is efficiency: a tt-step multi-tape computation costs O(t2)O(t^2) steps on a single tape, so multi-tape gives a polynomial speedup but no extra computational power.

turing-machinevariants
10short6 marks

Differentiate between recursive (decidable) and recursively enumerable languages with the help of suitable examples. Explain the relationship between the two classes using a closure-under-complement argument.

Recursive vs Recursively Enumerable languages

Recursive (decidable) language: A language LL is recursive if there is a Turing machine that halts on every input and decides membership — it accepts every wLw\in L and rejects (halts) every wLw\notin L. The machine is a total decider.

Recursively enumerable (RE / Turing-recognizable): LL is RE if there is a TM that accepts every wLw\in L, but on wLw\notin L it may reject or run forever (it need not halt). The machine is a recognizer, not necessarily a decider.

RecursiveRecursively Enumerable
Halts on membersyes (accept)yes (accept)
Halts on non-membersyes (reject)not guaranteed (may loop)
Decision procedureexistsnot guaranteed

Examples:

  • Recursive: {anbncn}\{a^n b^n c^n\}, or any CFL, or {MM\{\langle M\rangle \mid M has 5\le 5 states}\} — membership is always decidable.
  • RE but not recursive: ATM={M,wMA_{TM}=\{\langle M,w\rangle \mid M accepts w}w\} (the acceptance/halting problem) — recognizable by a universal TM that simulates MM on ww, but undecidable.

Relationship via closure under complement

  • Every recursive language is RE (a decider is also a recognizer): RecursiveRE\text{Recursive}\subseteq\text{RE}.
  • Recursive languages are closed under complement: if MM decides LL, swap its accept/reject states to decide L\overline{L} (it still always halts).
  • Key theorem: LL is recursive iff both LL and L\overline{L} are RE. Run recognizers for LL and L\overline{L} in parallel; on any input exactly one accepts, giving a decider that always halts.
  • RE is not closed under complement. Since ATMA_{TM} is RE but undecidable, its complement ATM\overline{A_{TM}} cannot be RE — otherwise ATMA_{TM} would be recursive. Thus RecursiveRE\text{Recursive}\subsetneq\text{RE}, and ATM\overline{A_{TM}} is an example of a language that is not even RE.
decidabilityrecursive-recursively-enumerable
11short7 marks

(a) Define the complexity classes PP and NPNP and explain what is meant by an NPNP-complete problem. (4)

(b) State the significance of the PP versus NPNP question and give one example of a well-known NPNP-complete problem. (3)

(a) P, NP, and NP-completeness (4 marks)

  • PP (Polynomial time): the class of decision problems solvable by a deterministic Turing machine in time O(nk)O(n^k) for some constant kk, where nn is the input size. These are the problems regarded as efficiently solvable.
  • NPNP (Non-deterministic Polynomial time): the class of decision problems for which a proposed solution (certificate) can be verified by a deterministic TM in polynomial time; equivalently, solvable by a non-deterministic TM in polynomial time. Clearly PNPP\subseteq NP.
  • NPNP-complete: a problem XX is NP-complete if (1) XNPX\in NP, and (2) every problem in NPNP reduces to XX in polynomial time (XX is NP-hard). NP-complete problems are the "hardest" in NPNP: if any one of them is in PP, then P=NPP=NP.

(b) Significance of P vs NP, and an example (3 marks)

Significance: The P=?NPP\overset{?}{=}NP question asks whether every problem whose solution can be verified quickly can also be solved quickly. It is one of the seven Millennium Prize Problems. If P=NPP=NP, thousands of important optimization, scheduling, and cryptographic-breaking problems would have efficient algorithms; if PNPP\neq NP (widely believed), no polynomial-time algorithm exists for NP-complete problems, which underpins the security of modern cryptography. It remains open.

Example of an NP-complete problem: The Boolean Satisfiability problem (SAT) — deciding whether a Boolean formula has a satisfying assignment — was the first proven NP-complete problem (Cook–Levin theorem). Other examples: the Travelling Salesman (decision) problem, 3-SAT, Vertex Cover, Hamiltonian Cycle, and Subset Sum.

computational-complexityp-npnp-completeness
12short6 marks

Using the principle of mathematical induction, prove that for every integer n1n \geq 1, the number of distinct strings of length nn over an alphabet Σ\Sigma with Σ=k|\Sigma| = k is exactly knk^n. Clearly state the basis and the inductive step.

Proof by induction: number of strings of length nn over Σ=k|\Sigma|=k is knk^n

Let P(n)P(n) be the statement: the number of distinct strings of length nn over an alphabet Σ\Sigma with Σ=k|\Sigma|=k equals knk^n.

Basis (n=1n=1): A string of length 1 is just a single symbol from Σ\Sigma. There are exactly Σ=k|\Sigma|=k choices, and k1=kk^1=k. So P(1)P(1) holds.

(Optional stronger basis n=0n=0: there is exactly one string of length 0, the empty string ε\varepsilon, and k0=1k^0=1, so it also holds.)

Inductive hypothesis: Assume P(n)P(n) is true for some integer n1n\ge1, i.e. there are exactly knk^n distinct strings of length nn.

Inductive step — show P(n+1)P(n+1): Every string of length n+1n+1 is obtained uniquely by taking a string ww of length nn and appending one symbol aΣa\in\Sigma to its end, giving wawa.

  • By the inductive hypothesis there are knk^n choices for ww.
  • There are kk choices for the appended symbol aa.
  • Different (w,a)(w,a) pairs produce different strings, and every length-(n+1)(n+1) string arises from exactly one such pair.

By the multiplication (product) rule, the number of strings of length n+1n+1 is

knk=kn+1.k^n \cdot k = k^{n+1}.

Thus P(n+1)P(n+1) holds.

Conclusion: By the principle of mathematical induction, P(n)P(n) holds for every integer n1n\ge1: the number of distinct strings of length nn over an alphabet of size kk is exactly knk^n. \blacksquare

mathematical-inductionformal-proofs

Frequently asked questions

Where can I find the BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) question paper 2079?
The full BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 2079 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
Does the Theory of Computation (PU, CMP 264) 2079 paper come with solutions?
Yes. Every question on this Theory of Computation (PU, CMP 264) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 2079 paper?
The BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 2079 paper carries 100 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this Theory of Computation (PU, CMP 264) past paper free?
Yes — reading and attempting this Theory of Computation (PU, CMP 264) past paper on Kekkei is completely free.