Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

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

Halting Problem of a Turing Machine

The Halting Problem asks: Given an arbitrary Turing machine MM and an input string ww, does MM halt (stop) on input ww?

Formally, define the language

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

The Halting Problem is to decide membership in HALTTMHALT_{TM}.

Proof that the Halting Problem is Undecidable

We prove undecidability by contradiction (diagonalization).

  1. Assume there exists a Turing machine HH that decides the Halting Problem. That is, for every M,w\langle M, w\rangle:
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}
  1. Using HH, construct a new machine DD that takes a single TM description M\langle M\rangle as input and behaves as follows:
D(<M>):
   run H(<M>, <M>)        # does M halt on its own description?
   if H accepts:  loop forever
   if H rejects:  halt (accept)

Thus DD does the opposite of what MM does on its own encoding.

  1. Now run DD on its own description D\langle D\rangle:
    • If DD halts on D\langle D\rangle, then HH said "halts", so by construction DD loops — contradiction.
    • If DD loops on D\langle D\rangle, then HH said "loops", so by construction DD halts — contradiction.

Either case is a contradiction, so the assumed decider HH cannot exist. Therefore the Halting Problem is undecidable. (It is, however, recursively enumerable / semi-decidable — a TM can simulate MM on ww and accept if it halts.)

Decidable vs. Undecidable Problems

AspectDecidableUndecidable
DefinitionA problem for which a TM exists that always halts with the correct yes/no answerNo TM can decide it; any TM may loop forever on some inputs
Language classRecursiveNot recursive
GuaranteeAlgorithm always terminatesNo terminating algorithm exists
ExamplesMembership of a string in a regular/CFL language; whether a DFA accepts a string; emptiness of a DFAHalting Problem; whether L(M)=L(M)=\emptyset for a TM; Post Correspondence Problem; whether two CFGs are equivalent

In short: decidable problems have total deciders; undecidable problems (like the Halting Problem) have none.

halting-problemdecidability
2long10 marks

Explain the Chomsky hierarchy of languages with the corresponding grammars and recognizing machines. Discuss the closure properties of context-free languages.

Chomsky Hierarchy of Languages

Noam Chomsky classified formal grammars/languages into four nested types by restrictions on production rules. Each type corresponds to a class of grammar and an abstract machine that recognizes it.

TypeLanguage ClassGrammar (production form)Recognizing Machine
Type 0Recursively EnumerableUnrestricted: αβ\alpha \to \beta, αε\alpha \neq \varepsilonTuring Machine
Type 1Context-SensitiveαAβαγβ\alpha A \beta \to \alpha \gamma \beta, $\text{LHS}
Type 2Context-FreeAγA \to \gamma (single non-terminal LHS)Pushdown Automaton (PDA)
Type 3RegularAaBA \to aB or AaA \to a (right-linear)Finite Automaton (DFA/NFA)

The containment is strict: RegularCFLCSLRE\text{Regular} \subset \text{CFL} \subset \text{CSL} \subset \text{RE}.

Closure Properties of Context-Free Languages

Let L1,L2L_1, L_2 be context-free languages.

CFLs are CLOSED under:

  • Union: L1L2L_1 \cup L_2 — combine grammars with new start symbol SS1S2S \to S_1 \mid S_2.
  • Concatenation: L1L2L_1 L_2 — use SS1S2S \to S_1 S_2.
  • Kleene star: L1L_1^* — use SS1SεS \to S_1 S \mid \varepsilon.
  • Substitution and homomorphism.
  • Intersection with a regular language: L1RL_1 \cap R is context-free (product of PDA and DFA).
  • Reversal: L1RL_1^R.

CFLs are NOT CLOSED under:

  • Intersection: e.g. L1={anbncm}L_1=\{a^n b^n c^m\} and L2={ambncn}L_2=\{a^m b^n c^n\} are CFLs but L1L2={anbncn}L_1 \cap L_2 = \{a^n b^n c^n\} is not context-free.
  • Complementation: follows from non-closure under intersection (since L1L2=L1L2L_1 \cap L_2 = \overline{\overline{L_1} \cup \overline{L_2}} and CFLs are closed under union).
  • Set difference in general.

These properties are central to deciding whether a language is context-free.

chomsky-hierarchyclosure-properties
3long10 marks

Define the complexity classes P and NP. Explain NP-completeness and the concept of polynomial-time reduction with the example of the Satisfiability (SAT) problem.

