Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Define a Turing Machine formally. Design a Turing Machine that accepts the language L = { a^n b^n c^n | n >= 1 } and explain its working with a transition diagram.

Formal Definition of a Turing Machine

A Turing Machine (TM) is a 7-tuple:

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

where:

  • QQ = finite set of states
  • Σ\Sigma = input alphabet (does not contain the blank BB)
  • Γ\Gamma = tape alphabet, with ΣΓ\Sigma \subseteq \Gamma and BΓB \in \Gamma
  • δ:Q×ΓQ×Γ×{L,R}\delta: Q \times \Gamma \rightarrow Q \times \Gamma \times \{L, R\} = transition function
  • q0Qq_0 \in Q = start state
  • BB = blank symbol
  • FQF \subseteq Q = set of accepting (final) states

A TM reads/writes on an infinite tape and moves its head left (LL) or right (RR). The language accepted is L(M)={wΣq0wαqfβ, qfF}L(M) = \{ w \in \Sigma^* \mid q_0 w \vdash^* \alpha\, q_f\, \beta,\ q_f \in F \}.

TM for L={anbncnn1}L = \{ a^n b^n c^n \mid n \ge 1 \}

This is a classic non-context-free language; a single-tape TM accepts it.

Strategy: In each pass, mark the leftmost unmarked aa as XX, then move right to mark the leftmost unmarked bb as YY, then the leftmost unmarked cc as ZZ. Return to the left and repeat until all symbols are marked. Finally verify nothing is left over.

States: Q={q0,q1,q2,q3,q4,q5}Q = \{q_0, q_1, q_2, q_3, q_4, q_5\}, with q5q_5 the accept state. Tape symbols X,Y,ZX, Y, Z are markers for matched a,b,ca, b, c.

Transition function δ\delta:

StateabcXYZB
q0q_0(q1,X,R)(q_1, X, R)(q4,Y,R)(q_4, Y, R)
q1q_1(q1,a,R)(q_1, a, R)(q2,Y,R)(q_2, Y, R)(q1,Y,R)(q_1, Y, R)
q2q_2(q2,b,R)(q_2, b, R)(q3,Z,L)(q_3, Z, L)(q2,Z,R)(q_2, Z, R)
q3q_3(q3,a,L)(q_3, a, L)(q3,b,L)(q_3, b, L)(q0,X,R)(q_0, X, R)(q3,Y,L)(q_3, Y, L)(q3,Z,L)(q_3, Z, L)
q4q_4(q4,Y,R)(q_4, Y, R)(q4,Z,R)(q_4, Z, R)(q5,B,R)(q_5, B, R)

