Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 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 unbounded stack memory. The stack lets it count or match symbols, so a PDA recognizes exactly the 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, FF = set of final states

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

Idea: push one AA for every aa read; for every bb read, pop one AA. Accept (by final state) when the stack is restored to Z0Z_0 after the input ends.

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

  1. δ(q0,a,Z0)={(q0,AZ0)}\delta(q_0, a, Z_0) = \{(q_0, AZ_0)\} — first aa, push AA
  2. δ(q0,a,A)={(q0,AA)}\delta(q_0, a, A) = \{(q_0, AA)\} — more aa's, keep pushing
  3. δ(q0,b,A)={(q1,ε)}\delta(q_0, b, A) = \{(q_1, \varepsilon)\} — first bb, pop one AA
  4. δ(q1,b,A)={(q1,ε)}\delta(q_1, b, A) = \{(q_1, \varepsilon)\} — more bb's, keep popping
  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

Using instantaneous descriptions (state,remaining input,stack)(\text{state}, \text{remaining input}, \text{stack}) with stack top written leftmost:

StepIDRule used
0(q0, aabb, Z0)(q_0,\ aabb,\ Z_0)start
1(q0, abb, AZ0)(q_0,\ abb,\ AZ_0)rule 1
2(q0, bb, AAZ0)(q_0,\ bb,\ AAZ_0)rule 2
3(q1, b, AZ0)(q_1,\ b,\ AZ_0)rule 3
4(q1, ε, Z0)(q_1,\ \varepsilon,\ Z_0)rule 4
5(q2, ε, Z0)(q_2,\ \varepsilon,\ Z_0)rule 5

The input is fully consumed and the PDA halts in final state q2q_2, so aabb is accepted. Since the number of aa's pushed must equal the number of bb's popped before reaching q2q_2, MM accepts exactly {anbnn1}\{a^n b^n \mid n \ge 1\}.

pdacontext-free-languages
2long10 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 blank BB)
  • Γ\Gamma = tape alphabet, ΣΓ\Sigma \subseteq \Gamma, BΓB \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, BB = blank symbol, FF = set of accepting (halt) states

The TM has an infinite tape and a read/write head; it accepts an input if it halts in a final state. Since L={anbncn}L = \{a^n b^n c^n\} is not context-free, a PDA cannot accept it, but a TM can.

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

Strategy: repeatedly cross off one aa (mark as XX), then the matching bb (mark YY), then the matching cc (mark ZZ). Return to the left and repeat until no aa's remain. Then verify nothing but Y/ZY/Z is left.

States: {q0,q1,q2,q3,q4,q5}\{q_0,q_1,q_2,q_3,q_4,q_5\}, q5q_5 accepting. Tape alphabet {a,b,c,X,Y,Z,B}\{a,b,c,X,Y,Z,B\}.

q0, a -> q1, X, R     ; mark an a, scan right for a b
q1, a -> q1, a, R
q1, Y -> q1, Y, R
q1, b -> q2, Y, R     ; mark matching b, scan right for a c
q2, b -> q2, b, R
q2, Z -> q2, Z, R
q2, c -> q3, Z, L     ; mark matching c, go back left
q3, (a|b|Y|Z) -> q3, same, L
q3, X -> q0, X, R     ; reached leftmost X, restart on next a
q0, Y -> q4, Y, R     ; no more a's: only Y/Z should remain
q4, Y -> q4, Y, R
q4, Z -> q4, Z, R
q4, B -> q5, B, R     ; ACCEPT (equal counts, correct order)

If at any point the expected symbol is missing (e.g. a bb has no matching cc, or counts differ), δ\delta is undefined and the machine halts in a non-final state, rejecting the string.

Working / Transition Diagram (described)

Think of a cycle: q0a/X,Rq1b/Y,Rq2c/Z,Lq3X/X,Rq0q_0 \xrightarrow{a/X,R} q_1 \xrightarrow{b/Y,R} q_2 \xrightarrow{c/Z,L} q_3 \xrightarrow{X/X,R} q_0. Each pass through the loop converts one aa, one bb and one cc into X,Y,ZX,Y,Z. When q0q_0 instead reads YY, the input has been fully matched; it enters q4q_4 to scan the trailing YY's and ZZ's and, on reading blank BB, moves to accepting state q5q_5.

Example aabbcc becomes XaYbZcXXYYZZ after two cycles, then q4q_4 verifies and accepts.