Complexity Classes P and NP

  • P (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 efficiently solvable (tractable) problems. Examples: sorting, shortest path, primality testing.

  • NP (Nondeterministic Polynomial time): the class of decision problems for which a proposed solution (certificate) can be verified by a deterministic TM in polynomial time; equivalently, problems solvable by a nondeterministic TM in polynomial time. Examples: SAT, Hamiltonian cycle, subset-sum.

Clearly PNPP \subseteq NP (a problem that can be solved quickly can be verified quickly). Whether P=NPP = NP is the most famous open problem in computer science.

Polynomial-Time Reduction

A language AA is polynomial-time reducible to BB, written ApBA \le_p B, if there is a function ff computable in polynomial time such that

xA    f(x)B.x \in A \iff f(x) \in B.

Meaning: an efficient algorithm for BB yields an efficient algorithm for AA. Reductions transfer hardness: if ApBA \le_p B and BPB \in P, then APA \in P.

NP-Completeness

A language LL is NP-complete if:

  1. LNPL \in NP, and
  2. Every language ANPA \in NP satisfies ApLA \le_p L (NP-hardness).

NP-complete problems are the hardest in NP: if any one of them is in PP, then P=NPP = NP.

SAT (Satisfiability) Example

The SAT problem asks whether a given Boolean formula (e.g. in CNF) has an assignment of truth values making it true.

  • SAT is in NP: given a truth assignment (certificate), we can evaluate the formula in polynomial time to verify satisfaction.
  • Cook–Levin Theorem: SAT is NP-complete — it was the first problem proved NP-complete by showing that the computation of any polynomial-time NDTM on an input can be encoded as a Boolean formula that is satisfiable iff the machine accepts.

Because SAT is NP-complete, it serves as the canonical starting point for proving other problems NP-complete: to show a new problem XX is NP-hard, we exhibit a polynomial-time reduction SATpX\text{SAT} \le_p X (e.g. SAT p\le_p 3-SAT p\le_p Clique p\le_p Vertex Cover).

complexitynp-completeness
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

What is a Universal Turing Machine? Explain its significance.

Universal Turing Machine (UTM)

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

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

If MM accepts ww, UU accepts; if MM rejects, UU rejects; if MM loops, UU loops.

Significance

  • Stored-program concept: The UTM treats a program (the description M\langle M\rangle) as data on its tape — the theoretical basis for modern general-purpose, stored-program computers (von Neumann architecture).
  • Programmability: A single fixed machine can perform any computation simply by changing its input, rather than building a new machine per task.
  • Foundation for undecidability: The existence of a UTM makes self-reference possible and underlies proofs that the Halting Problem and the language ATM={M,w:M accepts w}A_{TM}=\{\langle M,w\rangle : M \text{ accepts } w\} are undecidable.
  • It confirms the Church–Turing thesis that Turing machines capture the notion of effective/algorithmic computation.
turing-machineuniversal-tm
5short5 marks

Differentiate between recursive and recursively enumerable languages.

Recursive vs. Recursively Enumerable Languages

Both are accepted by Turing machines, but differ in the halting guarantee.

  • A language is recursive (decidable) if there exists a TM that halts on every input, accepting strings in the language and rejecting those not in it.
  • A language is recursively enumerable (RE / semi-decidable) if there exists a TM that halts and accepts every string in the language, but may loop forever on strings not in the language.
AspectRecursiveRecursively Enumerable
TM behaviourAlways halts (decides)Halts on accept; may loop on reject
Also calledDecidableSemi-decidable / Turing-recognizable
MembershipDecidableOnly "yes" is guaranteed; "no" may not terminate
Closure under complementClosed (recursive)Not closed
ContainmentEvery recursive language is RENot every RE language is recursive
Example{anbncn}\{a^n b^n c^n\}, any context-sensitive languageATM={M,w:M accepts w}A_{TM}=\{\langle M,w\rangle: M \text{ accepts } w\}, the Halting Problem language

Key relation: RecursiveRE\text{Recursive} \subset \text{RE}. A language LL is recursive iff both LL and its complement L\overline{L} are RE.

recursiverecursively-enumerable
6short5 marks

Define Mealy and Moore machines and differentiate between them.

Mealy and Moore Machines

Both are finite-state machines with output (finite-state transducers).

Moore machine — output depends only on the current state. Defined as a 6-tuple (Q,Σ,O,δ,λ,q0)(Q,\Sigma,O,\delta,\lambda,q_0) where λ:QO\lambda: Q \to O associates an output with each state.

Mealy machine — output depends on the current state AND the current input symbol. Defined as a 6-tuple (Q,Σ,O,δ,λ,q0)(Q,\Sigma,O,\delta,\lambda,q_0) where λ:Q×ΣO\lambda: Q \times \Sigma \to O associates an output with each transition.

Differences

AspectMoore MachineMealy Machine
Output depends onCurrent state onlyCurrent state and input symbol
Output functionλ:QO\lambda: Q \to Oλ:Q×ΣO\lambda: Q \times \Sigma \to O
Output associated withStates (nodes)Transitions (edges)
Output for input of length nnn+1n+1 symbols (includes initial state output)nn symbols
Reaction to inputOne clock delay (slower)Immediate (reacts in same cycle)
Number of statesGenerally needs more statesGenerally fewer states

Both models are equivalent in computational power and can be converted into each other (they compute the same input–output relations, ignoring the initial-state output of Moore).

mealy-moore
7short5 marks

Explain the closure properties of regular languages.

Closure Properties of Regular Languages

Regular languages are closed under a wide range of operations: applying these operations to regular languages always yields a regular language. Let L1,L2L_1, L_2 be regular over alphabet Σ\Sigma.

  • Union: L1L2L_1 \cup L_2 is regular (combine NFAs with a new start state and ε\varepsilon-moves).
  • Concatenation: L1L2L_1 L_2 is regular (link accepting states of the first NFA to the start of the second).
  • Kleene star: L1L_1^* is regular (loop back accepting states to start).
  • Complement: L1=ΣL1\overline{L_1} = \Sigma^* \setminus L_1 is regular (complete the DFA and swap accepting/non-accepting states).
  • Intersection: L1L2L_1 \cap L_2 is regular (product/Cartesian construction of the two DFAs; also via L1L2\overline{\overline{L_1}\cup\overline{L_2}}).
  • Set difference: L1L2=L1L2L_1 \setminus L_2 = L_1 \cap \overline{L_2} is regular.
  • Reversal: L1RL_1^R is regular (reverse all transitions, swap start and accepting states).
  • Homomorphism and inverse homomorphism preserve regularity.

Significance: Because the regular languages form a Boolean algebra (closed under union, intersection, complement), these closure properties let us build and reason about regular languages compositionally and prove non-regularity by closure arguments.

closure-propertiesregular-languages
8short5 marks

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

Membership Problem

The membership problem for a grammar/language asks: Given a grammar GG (or automaton) and a string ww, does wL(G)w \in L(G)? i.e. can the grammar generate the string? For context-free grammars this problem is decidable, and the CYK algorithm solves it efficiently.

CYK (Cocke–Younger–Kasami) Algorithm

The CYK algorithm decides membership of a string w=a1a2anw = a_1 a_2 \dots a_n in a context-free language. The grammar must first be converted to Chomsky Normal Form (CNF) (rules of the form ABCA \to BC or AaA \to a).

It uses dynamic programming / bottom-up parsing, filling an upper-triangular table V[i][j]V[i][j] where V[i][j]V[i][j] holds the set of non-terminals that can derive the substring aiaja_i \dots a_j.

CYK(w = a1..an, grammar G in CNF):
  for i = 1 to n:                         # length-1 substrings
     V[i][i] = { A : (A -> a_i) in G }
  for len = 2 to n:                       # increasing substring length
     for i = 1 to n-len+1:
        j = i + len - 1
        V[i][j] = {}
        for k = i to j-1:                 # split point
           for each rule A -> B C:
              if B in V[i][k] and C in V[k+1][j]:
                 add A to V[i][j]
  accept if  S (start symbol) in V[1][n]

Result: wL(G)w \in L(G) iff the start symbol SV[1][n]S \in V[1][n].

Time complexity: O(n3G)O(n^3 \cdot |G|), where n=wn = |w| — polynomial, hence the membership problem for CFLs is efficiently decidable.

cykdecidability
9short5 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 denotes all binary strings that end with the symbol 11.

NFA N=(Q,Σ,δ,q0,F)N = (Q, \Sigma, \delta, q_0, F):

  • States: Q={q0,q1}Q = \{q_0, q_1\}
  • Alphabet: Σ={0,1}\Sigma = \{0, 1\}
  • Start state: q0q_0
  • Accepting state: F={q1}F = \{q_1\}

Transition function:

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

Diagram (described): State q0q_0 has self-loops on both 00 and 11 (this realizes (0+1)(0+1)^*, allowing any prefix). On reading a 11, q0q_0 also has a transition to the final state q1q_1, which is the guess that this 11 is the last symbol. q1q_1 has no outgoing transitions.

Working: The machine stays in q0q_0 consuming any combination of 00s and 11s, and nondeterministically moves to the accepting state q1q_1 exactly when the final input symbol is a 11. Thus it accepts precisely the strings ending in 11, e.g. 1,01,11,001,1011, 01, 11, 001, 101 \dots, and rejects strings ending in 00 or the empty string.

nfaregular-expression
10short5 marks

Explain Rice's theorem in brief.

Rice's Theorem

Statement: Every non-trivial semantic (behavioural) property of the language recognized by a Turing machine is undecidable.

Here:

  • A property PP is a set of recursively enumerable languages (it refers to what the machine computes — i.e. its language L(M)L(M) — not to how it is coded).
  • The property is non-trivial if it is true for some TMs but not all — i.e. PP is neither the empty set nor the set of all RE languages.

Then the problem "Does L(M)L(M) have property PP?" — formally deciding {M:L(M)P}\{\langle M\rangle : L(M) \in P\} — is undecidable.

Explanation / Consequences

Rice's theorem generalizes the undecidability of the Halting Problem: we cannot algorithmically test any interesting property of a program's input–output behaviour. The proof reduces the Halting Problem (or ATMA_{TM}) to deciding the property.

Examples of undecidable questions (by Rice's theorem):

  • Is L(M)=L(M) = \emptyset? (Is the language empty?)
  • Is L(M)L(M) regular / finite / infinite?
  • Does MM accept a particular string ww?
  • Are two TMs equivalent (L(M1)=L(M2)L(M_1)=L(M_2))?

Note: The theorem applies only to semantic properties. Syntactic properties (e.g. "does MM have 5 states?" or "does MM ever move left?") are about the machine's description and can be decidable.

rices-theoremdecidability
11short5 marks

Define alphabet, string, and language with examples.

Alphabet, String, and Language

Alphabet (Σ\Sigma): A finite, non-empty set of symbols.

  • Example: Σ={0,1}\Sigma = \{0, 1\} (binary alphabet); Σ={a,b,c}\Sigma = \{a, b, c\}.

String (word): A finite sequence of symbols drawn from an alphabet. The empty string is denoted ε\varepsilon (length 0). The length w|w| is the number of symbols.

  • Example: over Σ={0,1}\Sigma=\{0,1\}, the strings 01100110, 11, and ε\varepsilon are valid; 0110=4|0110| = 4.
  • Σ\Sigma^* denotes the set of all strings over Σ\Sigma (including ε\varepsilon); Σ+=Σ{ε}\Sigma^+ = \Sigma^* \setminus \{\varepsilon\}.

Language: A set of strings over a given alphabet, i.e. any subset of Σ\Sigma^*. A language may be finite or infinite.

  • Example over Σ={0,1}\Sigma=\{0,1\}:
    • L1={0,01,011}L_1 = \{0, 01, 011\} (finite),
    • L2={w:w ends in 1}L_2 = \{w : w \text{ ends in } 1\} (infinite),
    • L3={0n1n:n0}L_3 = \{0^n 1^n : n \ge 0\},
    • \emptyset (the empty language) and {ε}\{\varepsilon\} are both valid languages.
formal-languages
12short5 marks

Differentiate between DFA and NFA.

DFA vs. NFA

Both are finite automata of the form (Q,Σ,δ,q0,F)(Q, \Sigma, \delta, q_0, F) and accept exactly the regular languages, but they differ in how transitions are defined.

AspectDFA (Deterministic)NFA (Non-deterministic)
Transition functionδ:Q×ΣQ\delta: Q \times \Sigma \to Q (exactly one next state)δ:Q×(Σ{ε})2Q\delta: Q \times (\Sigma \cup \{\varepsilon\}) \to 2^Q (a set of next states)
Next stateUnique for each (state, symbol)Zero, one, or many possible states
ε\varepsilon (empty) movesNot allowedAllowed
AcceptanceSingle computation path; accept if it ends in FFAccept if some path ends in FF
Number of statesOften more states neededUsually fewer / more compact
ConstructionHarder to design directlyEasier to design from regular expressions
ExecutionFaster, deterministic simulationNeeds to track a set of states (or backtrack)

Equivalence: Every NFA can be converted to an equivalent DFA by the subset (powerset) construction; an NFA with nn states yields a DFA with at most 2n2^n states. Hence DFA and NFA have the same expressive power — both recognize exactly the class of regular languages.

dfanfa

Frequently asked questions

Where can I find the BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) question paper 2078?
The full BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) 2078 (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) 2078 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) 2078 paper?
The BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) 2078 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.