Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Define finite automata. Construct a DFA that accepts all strings over {0, 1} having an even number of 0's and an even number of 1's. Show the transition table and transition diagram.

Finite Automata

A Finite Automaton (FA) is an abstract mathematical model of a machine with a finite amount of memory used to recognize regular languages. Formally, a Deterministic Finite Automaton (DFA) is a 5-tuple:

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

where:

  • QQ = finite set of states
  • Σ\Sigma = finite input alphabet
  • δ:Q×ΣQ\delta : Q \times \Sigma \to Q = transition function
  • q0Qq_0 \in Q = start state
  • FQF \subseteq Q = set of accepting (final) states

DFA for even number of 0's and even number of 1's

We track parity of 0's and parity of 1's. There are four combinations, giving four states:

  • AA = (even 0's, even 1's) — start and accepting
  • BB = (odd 0's, even 1's)
  • CC = (even 0's, odd 1's)
  • DD = (odd 0's, odd 1's)

Reading a 0 flips the 0-parity; reading a 1 flips the 1-parity.

Transition Table

State01
A\to *ABBCC
BBAADD
CCDDAA
DDCCBB

(\to = start state, * = final state). F={A}F = \{A\}.

Transition Diagram (described)

Four states A,B,C,DA, B, C, D arranged as a square. Horizontal edges (labelled 0) connect ABA\leftrightarrow B and CDC\leftrightarrow D (toggling 0-parity). Vertical edges (labelled 1) connect ACA\leftrightarrow C and BDB\leftrightarrow D (toggling 1-parity). AA has an incoming start arrow and is drawn with a double circle (accepting).

Example: string 0011A0B0A1C1AA\xrightarrow{0}B\xrightarrow{0}A\xrightarrow{1}C\xrightarrow{1}A, ends in AA → accepted (two 0's, two 1's, both even). String 010 ends in CC → rejected.

finite-automatadfa
2long10 marks

What is a Non-deterministic Finite Automaton (NFA)? Construct an NFA that accepts the set of strings over {0, 1} ending with '01' and convert it into an equivalent DFA using the subset construction method.

Non-deterministic Finite Automaton (NFA)

An NFA is a 5-tuple M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F) where the transition function maps a state and an input symbol to a set of states:

δ:Q×Σ2Q\delta : Q \times \Sigma \to 2^{Q}

From a given state on a given symbol an NFA may move to zero, one, or several states (non-determinism). A string is accepted if some sequence of choices leads to a final state. NFAs accept exactly the regular languages, the same class as DFAs.

NFA for strings ending with 01

N=({q0,q1,q2},{0,1},δ,q0,{q2})N = (\{q_0, q_1, q_2\}, \{0,1\}, \delta, q_0, \{q_2\})

NFA Transition Table

State01
q0\to q_0{q0,q1}\{q_0, q_1\}{q0}\{q_0\}
q1q_1\emptyset{q2}\{q_2\}
q2*q_2\emptyset\emptyset

q0q_0 loops on 0 and 1 (guessing the rest of the string), branches to q1q_1 on a 0, then q2q_2 on the following 1.

Subset Construction (NFA → DFA)

Start from {q0}\{q_0\} and compute reachable subsets.

DFA State01
A={q0}\to 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}=A\{q_0\}=A

Accepting states: any subset containing q2q_2, i.e. CC. F={C}F=\{C\}.

Resulting DFA

  • States: A,B,CA, B, C
  • Start: AA, Final: CC

Diagram (described): AA on 0 → BB, on 1 → AA (self-loop). BB on 0 → BB (self-loop), on 1 → CC. CC (double circle) on 0 → BB, on 1 → AA.

Check: 001A0B0B1CA\xrightarrow{0}B\xrightarrow{0}B\xrightarrow{1}C → accepted.

nfadfasubset-construction
3long10 marks

State and prove the Pumping Lemma for regular languages. Using it, prove that the language L = { a^n b^n | n >= 0 } is not regular.

Pumping Lemma for Regular Languages