turing-machinerecursively-enumerable
3long10 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

Kleene's Theorem states that a language is regular iff it can be described by a regular expression iff it is accepted by some finite automaton (DFA/NFA/ε\varepsilon-NFA). Thus regular expressions and finite automata have exactly the same expressive power and are inter-convertible:

  • RE \to ε\varepsilon-NFA: Thompson's construction.
  • NFA/ε\varepsilon-NFA \to DFA: subset construction.
  • DFA \to RE: state elimination / Arden's theorem.

For every RE there is an ε\varepsilon-NFA (Thompson's construction)

Proof by induction on the structure of the regular expression rr. Base cases:

  • r=r = \varnothing: an automaton with start and non-accepting state, no transitions.
  • r=εr = \varepsilon: start state that is also accepting.
  • r=ar = a (aΣa \in \Sigma): start state with an aa-edge to a single accepting state.

Inductive step (let N(s),N(t)N(s),N(t) be ε\varepsilon-NFAs for sub-expressions s,ts,t):

  • Union s+ts+t: new start state with ε\varepsilon-edges to the starts of N(s)N(s) and N(t)N(t); their accepting states ε\varepsilon-link to a new final state.
  • Concatenation stst: connect the accepting state of N(s)N(s) by ε\varepsilon to the start of N(t)N(t).
  • Star ss^{*}: new start/final state, with ε\varepsilon-edges into N(s)N(s) and a loop-back ε\varepsilon-edge from its accepting state, plus an ε\varepsilon-edge allowing ε\varepsilon itself.

Each case preserves the language, so by induction every RE has an equivalent ε\varepsilon-NFA. \blacksquare

Converting (a+b)ab(a+b)^{*}ab to a finite automaton

The RE means: any string over {a,b}\{a,b\} ending in ab. A simple NFA (start q0q_0):

Stateaabb
q0\to q_0{q0,q1}\{q_0,q_1\}{q0}\{q_0\}
q1q_1\varnothing{q2}\{q_2\}
q2*q_2\varnothing\varnothing

q0q_0 loops on a,ba,b (the (a+b)(a+b)^{*} part) and non-deterministically guesses the final ab by going q0aq1bq2q_0 \xrightarrow{a} q_1 \xrightarrow{b} q_2.

Determinized (DFA) by subset construction:

DFA stateaabb
A={q0}A=\{q_0\} (start)BBAA
B={q0,q1}B=\{q_0,q_1\}BBCC
C={q0,q2}C=\{q_0,q_2\} (final)BBAA

Accepting state CC contains q2q_2. This 3-state DFA accepts exactly the strings ending in ab, confirming the equivalence.

regular-expressionepsilon-nfa
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

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

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 derivations or two distinct rightmost derivations).

Example

Consider the grammar:

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

The string id + id * id has two different leftmost derivations / parse trees:

Derivation 1 (group ++ first):

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

Parse tree: root +, with right child a * subtree → corresponds to id+(idid)id + (id * id).

Derivation 2 (group * first):

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

Parse tree: root *, with left child a + subtree → corresponds to (id+id)id(id + id) * id.

Since the same string id + id * id yields two distinct parse trees, the grammar is ambiguous. (Ambiguity can often be removed by introducing precedence/associativity, e.g. EE+TT, TTFF, FidE \to E + T \mid T,\ T \to T * F \mid F,\ F \to id.)

ambiguitycfg
5short5 marks

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

Eliminating Left Recursion from AAabA \to Aa \mid b

General rule: for a left-recursive rule AAαβA \to A\alpha \mid \beta (where β\beta does not start with AA), replace it with:

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

Here α=a\alpha = a and β=b\beta = b. Substituting:

AbAA \to b\,A' AaAεA' \to a\,A' \mid \varepsilon

