Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

3 questions
1long16 marks

(a) Define a Non-deterministic Finite Automaton (NFA) formally as a 5-tuple and explain how it differs from a Deterministic Finite Automaton (DFA). (b) Construct an NFA that accepts the language of all strings over {0,1}\{0,1\} that contain the substring 011011. Convert the obtained NFA into an equivalent DFA using the subset construction method, clearly showing the transition table and the resulting state diagram.

(a) NFA Definition and Difference from DFA

A Non-deterministic Finite Automaton (NFA) is formally a 5-tuple:

M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F)

where:

  • QQ — a finite set of states,
  • Σ\Sigma — a finite input alphabet,
  • δ:Q×(Σ{ε})2Q\delta : Q \times (\Sigma \cup \{\varepsilon\}) \rightarrow 2^{Q} — the transition function mapping a state and an input symbol (or ε\varepsilon) to a set of states,
  • q0Qq_0 \in Q — the start state,
  • FQF \subseteq Q — the set of accepting (final) states.

Differences from a DFA:

AspectDFANFA
Transitionδ:Q×ΣQ\delta: Q\times\Sigma \to Q (single state)δ:Q×(Σ{ε})2Q\delta: Q\times(\Sigma\cup\{\varepsilon\}) \to 2^Q (set of states)
ε\varepsilon-movesNot allowedAllowed
Choices per symbolExactly oneZero, one, or many
AcceptanceUnique pathAccepts if some path ends in FF

Both recognize exactly the same class — the regular languages — but the NFA is often easier to design.

(b) NFA for strings containing substring 011

States: q0q_0 (start), q1q_1 (seen 0), q2q_2 (seen 01), q3q_3 (seen 011, accepting).

State01
q0\to q_0{q0,q1}\{q_0,q_1\}{q0}\{q_0\}
q1q_1{q1}\{q_1\}{q2}\{q_2\}
q2q_2{q1}\{q_1\}{q3}\{q_3\}
q3*q_3{q3}\{q_3\}{q3}\{q_3\}

q0q_0 loops on both symbols (guessing the start of the pattern); once 011 is found, q3q_3 absorbs all further input.

Subset construction (NFA → DFA)

Start with {q0}\{q_0\} and compute reachable subsets:

DFA state01
A={q0}A=\{q_0\}{q0,q1}=B\{q_0,q_1\}=B{q0}=A\{q_0\}=A
B={q0,q1}B=\{q_0,q_1\}{q0,q1}=B\{q_0,q_1\}=B{q0,q2}=C\{q_0,q_2\}=C
C={q0,q2}C=\{q_0,q_2\}{q0,q1}=B\{q_0,q_1\}=B{q0,q3}=D\{q_0,q_3\}=D
D={q0,q3}*D=\{q_0,q_3\}{q0,q1,q3}=E\{q_0,q_1,q_3\}=E{q0,q3}=D\{q_0,q_3\}=D
E={q0,q1,q3}*E=\{q_0,q_1,q_3\}{q0,q1,q3}=E\{q_0,q_1,q_3\}=E{q0,q2,q3}=F\{q_0,q_2,q_3\}=F
F={q0,q2,q3}*F=\{q_0,q_2,q_3\}{q0,q1,q3}=E\{q_0,q_1,q_3\}=E{q0,q3}=D\{q_0,q_3\}=D

DFA: start state AA; accepting states D,E,FD, E, F (every subset containing q3q_3).

Resulting DFA state diagram (described)

  • A0BA \xrightarrow{0} B, A1AA \xrightarrow{1} A
  • B0BB \xrightarrow{0} B, B1CB \xrightarrow{1} C
  • C0BC \xrightarrow{0} B, C1DC \xrightarrow{1} D (accept)
  • D,E,FD,E,F are accepting and never leave the accepting region: each transitions among {D,E,F}\{D,E,F\}, so once 011 has appeared the string is accepted regardless of the suffix.

This DFA accepts exactly the strings over {0,1}\{0,1\} containing 011.

finite-automatanfa-to-dfadfa-design
2long16 marks

