Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Define context-free grammar (CFG). Convert the following CFG into an equivalent grammar in Chomsky Normal Form (CNF): S -> ASA | aB, A -> B | S, B -> b | epsilon.

Context-Free Grammar (CFG)

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, with VT=V \cap T = \varnothing
  • PP = finite set of productions of the form AαA \to \alpha, where AVA \in V and α(VT)\alpha \in (V \cup T)^*
  • SVS \in V = the start symbol

It is context-free because the left side of every production is a single variable, so a variable can be replaced regardless of context.

Converting to Chomsky Normal Form (CNF)

A grammar is in CNF if every production has the form ABCA \to BC (two variables) or AaA \to a (single terminal). Given grammar:

SASAaB,ABS,BbεS \to ASA \mid aB, \quad A \to B \mid S, \quad B \to b \mid \varepsilon

Step 1 — Add a new start symbol. Introduce S0SS_0 \to S so the start symbol never appears on a right side.

S0S,SASAaB,ABS,BbεS_0 \to S,\quad S \to ASA \mid aB,\quad A \to B \mid S,\quad B \to b \mid \varepsilon

Step 2 — Remove ε\varepsilon-productions. Nullable variables: BB (from BεB \to \varepsilon), and AA (since ABA \to B). Remove BεB \to \varepsilon and add all combinations omitting nullable symbols:

  • SASAS \to ASA gives SASASAASSS \to ASA \mid SA \mid AS \mid S (dropping one or both AA's).
  • SaBS \to aB gives SaBaS \to aB \mid a.
  • ABA \to B stays; nothing new since BB has a non-empty body.

Resulting set:

S0S,  SASASAASSaBa,  ABS,  BbS_0 \to S,\; S \to ASA \mid SA \mid AS \mid S \mid aB \mid a,\; A \to B \mid S,\; B \to b

Step 3 — Remove unit productions. Units are S0S, SS, AB, ASS_0 \to S,\ S \to S,\ A \to B,\ A \to S. Drop SSS \to S (trivial). Substitute the bodies:

  • S0ASASAASaBaS_0 \to ASA \mid SA \mid AS \mid aB \mid a
  • SASASAASaBaS \to ASA \mid SA \mid AS \mid aB \mid a
  • AbA \to b (from ABbA \to B \to b) and AASASAASaBaA \to ASA \mid SA \mid AS \mid aB \mid a (from ASA \to S)
  • BbB \to b

Step 4 — Replace terminals in long bodies. Introduce TaaT_a \to a and replace aa in aBaB by TaT_a, giving bodies TaBT_aB.

Step 5 — Break bodies longer than 2. For ASAASA, introduce A1SAA_1 \to SA, so ASAAA1ASA \to A\,A_1.

Final CNF Grammar

S0AA1SAASTaBaSAA1SAASTaBaAAA1SAASTaBabA1SABbTaa\begin{aligned} S_0 &\to AA_1 \mid SA \mid AS \mid T_aB \mid a \\ S &\to AA_1 \mid SA \mid AS \mid T_aB \mid a \\ A &\to AA_1 \mid SA \mid AS \mid T_aB \mid a \mid b \\ A_1 &\to SA \\ B &\to b \\ T_a &\to a \end{aligned}

Every production now has the form ABCA \to BC or AaA \to a, so the grammar is in Chomsky Normal Form and generates the same language as the original.

cfgchomsky-normal-form
2long10 marks

What is a Pushdown Automaton (PDA)? Design a PDA that accepts the language L = { a^n b^n | n >= 1 } and trace its moves for the string 'aabb'.

Pushdown Automaton (PDA)

A Pushdown Automaton is a finite automaton augmented with an auxiliary stack (LIFO) memory, which gives it more power than a finite automaton and lets it recognize context-free languages. Formally it is a 7-tuple:

M=(Q,Σ,Γ,δ,q0,Z0,F)M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)
  • QQ = finite set of states
  • Σ\Sigma = input alphabet
  • Γ\Gamma = stack alphabet
  • δ:Q×(Σ{ε})×Γ\delta: Q \times (\Sigma \cup \{\varepsilon\}) \times \Gamma \to finite subsets of Q×ΓQ \times \Gamma^* = transition function
  • q0q_0 = start state, Z0Z_0 = initial stack symbol, FQF \subseteq Q = accepting states