Verification: the original grammar generates bab a^{*} (a bb followed by any number of aa's). The new grammar derives AbAbaAbanA \Rightarrow bA' \Rightarrow b\,a\,A' \Rightarrow \dots \Rightarrow b a^{n}, the same language, but the new productions are right-recursive, so left recursion has been removed (making the grammar suitable for top-down/LL parsing).

cfgleft-recursion
6short5 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 non-terminals. The grammar must be ε\varepsilon-free (except possibly SεS \to \varepsilon). GNF guarantees that each derivation step produces exactly one terminal, which is useful for proving the CFG–PDA equivalence and for top-down parsing.

Conversion Procedure

  1. Pre-process: remove ε\varepsilon-productions, unit productions, and useless symbols. Convert the grammar to Chomsky Normal Form (CNF) (ABCA \to BC or AaA \to a) as a clean starting point.
  2. Order the non-terminals A1,A2,,AnA_1, A_2, \dots, A_n.
  3. Remove left recursion and substitute so every production's right-hand side starts with a higher-numbered non-terminal. For each ii, for each rule AiAjγA_i \to A_j \gamma with j<ij < i, replace AjA_j by all of its right-hand sides. Eliminate any resulting immediate left recursion AiAiαβA_i \to A_i\alpha \mid \beta using a new variable BiB_i: AiβBi, BiαBiεA_i \to \beta B_i,\ B_i \to \alpha B_i \mid \varepsilon (rewritten to avoid ε\varepsilon).
  4. Back-substitute from the highest-numbered non-terminal downward. After step 3, AnA_n's productions begin with a terminal; substitute these into the productions of An1,An2,A_{n-1}, A_{n-2}, \dots so that every production begins with a terminal.
  5. Fix the new variables BiB_i similarly so their productions also begin with a terminal.

The result is an equivalent grammar in which every production is of the form AaαA \to a\,\alpha, i.e. in Greibach Normal Form.

greibach-normal-formcfg
7short5 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 configuration of a PDA at a moment in time. It is a triple

(q,w,γ)(q, w, \gamma)
  • qq = current state
  • ww = the remaining (unread) portion of the input string
  • γ\gamma = current contents of the stack (top symbol written leftmost)

A move is written (q,aw,Xβ)(p,w,αβ)(q, aw, X\beta) \vdash (p, w, \alpha\beta) when δ(q,a,X)\delta(q,a,X) contains (p,α)(p,\alpha). The relation \vdash^{*} is the reflexive–transitive closure (zero or more moves).

Acceptance by Final State

The language accepted by final state is:

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

The input is accepted if, after consuming all of ww, the PDA is in some accepting state qFq \in F; the stack contents γ\gamma are irrelevant.

Acceptance by Empty Stack

The language accepted by empty stack is:

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

Here the input is accepted if, after consuming all of ww, the stack becomes empty, regardless of the state. The set FF is not used.

Note: the two acceptance criteria are equivalent in power — for every PDA accepting by final state there is a PDA accepting the same language by empty stack, and vice versa.

pda
8short5 marks

Explain the working of a multi-tape Turing Machine.

Multi-tape Turing Machine

A multi-tape Turing Machine has kk tapes (k1k \ge 1), each with its own independent read/write head. Initially the input is placed on tape 1 and the other tapes are blank.

Transition function: in one step the machine reads the kk symbols currently under all heads, and depending on the current state and these kk symbols it:

  1. changes state,
  2. writes a (possibly new) symbol on each of the kk tapes,
  3. moves each head independently Left, Right, or Stays put.

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

Advantage: extra tapes act as scratch/work space, often making algorithms simpler and faster. For example, {anbncn}\{a^n b^n c^n\} or palindrome checking, or copying data, is much easier with separate work tapes than on a single tape.

Equivalence: 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 tracks/head positions on one tape). The simulation is at most a polynomial (quadratic) slowdown: tt steps of a kk-tape machine take O(t2)O(t^2) steps on the single-tape machine. Hence multi-tape TMs recognize exactly the recursively enumerable languages, confirming the Church–Turing thesis.

turing-machine
9short5 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 MM on any input ww. It takes as input an encoding M,w\langle M, w \rangle — a description of MM's states and transition function together with the input ww — and then carries out, step by step, exactly what MM would do on ww:

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

That is, UU accepts iff MM accepts ww, halts iff MM halts, and loops iff MM loops.

Significance

  • Programmable / stored-program concept: A single fixed machine can perform any computation by reading a description of the machine to be run as data. This is the theoretical foundation of the general-purpose, stored-program digital computer (von Neumann architecture), where programs and data live in the same memory.
  • Universality of computation: It shows that one machine is enough to compute everything computable, supporting the Church–Turing thesis.
  • Basis for undecidability: The encoding-and-simulation idea behind the UTM is exactly what makes it possible to prove that the Halting Problem and many other problems are undecidable (by diagonalization / reduction). Hence the UTM is central both to what computers can do and to the limits of what they cannot do.