Working:

  1. q0q_0: replace an aa by XX, enter q1q_1. If it instead sees YY (all aa's already marked) it goes to the verification state q4q_4.
  2. q1q_1: skip remaining aa's and already-placed YY's, replace the first bb by YY, enter q2q_2.
  3. q2q_2: skip remaining bb's and ZZ's, replace the first cc by ZZ, move left into q3q_3.
  4. q3q_3: walk left over a,b,Y,Za,b,Y,Z until the rightmost XX is found, step right and return to q0q_0 to start the next pass.
  5. q4q_4 (verification): only YY's and ZZ's should remain; on reading blank BB go to accept state q5q_5. Any leftover aa, bb or cc causes a halt with no accepting transition (reject).

The machine accepts only strings with equal numbers of aa, bb, cc in the order anbncna^nb^nc^n.

Transition Diagram (description)

Nodes q0q1q2q3q0q_0 \to q_1 \to q_2 \to q_3 \to q_0 form the marking loop; an arrow from q0q_0 on input YY goes to q4q_4, and from q4q_4 on BB to the double-circle accept state q5q_5. Self-loops on q1,q2,q3,q4q_1,q_2,q_3,q_4 represent skipping over symbols.

turing-machinerecursively-enumerable
2long10 marks

Explain the relationship between regular expressions and finite automata. Show that for every regular expression there is an epsilon-NFA accepting the same language, and convert (a+b)*ab into an equivalent finite automaton.

Regular Expressions and Finite Automata

Regular expressions (RE) and finite automata (FA) are equivalent in expressive power: a language is regular iff it is described by some regular expression, iff it is accepted by some finite automaton (Kleene's Theorem).

  • For every FA there exists an equivalent RE (state-elimination / Arden's theorem).
  • For every RE there exists an equivalent ε\varepsilon-NFA (Thompson's construction).

Every RE has an equivalent ε\varepsilon-NFA (Thompson's Construction)

We prove by structural induction on the RE. Each constructed NFA has exactly one start and one accept state.

Base cases:

  • \varnothing: start and (separate) accept state, no transitions.
  • ε\varepsilon: start ε\xrightarrow{\varepsilon} accept.
  • aΣa \in \Sigma: start a\xrightarrow{a} accept.

Inductive cases (let N(R)N(R) be the NFA for RR):

  • Union R1+R2R_1 + R_2: new start with ε\varepsilon-moves to the starts of N(R1),N(R2)N(R_1), N(R_2); their accepts have ε\varepsilon-moves to a new accept.
  • Concatenation R1R2R_1 R_2: accept of N(R1)N(R_1) gets an ε\varepsilon-move to the start of N(R2)N(R_2).
  • Kleene star R1R_1^*: new start ε\xrightarrow{\varepsilon} start of N(R1)N(R_1) and ε\xrightarrow{\varepsilon} new accept; accept of N(R1)N(R_1) loops back ε\xrightarrow{\varepsilon} to its start and ε\xrightarrow{\varepsilon} to the new accept.

By induction, every RE is converted into an ε\varepsilon-NFA accepting the same language. \blacksquare

Converting (a+b)ab(a+b)^*ab to a Finite Automaton

ε\varepsilon-NFA (Thompson): Build (a+b)(a+b)^* as a loop that reads any number of aa's and bb's, then concatenate the literals aa then bb.

After eliminating ε\varepsilon-moves and applying the subset construction we obtain a clean DFA. The language is all strings over {a,b}\{a,b\} that end in abab.

DFA:

Stateon aaon bb
A\to A (start)BBAA
BB (last symbol was aa)BBCC
C*C (just read abab)BBAA
  • AA: have not yet seen a pending aa.
  • BB: last symbol read was aa (possible prefix of abab).
  • CC (accepting): string just ended in abab.

This DFA accepts exactly L((a+b)ab)L\big((a+b)^*ab\big).

regular-expressionepsilon-nfa
3long10 marks

State the Halting Problem of a Turing Machine. Prove that the Halting Problem is undecidable. Differentiate between decidable and undecidable problems with examples.

The Halting Problem

Statement: Given an arbitrary Turing Machine MM and an input ww, determine whether MM halts (stops) when run on ww. As a language:

HALTTM={M,wM is a TM that halts on input w}HALT_{TM} = \{ \langle M, w \rangle \mid M \text{ is a TM that halts on input } w \}

The Halting Problem asks for an algorithm (a TM) that decides membership in HALTTMHALT_{TM} for every input.

Proof that the Halting Problem is Undecidable

We use proof by contradiction (diagonalization / reduction).

  1. Assume a TM HH exists that decides the halting problem:
H(M,w)={acceptif M halts on wrejectif M loops on wH(\langle M, w\rangle) = \begin{cases} \text{accept} & \text{if } M \text{ halts on } w \\ \text{reject} & \text{if } M \text{ loops on } w \end{cases}

HH always halts and gives the correct answer.

  1. Construct a new TM DD that takes a single TM encoding M\langle M \rangle as input and does:

    • Run HH on M,M\langle M, \langle M\rangle \rangle (i.e., does MM halt on its own description?).
    • If HH says "halts" \Rightarrow DD loops forever.
    • If HH says "loops" \Rightarrow DD halts.
  2. Now run DD on its own description D\langle D \rangle:

    • If DD halts on D\langle D\rangle, then by construction HH said "loops," so DD should loop — contradiction.
    • If DD loops on D\langle D\rangle, then HH said "halts," so DD should halt — contradiction.

Both cases are contradictory, so the assumption that HH exists is false. Hence no TM can decide the Halting Problem; it is undecidable. \blacksquare

Decidable vs Undecidable Problems

AspectDecidableUndecidable
DefinitionA TM (decider) exists that always halts with yes/noNo TM halts with the correct answer on all inputs
Language classRecursiveNot recursive
TerminationAlways haltsMay loop forever on some inputs
ExamplesMembership in a regular/CFL; emptiness of a DFA; "does DFA accept ww"; anbncna^nb^nc^n membershipHalting problem; Post Correspondence Problem; "is L(M)=L(M)=\varnothing" for a TM; Rice's theorem properties

Note: A problem can be recursively enumerable (a TM accepts all yes-instances but may loop on no-instances) yet still undecidable — the Halting Problem is exactly such a case.

halting-problemdecidability
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Explain the conversion of a CFG into Greibach Normal Form (GNF).

Greibach Normal Form (GNF)

A CFG is in GNF if every production has the form:

AaαA \rightarrow a\,\alpha

where aa is a single terminal and α\alpha is a (possibly empty) string of variables (αV\alpha \in V^*). Each production starts with exactly one terminal followed by zero or more non-terminals.

Conversion Procedure

  1. Pre-process: Eliminate ε\varepsilon-productions, unit productions, and useless symbols, then convert the grammar to Chomsky Normal Form (CNF) as a starting point.
  2. Order the variables A1,A2,,AnA_1, A_2, \dots, A_n.
  3. Remove left recursion and forward substitution: Rewrite productions so that for every AiAjγA_i \rightarrow A_j\,\gamma, we have j>ij > i.
    • If AiAjγA_i \rightarrow A_j\gamma with j<ij < i, substitute all productions of AjA_j into AiA_i.
    • If AiAiγA_i \rightarrow A_i\gamma (left recursion), eliminate it by introducing a new variable BiB_i:
AiββBi,BiγγBiA_i \rightarrow \beta \mid \beta B_i, \qquad B_i \rightarrow \gamma \mid \gamma B_i
  1. Make leading symbols terminal: Starting from the highest-numbered variable AnA_n (whose productions already begin with a terminal), back-substitute downward so that every AiA_i production begins with a terminal.
  2. Fix the new BiB_i variables the same way so their productions also begin with terminals.

Example

For SSabS \rightarrow Sa \mid b (left-recursive):

  • Eliminate left recursion: SbbAS \rightarrow b \mid bA, AaaAA \rightarrow a \mid aA.
  • Both productions now begin with a terminal — this is in GNF.

Use: GNF guarantees each derivation step consumes exactly one terminal, which is useful for constructing a PDA and for proving that every CFL has a PDA (and bounds derivation length to w|w| steps).

greibach-normal-formcfg
5short5 marks

Define instantaneous description (ID) of a PDA and explain acceptance by final state and by empty stack.

Instantaneous Description (ID) of a PDA

A Pushdown Automaton is P=(Q,Σ,Γ,δ,q0,Z0,F)P = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F). An instantaneous description captures the complete configuration of the PDA at a moment in time. It is a triple:

(q,w,γ)(q, w, \gamma)

where:

  • qQq \in Q = current state,
  • wΣw \in \Sigma^* = remaining (unread) portion of the input,
  • γΓ\gamma \in \Gamma^* = current contents of the stack (top written leftmost).

A single move is written using the turnstile \vdash: if δ(q,a,X)\delta(q, a, X) contains (p,β)(p, \beta), then

(q,aw,Xγ)(p,w,βγ).(q, aw, X\gamma) \vdash (p, w, \beta\gamma).

The reflexive-transitive closure \vdash^* denotes zero or more moves.

Acceptance by Final State

The PDA accepts ww if, starting from the initial ID, it can consume all of ww and reach a final state (stack contents irrelevant):

L(P)={w(q0,w,Z0)(p,ε,γ), pF, γΓ}L(P) = \{ w \mid (q_0, w, Z_0) \vdash^* (p, \varepsilon, \gamma),\ p \in F,\ \gamma \in \Gamma^* \}

Acceptance by Empty Stack

The PDA accepts ww if, after consuming all of ww, the stack becomes empty (final state irrelevant):

N(P)={w(q0,w,Z0)(p,ε,ε), pQ}N(P) = \{ w \mid (q_0, w, Z_0) \vdash^* (p, \varepsilon, \varepsilon),\ p \in Q \}

Equivalence

Both modes accept exactly the context-free languages. For any PDA accepting by final state there is an equivalent PDA accepting by empty stack, and vice versa, so the two acceptance criteria are equivalent in power.

pda
6short5 marks

Explain the working of a multi-tape Turing Machine.

Multi-tape Turing Machine

A multi-tape TM has kk tapes (k1k \ge 1), each with its own independent read/write head. It is defined like a standard TM except the transition function is:

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

Working

  1. Input: The input is placed on tape 1; the other tapes start blank.
  2. Reading: In one step the machine reads the symbols under all kk heads simultaneously (one symbol per tape).
  3. Action: Based on the current state and the kk-tuple of scanned symbols, it:
    • changes state,
    • writes a new symbol on each tape, and
    • moves each head independently left (LL), right (RR), or keeps it stationary (SS).
  4. Tapes are used as scratch/work space (e.g., one tape for input, one for a counter, one for output), which makes algorithms much easier to design.

Equivalence with a Single-Tape TM

A multi-tape TM is no more powerful than a single-tape TM; both accept exactly the recursively enumerable languages.

  • A single-tape TM can simulate a kk-tape TM by storing the kk tapes on one tape using tracks, marking each head position, and sweeping across to gather symbols.
  • Cost: If a kk-tape TM runs in time T(n)T(n), the single-tape simulation runs in O(T(n)2)O(T(n)^2) time.

Thus multi-tape TMs improve convenience and efficiency, not computational power.

turing-machine
7short5 marks

What is a Universal Turing Machine? Explain its significance.

Universal Turing Machine (UTM)

A Universal Turing Machine is a single Turing Machine UU that can simulate the behaviour of any other Turing Machine. It takes as input an encoding M\langle M \rangle of an arbitrary TM MM together with an input string ww, i.e. the pair M,w\langle M, w \rangle, and then simulates MM running on ww:

U(M,w)=M(w)U(\langle M, w \rangle) = M(w)

UU accepts M,w\langle M, w\rangle iff MM accepts ww, halts iff MM halts, and loops iff MM loops.

How it Works

UU typically uses multiple tracks/tapes to store: (1) the encoded transition table of MM, (2) the current tape contents of MM, and (3) the current state of MM. It repeatedly looks up the matching transition of MM in the description, updates the simulated tape, state and head position, and continues until MM halts.

Significance

  • Stored-program concept: A UTM is the theoretical basis of the modern general-purpose, programmable computer — program and data are both stored as input. This directly inspired the von Neumann architecture.
  • Universality: It shows one fixed machine can compute anything any TM can compute, supporting the Church–Turing thesis.
  • Undecidability: The existence of the UTM enables key undecidability proofs, since its acceptance language Lu={M,wM accepts w}L_u = \{\langle M, w\rangle \mid M \text{ accepts } w\} is recursively enumerable but not recursive (undecidable), central to proving the Halting Problem undecidable.
turing-machineuniversal-tm
8short5 marks

Differentiate between recursive and recursively enumerable languages.

Recursive vs Recursively Enumerable Languages

Both are defined by Turing machines, but differ in halting behaviour.

  • Recursive language (Decidable): A language LL is recursive if there exists a TM (a decider) that always halts — it accepts every wLw \in L and rejects (halts) every wLw \notin L.
  • Recursively Enumerable (RE) language (Turing-recognizable): A language LL is RE if there exists a TM that accepts every wLw \in L, but on wLw \notin L it may either reject or loop forever.
PropertyRecursiveRecursively Enumerable
TM behaviourAlways halts (decider)Halts on accept; may loop on reject
DecidabilityDecidableMay be undecidable
MembershipAlways answerable (yes/no)"Yes" answerable; "no" may never come
Closure under complementClosed (complement also recursive)NOT closed under complement
RelationshipEvery recursive language is RENot every RE language is recursive
Example{anbncn}\{a^n b^n c^n\}, any decidable problemLuL_u (universal language), the Halting language

Key theorem: LL is recursive iff both LL and its complement Lˉ\bar{L} are recursively enumerable. The Halting language is RE but not recursive, proving recursive \subsetneq RE.

recursiverecursively-enumerable
9short5 marks

Define Mealy and Moore machines and differentiate between them.

Mealy and Moore Machines

Both are finite-state machines with output (transducers). A general definition is the 6-tuple (Q,Σ,Δ,δ,λ,q0)(Q, \Sigma, \Delta, \delta, \lambda, q_0), where Δ\Delta is the output alphabet and λ\lambda is the output function — the two differ in λ\lambda.

Moore Machine

Output depends only on the current state:

λ:QΔ\lambda: Q \rightarrow \Delta

Each state is labelled with an output symbol. For an input of length nn, the output length is n+1n+1 (the start state's output is emitted before any input).

Mealy Machine

Output depends on both the current state and the current input:

λ:Q×ΣΔ\lambda: Q \times \Sigma \rightarrow \Delta

Outputs are written on the transitions. For an input of length nn, the output length is nn.

Differences

AspectMoore MachineMealy Machine
Output depends onCurrent state onlyCurrent state and current input
Output associated withStates (nodes)Transitions (edges)
Output functionλ:QΔ\lambda: Q \to \Deltaλ:Q×ΣΔ\lambda: Q \times \Sigma \to \Delta
Output length (input len nn)n+1n+1nn
Reaction to inputDelayed by one clockImmediate
Number of statesOften moreOften fewer

Both machines are equivalent in computational power — any Moore machine can be converted to an equivalent Mealy machine and vice versa.

mealy-moore
10short5 marks

Explain the closure properties of regular languages.

Closure Properties of Regular Languages

A class of languages is closed under an operation if applying that operation to regular languages always yields a regular language. Regular languages are closed under all the following operations. Let L1,L2L_1, L_2 be regular.

  1. UnionL1L2L_1 \cup L_2 is regular. (RE: R1+R2R_1 + R_2; or product/parallel NFA.)
  2. ConcatenationL1L2L_1 L_2 is regular. (RE: R1R2R_1 R_2.)
  3. Kleene StarL1L_1^* is regular. (RE: R1R_1^*.)
  4. ComplementationL1ˉ=ΣL1\bar{L_1} = \Sigma^* - L_1 is regular. (Take the DFA and swap accepting/non-accepting states.)
  5. IntersectionL1L2L_1 \cap L_2 is regular. (Product automaton; or via L1ˉL2ˉ\overline{\bar{L_1} \cup \bar{L_2}} by De Morgan.)
  6. DifferenceL1L2=L1L2ˉL_1 - L_2 = L_1 \cap \bar{L_2} is regular.
  7. ReversalL1RL_1^R is regular. (Reverse all transitions, swap start/final states.)
  8. Homomorphism and inverse homomorphism — regular languages are closed under both.

Significance: These properties let us prove a language regular by building it from known regular languages, and the decision/closure under intersection & complement is heavily used (e.g., for the product construction and for proving non-regularity by combining with the pumping lemma).

closure-propertiesregular-languages
11short5 marks

What is the membership problem? Explain the CYK algorithm in brief.

Membership Problem

The membership problem asks: given a grammar GG (or automaton) and a string ww, does wL(G)w \in L(G)? For context-free grammars this is decidable — the CYK algorithm answers it in polynomial time.

CYK (Cocke–Younger–Kasami) Algorithm

CYK is a bottom-up dynamic-programming parser that decides whether wL(G)w \in L(G), where GG must be in Chomsky Normal Form (productions of the form ABCA \to BC or AaA \to a). For w=a1a2anw = a_1 a_2 \dots a_n it builds a triangular table Vi,jV_{i,j} = the set of variables that derive the substring of length jj starting at position ii.

Steps:

  1. Length-1: For each symbol aia_i, set Vi,1={AAaiG}V_{i,1} = \{ A \mid A \to a_i \in G \}.
  2. Longer substrings: For length j=2nj = 2 \dots n and start ii, examine every split point kk (1k<j1 \le k < j):
AVi,j if ABC, BVi,k, CVi+k,jkA \in V_{i,j} \ \text{if}\ A \to BC,\ B \in V_{i,k},\ C \in V_{i+k,\,j-k}
  1. Acceptance: wL(G)w \in L(G) iff the start symbol SV1,nS \in V_{1,n} (the cell covering the whole string).

Complexity: O(n3G)O(n^3 \cdot |G|) time, O(n2)O(n^2) space — polynomial, so the membership problem for CFLs is decidable.

for i = 1 to n:                      // base case
    V[i][1] = { A : A -> a_i }
for j = 2 to n:                      // substring length
  for i = 1 to n-j+1:                // start position
    for k = 1 to j-1:                // split point
      if A->BC, B in V[i][k], C in V[i+k][j-k]:
        add A to V[i][j]
accept if S in V[1][n]
cykdecidability
12short5 marks

Construct an NFA for the regular expression (0+1)*1.

NFA for (0+1)1(0+1)^*1

The regular expression (0+1)1(0+1)^*1 describes all strings over {0,1}\{0,1\} that end with 11.

NFA M=({q0,q1},{0,1},δ,q0,{q1})M = (\{q_0, q_1\}, \{0,1\}, \delta, q_0, \{q_1\}):

  • q0q_0 is the start state. On both 00 and 11 it can stay in q0q_0 (the (0+1)(0+1)^* loop), and on 11 it may also non-deterministically move to q1q_1.
  • q1q_1 is the single accepting state, reached only after reading a final 11.

Transition table:

Stateon 00on 11
q0\to q_0{q0}\{q_0\}{q0,q1}\{q_0, q_1\}
q1*q_1\varnothing\varnothing

Transition diagram (description): A self-loop on q0q_0 labelled 0,10,1 (for (0+1)(0+1)^*); an arrow q01q1q_0 \xrightarrow{1} q_1; q1q_1 is a double circle (accepting) with no outgoing edges.

Verification: A string is accepted iff there is a path ending in q1q_1, i.e. iff the last symbol read was 11 — exactly L((0+1)1)L((0+1)^*1). For example, 101 is accepted, 110 is rejected.

nfaregular-expression

Frequently asked questions

Where can I find the BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) question paper 2077?
The full BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) 2077 (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 (BSc CSIT, CSC257) 2077 paper come with solutions?
Yes. Every question on this Theory of Computation (BSc CSIT, CSC257) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) 2077 paper?
The BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) 2077 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this Theory of Computation (BSc CSIT, CSC257) past paper free?
Yes — reading and attempting this Theory of Computation (BSc CSIT, CSC257) past paper on Kekkei is completely free.