PDA for L={anbnn1}L = \{a^n b^n \mid n \ge 1\}

Idea: push a marker for each aa, then pop one for each bb; accept when input ends and the stack is back to its bottom.

Let M=({q0,q1,q2},{a,b},{Z0,A},δ,q0,Z0,{q2})M = (\{q_0, q_1, q_2\}, \{a,b\}, \{Z_0, A\}, \delta, q_0, Z_0, \{q_2\}) (acceptance by final state). Transitions:

#δ\deltaMeaning
1δ(q0,a,Z0)=(q0,AZ0)\delta(q_0, a, Z_0) = (q_0, AZ_0)push first AA
2δ(q0,a,A)=(q0,AA)\delta(q_0, a, A) = (q_0, AA)push more AA's
3δ(q0,b,A)=(q1,ε)\delta(q_0, b, A) = (q_1, \varepsilon)first bb: pop AA
4δ(q1,b,A)=(q1,ε)\delta(q_1, b, A) = (q_1, \varepsilon)pop AA per bb
5δ(q1,ε,Z0)=(q2,Z0)\delta(q_1, \varepsilon, Z_0) = (q_2, Z_0)stack empty of AA's, accept

Trace for the string aabb

ID notation: (state,remaining input,stack)(\text{state}, \text{remaining input}, \text{stack}), stack top on the left.

(q0, aabb, Z0)(q0, abb, AZ0)rule 1 (read a)(q0, bb, AAZ0)rule 2 (read a)(q1, b, AZ0)rule 3 (read b, pop)(q1, ε, Z0)rule 4 (read b, pop)(q2, ε, Z0)rule 5 (ε-move)\begin{aligned} (q_0,\ aabb,\ Z_0) &\vdash (q_0,\ abb,\ AZ_0) && \text{rule 1 (read } a)\\ &\vdash (q_0,\ bb,\ AAZ_0) && \text{rule 2 (read } a)\\ &\vdash (q_1,\ b,\ AZ_0) && \text{rule 3 (read } b\text{, pop)}\\ &\vdash (q_1,\ \varepsilon,\ Z_0) && \text{rule 4 (read } b\text{, pop)}\\ &\vdash (q_2,\ \varepsilon,\ Z_0) && \text{rule 5 (}\varepsilon\text{-move)} \end{aligned}

The input is fully consumed and the machine is in accepting state q2q_2, so aabb is accepted. Hence MM accepts L={anbnn1}L = \{a^n b^n \mid n \ge 1\}.

pdacontext-free-languages
3long10 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)
  • QQ = finite set of states
  • Σ\Sigma = input alphabet (does not contain the blank)
  • Γ\Gamma = tape alphabet, ΣΓ\Sigma \subseteq \Gamma, with blank BΓB \in \Gamma
  • δ:Q×ΓQ×Γ×{L,R}\delta: Q \times \Gamma \to Q \times \Gamma \times \{L, R\} = transition function (write a symbol, move head Left or Right)
  • q0Qq_0 \in Q = start state, BB = blank symbol, FQF \subseteq Q = accepting (halting) states

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

Strategy: repeatedly mark the leftmost unmarked aa as XX, the leftmost bb as YY, the leftmost cc as ZZ, then return to the left and repeat. This matches one aa, one bb, one cc per pass, guaranteeing equal counts in correct order. Accept when only X,Y,ZX, Y, Z remain.

States: q0q_0 (find aa), q1q_1 (scan right for bb), q2q_2 (scan right for cc), q3q_3 (return left), q4q_4 (verify all marked), qaccq_{acc}.