turing-machineuniversal-tm
10short5 marks

Differentiate between recursive and recursively enumerable languages.

Recursive vs. Recursively Enumerable Languages

Both classes are defined by Turing Machines, differing in whether the TM is guaranteed to halt.

AspectRecursive (Decidable)Recursively Enumerable (Turing-recognizable)
TM behaviourA TM always halts: accepts strings in LL and rejects (halts) strings not in LLA TM halts and accepts strings in LL, but may loop forever on strings not in LL
DecisionThe language is decidable — there is an algorithm that always answers yes/noOnly semi-decidable — yes-answers are guaranteed, no-answers may never come
ComplementClosed under complement: if LL is recursive, so is L\overline{L}Not closed under complement: LL r.e. does not imply L\overline{L} r.e.
RelationshipEvery recursive language is recursively enumerableThe converse is false — some r.e. languages are not recursive
Example{anbncn}\{a^n b^n c^n\}, any CFL, the membership problem for a TM that always haltsThe language LuL_u (acceptance / Halting problem ATMA_{TM}) is r.e. but not recursive

Key fact: A language LL is recursive iff both LL and its complement L\overline{L} are recursively enumerable. The Halting problem shows the inclusion Recursive \subsetneq Recursively Enumerable is strict.

recursiverecursively-enumerable
11short5 marks

Define Mealy and Moore machines and differentiate between them.

Mealy and Moore Machines

Both are finite-state machines with output (transducers). They are 6-tuples (Q,Σ,Δ,δ,λ,q0)(Q, \Sigma, \Delta, \delta, \lambda, q_0) where Δ\Delta is the output alphabet and λ\lambda is the output function; they differ in how λ\lambda is defined.

Moore machine: output depends only on the current state.

λ:QΔ(output=λ(q))\lambda: Q \to \Delta \qquad (\text{output} = \lambda(q))

Mealy machine: output depends on the current state and the current input.

λ:Q×ΣΔ(output=λ(q,a))\lambda: Q \times \Sigma \to \Delta \qquad (\text{output} = \lambda(q, a))

Differences

Mealy MachineMoore Machine
Output associated with transitions (state + input)Output associated with states only
λ:Q×ΣΔ\lambda: Q \times \Sigma \to \Deltaλ:QΔ\lambda: Q \to \Delta
For input of length nn, produces nn outputsFor input of length nn, produces n+1n+1 outputs (includes start-state output)
Output changes immediately with input (reacts faster)Output changes only after a state change (one step delay)
Usually needs fewer states for the same taskUsually needs more states
Output written on edges of the transition diagramOutput written inside the state circles

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

mealy-moore
12short5 marks

Explain the closure properties of regular languages.

Closure Properties of Regular Languages

The class of regular languages is closed under an operation if applying that operation to regular language(s) always yields a regular language. Regular languages are closed under the following operations (each provable by constructing an FA or RE for the result):

  1. Union: if L1,L2L_1, L_2 are regular, L1L2L_1 \cup L_2 is regular. (RE: r1+r2r_1 + r_2; or an NFA with a new start state ε\varepsilon-linked to both.)
  2. Concatenation: L1L2L_1 L_2 is regular. (RE: r1r2r_1 r_2; link accepting states of M1M_1 to the start of M2M_2.)
  3. Kleene Star: L1L_1^{*} is regular. (RE: r1r_1^{*}.)
  4. Complement: L1=ΣL1\overline{L_1} = \Sigma^{*} \setminus L_1 is regular. (Take a complete DFA and swap accepting / non-accepting states.)
  5. Intersection: L1L2L_1 \cap L_2 is regular. (Product/cross construction of the two DFAs; also follows from union + complement by De Morgan: L1L2=L1L2L_1 \cap L_2 = \overline{\overline{L_1} \cup \overline{L_2}}.)
  6. Difference: L1L2=L1L2L_1 - L_2 = L_1 \cap \overline{L_2} is regular.
  7. Reversal: L1RL_1^{R} is regular. (Reverse all edges, swap start/final.)
  8. Homomorphism and inverse homomorphism also preserve regularity.

These closure properties are useful both to prove a language is regular (by building it from known regular pieces) and to prove non-regularity (e.g., if LRL \cap R were non-regular for a regular RR, then LL cannot be regular).

closure-propertiesregular-languages

Frequently asked questions

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