(a) Define a Context-Free Grammar (CFG) and a Pushdown Automaton (PDA). Explain the equivalence between CFGs and PDAs. (b) Consider the grammar SaSbabS \rightarrow aSb \mid ab. Show that it generates the language L={anbnn1}L = \{a^n b^n \mid n \geq 1\} and construct a PDA (accepting by empty stack) that recognizes this language, giving its complete set of transition rules.

(a) CFG, PDA, and their Equivalence

Context-Free Grammar (CFG): a 4-tuple G=(V,T,P,S)G = (V, T, P, S) where VV is a finite set of variables (non-terminals), TT the set of terminals (VT=V\cap T=\varnothing), PP a finite set of productions of the form AαA \to \alpha with AVA\in V and α(VT)\alpha\in(V\cup T)^*, and SVS\in V the start symbol. The language is L(G)={wTSw}L(G)=\{w\in T^*\mid S \Rightarrow^* w\}.

Pushdown Automaton (PDA): a 7-tuple M=(Q,Σ,Γ,δ,q0,Z0,F)M = (Q,\Sigma,\Gamma,\delta,q_0,Z_0,F), i.e. an NFA augmented with a stack, where Γ\Gamma is the stack alphabet, Z0Z_0 the initial stack symbol, and δ:Q×(Σ{ε})×Γ2Q×Γ\delta: Q\times(\Sigma\cup\{\varepsilon\})\times\Gamma \to 2^{Q\times\Gamma^*}.

Equivalence: A language is context-free iff it is accepted by some PDA. Every CFG can be converted to an equivalent PDA (and vice versa). Moreover, acceptance by final state and acceptance by empty stack define the same class of languages. Hence CFGs and PDAs have exactly the same expressive power (the context-free languages).

(b) Grammar SaSbabS \to aSb \mid ab

It generates L={anbnn1}L=\{a^nb^n\mid n\ge 1\}:

By induction. Base: Sab=a1b1S\Rightarrow ab = a^1b^1. Inductive step: applying SaSbS\to aSb to anbna^{n}b^{n} wraps one aa on the left and one bb on the right, giving an+1bn+1a^{n+1}b^{n+1}. Every derivation must end with SabS\to ab, so every generated string has the form anbna^nb^n (n1n\ge1), and each such string is derivable by n1n-1 uses of SaSbS\to aSb then SabS\to ab. Therefore L(G)={anbnn1}L(G)=\{a^nb^n\mid n\ge1\}. \blacksquare

PDA accepting by empty stack. Idea: push a marker for each aa, pop one for each matching bb.

M=({q0,q1},{a,b},{A,Z0},δ,q0,Z0,)M=(\{q_0,q_1\},\{a,b\},\{A,Z_0\},\delta,q_0,Z_0,\varnothing) with transitions:

1. delta(q0, a, Z0) = { (q0, A Z0) }   ; first a: push A
2. delta(q0, a, A)  = { (q0, A A)  }   ; more a's: push A
3. delta(q0, b, A)  = { (q1, e)    }   ; first b: pop one A
4. delta(q1, b, A)  = { (q1, e)    }   ; more b's: pop A
5. delta(q1, e, Z0) = { (q1, e)    }   ; pop Z0 -> empty stack, accept

(Here e = ε\varepsilon.) After reading all aa's the stack holds AnZ0A^nZ_0; each bb pops one AA; if counts match, after the last bb the stack is Z0Z_0, which rule 5 pops, emptying the stack and accepting. Unequal counts leave the stack non-empty or block a transition, so they are rejected.

context-free-grammarpushdown-automatacfg-to-pda
3long16 marks

(a) Describe the formal model of a standard (single-tape) Turing machine and explain the Church-Turing thesis. (b) Design a Turing machine that accepts the language L={anbncnn1}L = \{a^n b^n c^n \mid n \geq 1\}. Give the transition function and trace the computation of the machine on the input string aabbccaabbcc.

(a) Standard Turing Machine and the Church-Turing Thesis

A (single-tape) Turing Machine is a 7-tuple:

M=(Q,Σ,Γ,δ,q0,qaccept,qreject)M = (Q, \Sigma, \Gamma, \delta, q_0, q_{accept}, q_{reject})
  • QQ — finite set of states,
  • Σ\Sigma — input alphabet (blank Σ\sqcup \notin \Sigma),
  • Γ\Gamma — tape alphabet, ΣΓ\Sigma\subseteq\Gamma, Γ\sqcup\in\Gamma,
  • δ:Q×ΓQ×Γ×{L,R}\delta: Q\times\Gamma \to Q\times\Gamma\times\{L,R\} — transition function (read a symbol, write a symbol, move head Left/Right),
  • q0q_0 — start state, qaccept,qrejectq_{accept}, q_{reject} — halting states.

The machine has a two-way infinite tape and a read/write head. It halts when it enters qacceptq_{accept} or qrejectq_{reject}; otherwise it may loop forever.

Church-Turing Thesis: every function that is effectively computable (computable by any mechanical/algorithmic procedure) can be computed by a Turing machine. Equivalently, the Turing machine captures the intuitive notion of an algorithm; all reasonable models of computation (λ-calculus, recursive functions, RAM, etc.) are equivalent in power to it. It is a thesis (not a provable theorem) because "effectively computable" is an informal notion.

(b) Turing Machine for L={anbncnn1}L=\{a^nb^nc^n \mid n\ge1\}

Strategy: repeatedly mark the leftmost unmarked aa as XX, then the leftmost bb as YY, then the leftmost cc as ZZ; return to the start and repeat. Accept when no symbols remain unmarked.

Tape alphabet Γ={a,b,c,X,Y,Z,}\Gamma=\{a,b,c,X,Y,Z,\sqcup\}. Transition function:

q0: a -> X,R,q1        ; mark an a, go find a b
    Y -> Y,R,q4        ; all a's done -> verify no extra b/c
q1: a -> a,R,q1        ; skip a's
    Y -> Y,R,q1        ; skip already-marked Y's
    b -> Y,R,q2        ; mark a b, go find a c
q2: b -> b,R,q2        ; skip b's
    Z -> Z,R,q2        ; skip already-marked Z's
    c -> Z,L,q3        ; mark a c, go back
q3: a,b,c,Y,Z -> same,L,q3   ; sweep left
    X -> X,R,q0        ; back to start, repeat
q4: Y -> Y,R,q4        ; skip Y's
    Z -> Z,R,q4        ; skip Z's
    blank -> blank,R,qaccept   ; nothing left -> accept

Any symbol read in a state with no rule (e.g. a stray aa, bb, or cc in q4q4, or a missing bb/cc) leads to qrejectq_{reject}.

Trace on input aabbcc

StepTape (head in bold)State
0aabbccq0q_0
Xabbccq1q_1
Xabbccq1q_1
XaYbccq2q_2
XaYbccq2q_2
XaYbZcq3q_3 (after marking c, sweep left)
sweep to X, thenq0q_0
2nd passXaYbZc → X a YbZc, mark a→Xq0q1q_0\to q_1
XXYbZc, skip Y, mark b→Yreaches q2q_2
XXYYZc → mark c→Zq2q3q_2\to q_3
sweep back to startq0q_0
3rdXXYYZZ, head on Yq0q_0 (no more a) → q4q_4
skip Y's and Z's, reach \sqcupq4q_4
finalXXYYZZ\sqcupqacceptq_{accept}

All three symbols are consumed in equal numbers, so the machine accepts aabbcc (n=2n=2).

turing-machinedecidability
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
4short8 marks

(a) State the precedence and meaning of the regular expression operators. (b) Write regular expressions for: (i) all strings over {0,1}\{0,1\} whose length is a multiple of 3, and (ii) all strings over {a,b}\{a,b\} that begin and end with the same symbol.

(a) Regular Expression Operators: Precedence and Meaning