Statement. If LL is a regular language, then there exists a constant p1p \ge 1 (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. xyizLxy^{i}z \in L for all i0i \ge 0.

Proof (sketch)

Since LL is regular, there is a DFA MM with pp states accepting LL. Take any wLw \in L with wp|w| \ge p. While reading ww, MM visits w+1>p|w|+1 > p states, so by the pigeonhole principle some state qq is repeated within the first pp symbols. Let:

  • xx = prefix read before first visiting qq,
  • yy = part read on the loop from qq back to qq (y1|y|\ge 1, and xyp|xy|\le p),
  • zz = remainder.

The loop labelled yy can be traversed any number of times, so MM also accepts xyizxy^{i}z for every i0i \ge 0. Hence the three conditions hold. \blacksquare

Proving L={anbnn0}L = \{a^{n}b^{n} \mid n \ge 0\} is not regular

Proof by contradiction. Assume LL is regular with pumping length pp.

Choose w=apbpLw = a^{p}b^{p} \in L, with w=2pp|w| = 2p \ge p. By the lemma w=xyzw = xyz with xyp|xy| \le p and y1|y| \ge 1.

Because xyp|xy| \le p, the substring xyxy lies entirely within the first pp symbols, which are all aa's. Therefore y=aky = a^{k} for some k1k \ge 1.

Pump with i=2i = 2:

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

Since k1k \ge 1, this string has more aa's than bb's, so ap+kbpLa^{p+k}b^{p} \notin L. This contradicts condition (3) of the pumping lemma.

Therefore the assumption is false, and L={anbnn0}L = \{a^{n}b^{n} \mid n \ge 0\} is not regular. \blacksquare

pumping-lemmaregular-languages
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Define alphabet, string, and language with examples.

  • 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 and has length 0. Example: over {0,1}\{0,1\}, 0110 is a string of length 4; ε\varepsilon is the empty string.
  • Language: a set of strings over an alphabet, i.e. any subset of Σ\Sigma^{*} (the set of all strings over Σ\Sigma). A language may be finite or infinite. Example: L={w{0,1}w has even length}L = \{ w \in \{0,1\}^{*} \mid w \text{ has even length} \}, or L={anbnn0}L = \{a^{n}b^{n} \mid n \ge 0\}.
formal-languages
5short5 marks

Differentiate between DFA and NFA.

DFA vs NFA

FeatureDFANFA
Transition functionδ:Q×ΣQ\delta : Q \times \Sigma \to Q (single next state)δ:Q×Σ2Q\delta : Q \times \Sigma \to 2^{Q} (set of states)
Moves per (state, symbol)Exactly oneZero, one, or many
ε\varepsilon-transitionsNot allowedAllowed (in ε\varepsilon-NFA)
DeterminismDeterministic — next move uniquely definedNon-deterministic — may have choices
AcceptanceUnique path; accept if it ends in a final stateAccept if some path ends in a final state
Number of statesGenerally moreGenerally fewer / easier to design
ImplementationDirectly implementableMust usually be converted to DFA

Important: despite the differences, DFA and NFA have equal expressive power — both accept exactly the class of regular languages, and every NFA can be converted to an equivalent DFA via subset construction (with up to 2n2^{n} states).

dfanfa
6short5 marks

Construct a DFA that accepts all binary strings ending with '00'.

DFA accepting binary strings ending with 00

Track how many trailing 0's have been seen (0, 1, or 2\ge 2).

M=({q0,q1,q2},{0,1},δ,q0,{q2})M = (\{q_0, q_1, q_2\}, \{0,1\}, \delta, q_0, \{q_2\})
  • q0q_0: last symbol was not part of a 00 suffix (start; no relevant trailing 0)
  • q1q_1: string currently ends in exactly one 0
  • q2q_2: string ends in 00accepting

Transition Table

State01
q0\to q_0q1q_1q0q_0
q1q_1q2q_2q0q_0
q2*q_2q2q_2q0q_0

Reading a 1 always resets to q0q_0 (suffix broken). In q2q_2, another 0 keeps the ...00 suffix, so it self-loops.

Diagram (described): q00q10q2q_0\xrightarrow{0}q_1\xrightarrow{0}q_2; q2q_2 self-loops on 0; every 1 arrow goes back to q0q_0. q2q_2 is a double circle.

Check: 1100q01q01q00q10q2q_0\xrightarrow{1}q_0\xrightarrow{1}q_0\xrightarrow{0}q_1\xrightarrow{0}q_2 → accepted.

dfa
7short5 marks

Explain epsilon-closure with a suitable example.

ε\varepsilon-closure

For an NFA with ε\varepsilon-transitions, the ε\varepsilon-closure of a state qq, written ε-closure(q)\varepsilon\text{-closure}(q) (or ECLOSE(q)ECLOSE(q)), is the set of all states reachable from qq using zero or more ε\varepsilon (empty) transitions only (no input symbol consumed). For a set of states, the ε\varepsilon-closure is the union of the closures of its members. Every state is always in its own ε\varepsilon-closure.

It is used when simulating ε\varepsilon-NFAs and when converting an ε\varepsilon-NFA to a DFA.

Example

Consider the ε\varepsilon-transitions:

q0εq1,q1εq2,q3 (no ε out)q_0 \xrightarrow{\varepsilon} q_1, \qquad q_1 \xrightarrow{\varepsilon} q_2, \qquad q_3 \text{ (no } \varepsilon \text{ out)}

Then:

  • ε-closure(q0)={q0,q1,q2}\varepsilon\text{-closure}(q_0) = \{q_0, q_1, q_2\} (reach q1q_1 directly, q2q_2 via q1q_1)
  • ε-closure(q1)={q1,q2}\varepsilon\text{-closure}(q_1) = \{q_1, q_2\}
  • ε-closure(q2)={q2}\varepsilon\text{-closure}(q_2) = \{q_2\}
  • ε-closure(q3)={q3}\varepsilon\text{-closure}(q_3) = \{q_3\}
epsilon-nfa
8short5 marks

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

Regular expression: at least one 0 and at least one 1

The string must contain a 0 somewhere and a 1 somewhere (in either order). One standard answer, splitting on which symbol appears first:

(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 a 0 occurs before some later 1.
  • The second term covers strings where a 1 occurs before some later 0.

Together they describe exactly the strings over {0,1}\{0,1\} containing at least one 0 and at least one 1.

(Equivalently, this is Σ(0+1)\Sigma^{*} - (0^{*} + 1^{*}), i.e. all strings except those made only of 0's or only of 1's, including ε\varepsilon.)

Examples accepted: 01, 10, 0011, 1010. Rejected: ε\varepsilon, 000, 111.

regular-expression
9short5 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 regular expressions over an alphabet, where PP does not contain the empty string ε\varepsilon (i.e. εP\varepsilon \notin P). Then the equation

R=Q+RPR = Q + RP

has the unique solution

R=QP.R = Q\,P^{*}.

The condition εP\varepsilon \notin P guarantees the solution is unique.

Use: deriving a regular expression from a finite automaton

Given a DFA/NFA, Arden's theorem lets us solve the automaton's state equations:

  1. For each state qiq_i, write an equation expressing it as the sum of (predecessor state)(input symbol)(\text{predecessor state}) \cdot (\text{input symbol}) for every incoming transition. The start state's equation also includes a ε\varepsilon term.
  2. This yields a system of simultaneous regular-expression equations.
  3. Solve by substitution, repeatedly applying Arden's rule R=Q+RPR=QPR = Q + RP \Rightarrow R = QP^{*} to eliminate self-loops/recursion.
  4. The regular expression for the final state (sum of expressions for all final states) is the language accepted by the automaton.

Mini-example

For a state with q1=ε+q1aq_1 = \varepsilon + q_1 a (self-loop on aa), Arden gives q1=εa=aq_1 = \varepsilon a^{*} = a^{*}.

arden-theoremregular-expression
10short5 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 for arithmetic expressions:

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

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

Derivation 1 (treats ++ first):

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 groups as id+(idid)id + (id * id).

Derivation 2 (treats * first):

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 groups as (id+id)id(id + id) * id.

Since the single string id + id * id has two distinct parse trees, the grammar is ambiguous. (It can be made unambiguous by introducing precedence levels using terms and factors.)

ambiguitycfg
11short5 marks

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

Eliminating Left Recursion from AAabA \to Aa \mid b

General rule. For a grammar with immediate left recursion of the form

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

(where β\beta does not begin with AA), replace it by the right-recursive grammar:

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

Applying to AAabA \to Aa \mid b: here α=a\alpha = a and β=b\beta = b. Substituting:

AbAAaAε\boxed{A \to b A'} \qquad \boxed{A' \to a A' \mid \varepsilon}

Verification. The original grammar generates bab a^{*} (a bb followed by zero or more aa's). The new grammar also generates bb then any number of aa's, e.g. baa: AbAbaAbaaAbaaA \Rightarrow bA' \Rightarrow baA' \Rightarrow baaA' \Rightarrow baa. The languages are equal, and there is no longer any left recursion.

cfgleft-recursion
12short5 marks

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

Greibach Normal Form (GNF)

A CFG is in Greibach Normal Form if every production has the form

AaαA \to a\,\alpha

where aa is a single terminal and α\alpha is a (possibly empty) string of variables only (αV\alpha \in V^{*}). Thus every production begins with exactly one terminal. (If εL\varepsilon \in L, the production SεS \to \varepsilon is also permitted.)

Conversion Procedure

Given a CFG (with no ε\varepsilon-productions except possibly SεS\to\varepsilon, no unit productions, no useless symbols):

  1. Convert to Chomsky Normal Form (CNF) first — productions ABCA \to BC or AaA \to a. Remove ε\varepsilon-, unit, and useless productions along the way.
  2. Order the variables A1,A2,,AnA_1, A_2, \dots, A_n.
  3. Remove forward recursion: for each production AiAjγA_i \to A_j\gamma with j<ij < i, substitute every production of AjA_j for the leading AjA_j, so that the leading variable's index is not smaller. Repeat until every production starts with a higher-indexed variable or a terminal.
  4. Eliminate immediate left recursion of the form AiAiαA_i \to A_i\alpha by introducing a new variable BiB_i (right-recursion conversion).
  5. Back-substitute: now AnA_n's productions start with a terminal. Substitute these into An1,An2,A_{n-1}, A_{n-2}, \dots so every production begins with a terminal.
  6. Fix the new variables BiB_i similarly so their productions also begin with terminals.
  7. Replace any leading-position terminal that is followed by terminals by introducing variables, so each production becomes AaαA \to a\alpha with α\alpha over variables only.

The result is an equivalent grammar in GNF. GNF is useful because every derivation step produces exactly one terminal, so a string of length nn derives in exactly nn steps, and GNF directly relates CFGs to pushdown automata.

greibach-normal-formcfg

Frequently asked questions

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