StateReadWriteMoveNextAction
q0q_0aaXXRq1q_1mark an aa
q0q_0YYYYRq4q_4no aa left, verify
q1q_1a,Ya,YsameRq1q_1skip to a bb
q1q_1bbYYRq2q_2mark a bb
q2q_2b,Zb,ZsameRq2q_2skip to a cc
q2q_2ccZZLq3q_3mark a cc
q3q_3a,b,Y,Za,b,Y,ZsameLq3q_3move left
q3q_3XXXXRq0q_0back at start, repeat
q4q_4Y,ZY,ZsameRq4q_4ensure no a,b,ca,b,c remain
q4q_4BBBBRqaccq_{acc}accept

If at any point the expected symbol is missing (e.g. a bb before all aa's are matched, or leftover a/b/ca/b/c), no transition applies and the machine halts and rejects.

Transition Diagram (described)

Nodes q0q1q2q3q0q_0 \to q_1 \to q_2 \to q_3 \to q_0 form a loop: each cycle converts one aXa\to X, one bYb\to Y, one cZc\to Z. The arc q0q4qaccq_0 \to q_4 \to q_{acc} (taken when the first remaining symbol is YY and the rest are only Y,Z,BY,Z,B) leads to the accepting state. Self-loops on q1,q2,q3q_1, q_2, q_3 skip over already-marked or not-yet-needed symbols.

Working on aabbcc

Pass 1: aabbccXaYbZc\underline{a}abbcc \Rightarrow XaYbZc \dots — first a,b,ca,b,c marked. Pass 2: remaining a,b,ca,b,c marked as X,Y,ZX,Y,Z. Tape becomes XXYYZZXXYYZZ; in q4q_4 the head scans only Y,ZY,Z then a blank, reaching qaccq_{acc}. Thus the string is accepted.

Because this TM both writes and reads and may visit a cell many times, it recognizes the context-sensitive / recursively enumerable language LL, which is not context-free.

turing-machinerecursively-enumerable
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Write a regular expression for strings over {0,1} that contain at least one '0' and at least one '1'.

We need strings over {0,1}\{0,1\} containing at least one 0 and at least one 1. A clean regular expression is:

(0+1)0(0+1)1(0+1)  +  (0+1)1(0+1)0(0+1)(0+1)^*\,0\,(0+1)^*\,1\,(0+1)^* \;+\; (0+1)^*\,1\,(0+1)^*\,0\,(0+1)^*

The first term covers strings where some 0 appears before some 1; the second covers strings where a 1 appears before a 0. Their union therefore guarantees the presence of both symbols.

(Equivalently, in extended notation: all strings except those with no 0 or no 1, i.e. (0+1)(1+0)(0+1)^* \setminus (1^* + 0^*).)

regular-expression
5short5 marks

State Arden's theorem and explain its use in obtaining a regular expression from a finite automaton.

Arden's Theorem

Statement: Let PP and QQ be two regular expressions over an alphabet Σ\Sigma. If PP does not contain the empty string ε\varepsilon (i.e. εP\varepsilon \notin P), then the equation

R=Q+RPR = Q + RP

has a unique solution:

R=QPR = QP^*

Use in Obtaining a Regular Expression from a Finite Automaton

For a finite automaton, write one equation per state describing the strings that reach that state. For each state qq, its equation is the sum, over all incoming transitions, of (source-state expression \cdot input symbol); the start state's equation also includes ε\varepsilon.

This yields a system of simultaneous equations of the form R=Q+RPR = Q + RP. Using Arden's theorem, we repeatedly substitute and solve each self-referential equation by replacing R=Q+RPR = Q + RP with R=QPR = QP^*, eliminating variables one by one. The expression finally obtained for the final (accepting) state is the regular expression denoting the language accepted by the automaton.

Why the εP\varepsilon \notin P condition matters: it ensures uniqueness; if PP contained ε\varepsilon, infinitely many solutions would satisfy the equation.

arden-theoremregular-expression
6short5 marks

What is an ambiguous grammar? Show with an example that a grammar is ambiguous.

Ambiguous Grammar

A context-free grammar GG is said to be ambiguous if there exists at least one string wL(G)w \in L(G) that has two or more distinct derivation trees (equivalently, two distinct leftmost or two distinct rightmost derivations). Ambiguity is a property of the grammar, not of the language.

Example

Consider the expression grammar:

EE+EEEidE \to E + E \mid E * E \mid id

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

Parse 1 (treats ++ as the top operator):

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

Parse 2 (treats * as the top operator):

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

Since the same string id+ididid + id * id admits two distinct parse trees (one grouping as id+(idid)id + (id * id), the other as (id+id)id(id + id) * id), the grammar is ambiguous.

ambiguitycfg
7short5 marks

Eliminate left recursion from the grammar A -> Aa | b.

Eliminating Left Recursion from AAabA \to Aa \mid b

The production AAaA \to Aa is immediately left-recursive (the variable AA appears as the leftmost symbol of its own body).

General rule: a rule of the form

AAαβA \to A\alpha \mid \beta

(where β\beta does not start with AA) is rewritten using a new variable AA' as:

AβA,AαAεA \to \beta A', \qquad A' \to \alpha A' \mid \varepsilon

Applying it here with α=a\alpha = a and β=b\beta = b:

AbA,AaAε\boxed{A \to b\,A', \qquad A' \to a\,A' \mid \varepsilon}

This grammar is right-recursive and generates exactly the same language {bann0}\{b a^n \mid n \ge 0\} (i.e. bb followed by zero or more aa's), but is now suitable for top-down (e.g. recursive-descent / LL) parsing.

cfgleft-recursion
8short5 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 \to a\,\alpha

where aa is a single terminal and αV\alpha \in V^* is a (possibly empty) string of variables. Thus every body begins with exactly one terminal followed only by non-terminals.

Conversion Procedure (CFG → GNF)

Pre-requisite: first convert the grammar to Chomsky Normal Form and remove ε\varepsilon-productions, unit productions, and useless symbols.

Step 1 — Order the variables. Rename the variables A1,A2,,AnA_1, A_2, \dots, A_n.

Step 2 — Make productions increasing in index. Modify productions so that every rule AiAjγA_i \to A_j \gamma has j>ij > i:

  • If j<ij < i, substitute every production of AjA_j into the body of AiA_i, then repeat.
  • If j=ij = i, it is left recursion; eliminate it using a new variable BiB_i:
AiββBi,BiααBiA_i \to \beta \mid \beta B_i, \qquad B_i \to \alpha \mid \alpha B_i

(where AiAiαβA_i \to A_i\alpha \mid \beta).

Step 3 — Make leading symbols terminals (back-substitution). Now AnA_n's bodies already start with a terminal. Working backwards from AnA_n to A1A_1, substitute the (already-GNF) productions of AjA_j into any rule whose body starts with AjA_j, so that every leading symbol becomes a terminal.

Step 4 — Fix the new variables BiB_i. Apply the same back-substitution to the introduced BiB_i variables so their bodies also begin with a terminal.

The result is an equivalent grammar in GNF. GNF is important because it guarantees each derivation step consumes exactly one input terminal, which directly yields an equivalent PDA and bounds derivation length to w|w| steps for a string ww.

greibach-normal-formcfg
9short5 marks

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

Instantaneous Description (ID) of a PDA

An instantaneous description captures the complete momentary configuration of a PDA. It is a triple:

(q,w,γ)(q, w, \gamma)
  • qq = the current state
  • ww = the remaining unread input string
  • γ\gamma = the current stack contents (conventionally written with the top of the stack on the left)

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

(q, aw, Zγ)    (p, w, βγ).(q,\ a w,\ Z\gamma) \;\vdash\; (p,\ w,\ \beta\gamma).

\vdash^* denotes zero or more moves.

Acceptance by Final State

Starting from (q0,w,Z0)(q_0, w, Z_0), the PDA accepts ww by final state if there is a sequence of moves leading to an accepting state, regardless of the stack contents:

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

i.e. the whole input is consumed and the machine ends in some final state pFp \in F.

Acceptance by Empty Stack

The PDA accepts ww by empty stack if, after consuming all input, the stack becomes completely empty (the set FF is irrelevant here):

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

Equivalence: the two acceptance modes define the same class of languages (the context-free languages); any PDA accepting by final state can be converted to one accepting by empty stack and vice versa.

pda
10short5 marks

Explain the working of a multi-tape Turing Machine.

Multi-Tape Turing Machine

A multi-tape Turing Machine has k2k \ge 2 tapes, each with its own independent read/write head. The machine reads the symbols under all kk heads simultaneously and, in one move, can write a new symbol on each tape and move each head independently Left, Right, or stay (S).

Working / Transition Function

For a kk-tape machine the transition function is

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

On a single step the control unit, based on the current state and the kk scanned symbols (a1,,ak)(a_1, \dots, a_k), does the following at once:

  1. Moves to a new state,
  2. Writes a symbol on each of the kk tapes,
  3. Moves each of the kk heads independently.

Initially the input is placed on tape 1 and the other tapes hold blanks; the extra tapes serve as scratch / working memory, which often makes algorithms much simpler to express (e.g. copying, counting, or comparing substrings).

Power

A multi-tape TM is no more powerful than a standard single-tape TM: any kk-tape TM can be simulated by a single-tape TM (storing the kk tapes interleaved on one tape with head-position markers). The simulation costs at most a quadratic slowdown (O(T2)O(T^2) steps to simulate TT steps), so the class of languages recognized (recursively enumerable) is identical. Multi-tape machines are mainly a convenience that simplifies design and improves time efficiency.

turing-machine
11short5 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 on any input. It takes as input an encoding M\langle M \rangle of an arbitrary TM MM together with an encoded input string ww, written as M,w\langle M, w \rangle, and then:

  • simulates the computation of MM on ww step by step, and
  • accepts/halts exactly when MM would accept/halt on ww (and loops if MM loops).

Formally, UU on M,w\langle M, w \rangle produces the same result that MM produces on ww. UU keeps three pieces of information on its tape: the encoded description of MM, the simulated tape contents of MM, and MM's current state.

Significance

  1. Stored-program concept: the UTM shows that a single fixed machine can run any algorithm if the program (the description of MM) is supplied as data. This is the theoretical foundation of the modern general-purpose, stored-program computer (von Neumann architecture).
  2. Existence of a universal model: it proves computation is programmable — one machine, many tasks — rather than needing a new machine per problem.
  3. Undecidability: the UTM is central to proving the Halting Problem undecidable; the universal/diagonal construction shows there is no algorithm to decide whether an arbitrary MM halts on ww.
  4. It establishes the notion of a recursively enumerable universal language Lu={M,wM accepts w}L_u = \{\langle M, w\rangle \mid M \text{ accepts } w\}, which is RE but not recursive.
turing-machineuniversal-tm
12short5 marks

Differentiate between recursive and recursively enumerable languages.

Recursive vs Recursively Enumerable Languages

Both classes are defined in terms of Turing Machines, but differ in whether the TM is guaranteed to halt.

AspectRecursive (Decidable)Recursively Enumerable (RE)
TM behaviourA TM always halts on every input — it halts and accepts strings in LL, and halts and rejects strings not in LL.A TM halts and accepts strings in LL, but may run forever (loop) on strings not in LL.
DecidabilityThe language is decidable; membership can always be decided.The language is only semi-decidable (recognizable); membership can be confirmed but non-membership may never be confirmed.
Also calledDecidable / Turing-decidable.Turing-recognizable / Type-0.
Closure under complementClosed — if LL is recursive, so is L\overline{L}.Not closed under complement in general.
RelationshipEvery recursive language is RE.RE is a strict superset: there exist RE languages that are not recursive (e.g. the universal language LuL_u, the Halting language).

Key theorem: LL is recursive iff both LL and its complement L\overline{L} are recursively enumerable.

Example: {anbncnn1}\{a^n b^n c^n \mid n \ge 1\} is recursive (decidable). The Halting Problem language is recursively enumerable but not recursive.

recursiverecursively-enumerable

Frequently asked questions

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