For expressions over an alphabet Σ\Sigma, the three operators in decreasing order of precedence are:

  1. Kleene star rr^{*} — zero or more repetitions of rr (highest precedence). Meaning: L(r)=i0L(r)iL(r^*)=\bigcup_{i\ge0}L(r)^i.
  2. Concatenation r1r2r_1 r_2 — a string of r1r_1 followed by a string of r2r_2. Meaning: L(r1r2)=L(r1)L(r2)L(r_1r_2)=L(r_1)L(r_2).
  3. Union (alternation) r1r2r_1 \mid r_2 — a string in r1r_1 or r2r_2 (lowest precedence). Meaning: L(r1r2)=L(r1)L(r2)L(r_1\mid r_2)=L(r_1)\cup L(r_2).

Parentheses override precedence. Also ε\varepsilon denotes the empty string and \varnothing the empty language. Example: abca\mid bc^* means a(b(c))a\mid(b(c^*)).

(b) Regular Expressions

(i) Strings over {0,1}\{0,1\} of length a multiple of 3:

((01)(01)(01))\big((0\mid1)(0\mid1)(0\mid1)\big)^{*}

Each group contributes exactly 3 symbols, so the total length is 0,3,6,0,3,6,\dots (note ε\varepsilon of length 0 is included).

(ii) Strings over {a,b}\{a,b\} that begin and end with the same symbol:

a(ab)a    b(ab)b    a    ba\,(a\mid b)^{*}\,a \;\mid\; b\,(a\mid b)^{*}\,b \;\mid\; a \;\mid\; b

The first two alternatives cover strings of length 2\ge2 with matching ends; the single symbols aa and bb cover length-1 strings (whose first and last symbol coincide trivially).

regular-expressionsregular-languages
5short8 marks

State the Pumping Lemma for regular languages. Using it, prove that the language L={anbnn0}L = \{a^n b^n \mid n \geq 0\} is not regular.

Pumping Lemma for Regular Languages

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

  1. y1|y| \ge 1 (the middle part is non-empty),
  2. xyp|xy| \le p,
  3. for all i0i \ge 0, xyizLxy^{i}z \in L.

Proof that L={anbnn0}L=\{a^nb^n \mid n\ge0\} is not regular

Assume, for contradiction, that LL is regular. Let pp be the pumping length. Choose

w=apbpL,w=2pp.w = a^{p}b^{p}\in L, \quad |w|=2p\ge p.

By the lemma, w=xyzw=xyz with xyp|xy|\le p and y1|y|\ge1. Since the first pp symbols of ww are all aa's, the substring xyxy lies entirely within the aa-block, so yy consists only of aa's: y=aky=a^{k} with 1kp1\le k\le p.

Now pump with i=2i=2:

xy2z=ap+kbp.xy^{2}z = a^{p+k}b^{p}.

Here the number of aa's is p+k>pp+k > p = the number of bb's, so xy2zLxy^2z \notin L.

This contradicts condition 3 of the pumping lemma. Hence our assumption is false, and L={anbnn0}L=\{a^nb^n\mid n\ge0\} is not regular. \blacksquare

pumping-lemmaregular-languages
6short6 marks

Explain the Chomsky hierarchy of grammars. For each of the four types, give the form of production rules and the corresponding class of accepting automaton, illustrating with a suitable example for each type.

Chomsky Hierarchy of Grammars

Noam Chomsky classified grammars into four nested types by restricting the form of productions (A,BA,B = variables, aa = terminal, α,β,γ\alpha,\beta,\gamma = strings of symbols).

TypeNameProduction formAccepting automatonLanguage class
0Unrestrictedαβ\alpha \to \beta, α\alpha contains 1\ge1 variableTuring MachineRecursively enumerable
1Context-SensitiveαAβαγβ\alpha A\beta \to \alpha\gamma\beta, $\gamma\ge1$ (non-contracting)
2Context-FreeAγA \to \gamma, γ(VT)\gamma\in(V\cup T)^*Pushdown AutomatonContext-free
3RegularAaBA \to aB or AaA\to a (right-linear)Finite AutomatonRegular

The classes are strictly nested: Regular \subset Context-Free \subset Context-Sensitive \subset Recursively Enumerable.

Examples:

  • Type 3 (Regular): SaSbS\to aS \mid b generates aba^*b. Accepted by a finite automaton.
  • Type 2 (Context-Free): SaSbεS\to aSb \mid \varepsilon generates {anbnn0}\{a^nb^n\mid n\ge0\} (not regular). Accepted by a PDA.
  • Type 1 (Context-Sensitive): a grammar for {anbncnn1}\{a^nb^nc^n\mid n\ge1\} (not context-free). Accepted by a linear-bounded automaton.
  • Type 0 (Unrestricted): grammars generating any recursively enumerable language, e.g. encoding an arbitrary Turing machine's computation. Accepted by a Turing machine.
chomsky-hierarchy
7short6 marks

Define an ambiguous grammar. Show that the grammar EE+EEE(E)idE \rightarrow E + E \mid E * E \mid (E) \mid id is ambiguous by giving two distinct parse trees (or leftmost derivations) for the string id+ididid + id * id, and suggest how the ambiguity can be removed.

Ambiguous Grammar

A context-free grammar GG is ambiguous if there exists at least one string in L(G)L(G) that has two or more distinct parse trees (equivalently, two distinct leftmost or two distinct rightmost derivations).

The grammar EE+EEE(E)idE \to E+E \mid E*E \mid (E) \mid id is ambiguous

Consider the string id+ididid + id * id. It has two different leftmost derivations / parse trees:

Derivation 1 (treats + as the outer operator → id+(idid)id+(id*id)):

EE+Eid+Eid+EEid+idEid+ididE \Rightarrow E+E \Rightarrow id+E \Rightarrow id+E*E \Rightarrow id+id*E \Rightarrow id+id*id

Parse tree: root + with left child idid and right child the subtree EEE*E.

Derivation 2 (treats * as the outer operator → (id+id)id(id+id)*id):

EEEE+EEid+EEid+idEid+ididE \Rightarrow E*E \Rightarrow E+E*E \Rightarrow id+E*E \Rightarrow id+id*E \Rightarrow id+id*id

Parse tree: root * with left child the subtree E+EE+E and right child idid.

Two distinct parse trees for the same string ⇒ the grammar is ambiguous.

Removing the Ambiguity

Rewrite the grammar to enforce operator precedence (* binds tighter than +) and left-associativity, using separate non-terminals for each precedence level:

EE+TTTTFFF(E)idE \to E + T \mid T \qquad T \to T * F \mid F \qquad F \to (E) \mid id

Now id+ididid+id*id has a unique parse tree (with ididid*id grouped first), so the grammar is unambiguous.

context-free-grammargrammar-ambiguity
8short6 marks

Differentiate between a decidable and an undecidable problem. State the Halting Problem and explain, with the essential argument, why it is undecidable.

Decidable vs Undecidable Problems

A decidable (recursive) problem is one for which there exists an algorithm (a Turing machine) that halts on every input and correctly answers "yes" or "no". Example: "Does a DFA accept a given string?"

An undecidable problem is one for which no such always-halting algorithm exists; no Turing machine can decide all instances correctly. Example: the Halting Problem.

The Halting Problem

Statement: Given an arbitrary Turing machine (program) MM and an input ww, decide whether MM halts (terminates) when run on ww. Formally, decide membership in HALT={M,wM halts on w}HALT = \{\langle M,w\rangle \mid M \text{ halts on } w\}.

Why it is Undecidable (essential argument)

Suppose, for contradiction, a TM HH decides HALTHALT: H(M,w)H(\langle M,w\rangle) = yes if MM halts on ww, no otherwise (and HH always halts).

Build a machine DD that takes M\langle M\rangle and does:

D(<M>):
  if H(<M>, <M>) = yes  then  loop forever
  else                       halt

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

  • If DD halts on D\langle D\rangle, then H(D,D)=H(\langle D\rangle,\langle D\rangle)= yes, so by construction DD loops — contradiction.
  • If DD loops on D\langle D\rangle, then H(D,D)=H(\langle D\rangle,\langle D\rangle)= no, so by construction DD halts — contradiction.

Either case is contradictory, so the assumed HH cannot exist. This diagonalization argument proves the Halting Problem is undecidable. \blacksquare

decidabilityundecidabilityhalting-problem
9short6 marks

Given the regular grammar with productions SaAbSεS \rightarrow aA \mid bS \mid \varepsilon and AaSbAA \rightarrow aS \mid bA, construct the equivalent finite automaton and describe the language it accepts.

Constructing the Finite Automaton

The right-linear grammar is:

SaAbSε,AaSbAS \to aA \mid bS \mid \varepsilon, \qquad A \to aS \mid bA

Map each variable to a state (SS\to state SS, AA\to state AA); a production XcYX\to cY gives a transition XcYX\xrightarrow{c}Y, and XεX\to\varepsilon makes XX an accepting state.

  • SaAS\to aASaAS\xrightarrow{a}A
  • SbSS\to bSSbSS\xrightarrow{b}S
  • SεS\to\varepsilonSS is a final state
  • AaSA\to aSAaSA\xrightarrow{a}S
  • AbAA\to bAAbAA\xrightarrow{b}A

Transition table (start = SS, final = {S}\{S\}):

Stateab
S\to *SAASS
AASSAA

This is a DFA with two states.

Language Accepted

Reading a bb never changes the state (SSS\to S, AAA\to A); reading an aa toggles between SS and AA. So the automaton is in state AA exactly when the number of aa's read so far is odd, and in SS (the accepting state) when it is even.

Therefore the accepted language is:

L={w{a,b}w contains an even number of a’s}L = \{\, w \in \{a,b\}^{*} \mid w \text{ contains an even number of } a\text{'s} \,\}

(the number of bb's is unrestricted, and ε\varepsilon, with zero aa's, is accepted).

regular-grammarfinite-automata
10short6 marks

Convert the following context-free grammar into Chomsky Normal Form (CNF): SASBεS \rightarrow ASB \mid \varepsilon, AaASaA \rightarrow aAS \mid a, BSbSAbbB \rightarrow SbS \mid A \mid bb. Show all intermediate steps including removal of ε\varepsilon-productions and unit productions.

Converting to Chomsky Normal Form

Start grammar:

SASBε,AaASa,BSbSAbbS\to ASB\mid\varepsilon,\quad A\to aAS\mid a,\quad B\to SbS\mid A\mid bb

Step 1 — Add a new start symbol

S0SS_0\to S, keeping all old rules (so the start symbol never appears on a RHS).

Step 2 — Remove ε\varepsilon-productions

Nullable variables: SS (from SεS\to\varepsilon). BB has BSbSB\to SbS but bb is terminal, so BB is not nullable; AA is not nullable. Remove SεS\to\varepsilon and add versions of rules with SS omitted:

  • SASBS\to ASB ⟹ also SABS\to AB (drop the SS)
  • AaASA\to aAS ⟹ also AaAA\to aA
  • BSbSB\to SbS ⟹ also BbS, Sb, bB\to bS,\ Sb,\ b
  • S0SS_0\to S ⟹ also S0εS_0\to\varepsilon (kept, since εL\varepsilon\in L)

Now:

S0Sε,SASBAB,AaASaAa,BSbSbSSbbAbbS_0\to S\mid\varepsilon,\quad S\to ASB\mid AB,\quad A\to aAS\mid aA\mid a,\quad B\to SbS\mid bS\mid Sb\mid b\mid A\mid bb

Step 3 — Remove unit productions

Unit pairs: S0SS_0\to S and BAB\to A.

  • Replace S0SS_0\to S by SS's rules: S0ASBABS_0\to ASB\mid AB (and keep S0εS_0\to\varepsilon).
  • Replace BAB\to A by AA's rules: BaASaAaB\to aAS\mid aA\mid a.

Result:

S0ASBABε,SASBAB,AaASaAa,S_0\to ASB\mid AB\mid\varepsilon,\quad S\to ASB\mid AB,\quad A\to aAS\mid aA\mid a, BSbSbSSbbbbaASaAB\to SbS\mid bS\mid Sb\mid b\mid bb\mid aAS\mid aA

Step 4 — Replace terminals in long RHS

Introduce XaaX_a\to a and XbbX_b\to b, substituting them wherever a terminal sits in a string of length 2\ge2:

  • AXaASXaAaA\to X_aAS\mid X_aA\mid a
  • BSXbSXbSSXbbXbXbXaASXaAB\to SX_bS\mid X_bS\mid SX_b\mid b\mid X_bX_b\mid X_aAS\mid X_aA
  • S0ASBABεS_0\to ASB\mid AB\mid\varepsilon, SASBABS\to ASB\mid AB

Step 5 — Break RHS longer than 2 into binary

Introduce auxiliary variables for length-3 right-hand sides:

  • ASBASB: let C1SBC_1\to SB, then S0AC1S_0\to AC_1, SAC1S\to AC_1.
  • XaASX_aAS: let C2ASC_2\to AS, then AXaC2A\to X_aC_2, BXaC2B\to X_aC_2.
  • SXbSSX_bS: let C3XbSC_3\to X_bS, then BSC3B\to SC_3.

Final CNF grammar

S0AC1ABεSAC1ABAXaC2XaAaBSC3XbSSXbXaC2XaAXbXbbC1SB,C2AS,C3XbSXaa,Xbb\begin{aligned} S_0&\to AC_1\mid AB\mid\varepsilon\\ S&\to AC_1\mid AB\\ A&\to X_aC_2\mid X_aA\mid a\\ B&\to SC_3\mid X_bS\mid SX_b\mid X_aC_2\mid X_aA\mid X_bX_b\mid b\\ C_1&\to SB,\quad C_2\to AS,\quad C_3\to X_bS\\ X_a&\to a,\quad X_b\to b \end{aligned}

Every production now has the form ABCA\to BC or AaA\to a (with the single allowed exception S0εS_0\to\varepsilon because the start symbol does not appear on any RHS), so the grammar is in CNF.

context-free-grammarcnfgrammar-normalization
11short6 marks

Distinguish between recursive (decidable) languages and recursively enumerable languages. Explain why every recursive language is recursively enumerable but the converse is not necessarily true.

Recursive vs Recursively Enumerable Languages

Recursive (decidable) language: a language LL for which there is a Turing machine that always halts and decides membership — it accepts every wLw\in L and rejects (halts and says "no") every wLw\notin L.

Recursively enumerable (RE / Turing-recognizable) language: a language LL for which there is a Turing machine that accepts (halts) every wLw\in L, but on wLw\notin L it may either reject or loop forever (run without halting).

PropertyRecursiveRecursively Enumerable
TM behaviourAlways halts (decider)Halts on members; may loop on non-members (recognizer)
Decision possibleYesMembership semi-decidable only
Closed under complementYesNo

Why Recursive ⟹ Recursively Enumerable

If LL is recursive, it has a decider MM that halts on all inputs. This same MM is also a recognizer: it accepts exactly the strings of LL (and halts on them). A decider is a special case of a recognizer, so every recursive language is recursively enumerable.

Why the Converse Fails

There exist RE languages that are not recursive — the classic example is

ATM={M,wM accepts w}.A_{TM}=\{\langle M,w\rangle \mid M \text{ accepts } w\}.

A universal TM can recognize ATMA_{TM} (simulate MM on ww and accept if it accepts), so it is RE. But it is undecidable (no always-halting decider exists, by the Halting Problem). Hence it is RE but not recursive.

Key theoretical fact: LL is recursive iff both LL and its complement L\overline{L} are recursively enumerable. If "RE ⟹ recursive" held for all languages, every RE language would be decidable, contradicting the existence of ATMA_{TM}. Therefore RE is a strictly larger class, and the converse does not hold.

turing-machinerecursive-enumerabledecidability

Frequently asked questions

Where can I find the BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) question paper 2079?
The full BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 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 (IOE, CT 502) 2079 paper come with solutions?
Yes. Every question on this Theory of Computation (IOE, CT 502) 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 (IOE, TU) Theory of Computation (IOE, CT 502) 2079 paper?
The BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2079 paper carries 80 full marks and is meant to be completed in 180 minutes, across 11 questions.
Is practising this Theory of Computation (IOE, CT 502) past paper free?
Yes — reading and attempting this Theory of Computation (IOE, CT 502) past paper on Kekkei is completely free.