BSc CSIT (TU) Science Theory of Computation (BSc CSIT, CSC257) Question Paper 2081 Nepal
This is the official BSc CSIT (TU) (Science stream) Theory of Computation (BSc CSIT, CSC257) question paper for 2081, as set in the regular annual examination. It carries 60 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Theory of Computation (BSc CSIT, CSC257) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BSc CSIT (TU) Theory of Computation (BSc CSIT, CSC257) exam or solving previous years' question papers, this 2081 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
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:
- = finite set of states
- = input alphabet
- = stack alphabet
- finite subsets of = transition function
- = start state, = initial stack symbol, = set of final states
PDA for
Idea: push one for every read; for every read, pop one . Accept (by final state) when the stack is restored to after the input ends.
Let with:
- — first , push
- — more 's, keep pushing
- — first , pop one
- — more 's, keep popping
- — stack empty of 's, accept
Trace for the string aabb
Using instantaneous descriptions with stack top written leftmost:
| Step | ID | Rule used |
|---|---|---|
| 0 | start | |
| 1 | rule 1 | |
| 2 | rule 2 | |
| 3 | rule 3 | |
| 4 | rule 4 | |
| 5 | rule 5 |
The input is fully consumed and the PDA halts in final state , so aabb is accepted. Since the number of 's pushed must equal the number of 's popped before reaching , accepts exactly .
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:
- = finite set of states
- = input alphabet (does not contain blank )
- = tape alphabet, ,
- = transition function (read a symbol, write a symbol, move head Left/Right)
- = start state, = blank symbol, = 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 is not context-free, a PDA cannot accept it, but a TM can.
TM for
Strategy: repeatedly cross off one (mark as ), then the matching (mark ), then the matching (mark ). Return to the left and repeat until no 's remain. Then verify nothing but is left.
States: , accepting. Tape alphabet .
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 has no matching , or counts differ), is undefined and the machine halts in a non-final state, rejecting the string.
Working / Transition Diagram (described)
Think of a cycle: . Each pass through the loop converts one , one and one into . When instead reads , the input has been fully matched; it enters to scan the trailing 's and 's and, on reading blank , moves to accepting state .
Example aabbcc becomes XaYbZc → XXYYZZ after two cycles, then verifies and accepts.
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/-NFA). Thus regular expressions and finite automata have exactly the same expressive power and are inter-convertible:
- RE -NFA: Thompson's construction.
- NFA/-NFA DFA: subset construction.
- DFA RE: state elimination / Arden's theorem.
For every RE there is an -NFA (Thompson's construction)
Proof by induction on the structure of the regular expression . Base cases:
- : an automaton with start and non-accepting state, no transitions.
- : start state that is also accepting.
- (): start state with an -edge to a single accepting state.
Inductive step (let be -NFAs for sub-expressions ):
- Union : new start state with -edges to the starts of and ; their accepting states -link to a new final state.
- Concatenation : connect the accepting state of by to the start of .
- Star : new start/final state, with -edges into and a loop-back -edge from its accepting state, plus an -edge allowing itself.
Each case preserves the language, so by induction every RE has an equivalent -NFA.
Converting to a finite automaton
The RE means: any string over ending in ab. A simple NFA (start ):
| State | ||
|---|---|---|
loops on (the part) and non-deterministically guesses the final ab by going .
Determinized (DFA) by subset construction:
| DFA state | ||
|---|---|---|
| (start) | ||
| (final) |
Accepting state contains . This 3-state DFA accepts exactly the strings ending in ab, confirming the equivalence.
Section B: Short Answer Questions
Attempt any EIGHT questions.
What is an ambiguous grammar? Show with an example that a grammar is ambiguous.
Ambiguous Grammar
A context-free grammar is ambiguous if there exists at least one string in that has two or more distinct parse trees (equivalently, two distinct leftmost derivations or two distinct rightmost derivations).
Example
Consider the grammar:
The string id + id * id has two different leftmost derivations / parse trees:
Derivation 1 (group first):
Parse tree: root +, with right child a * subtree → corresponds to .
Derivation 2 (group first):
Parse tree: root *, with left child a + subtree → corresponds to .
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. .)
Eliminate left recursion from the grammar A -> Aa | b.
Eliminating Left Recursion from
General rule: for a left-recursive rule (where does not start with ), replace it with:
Here and . Substituting:
Verification: the original grammar generates (a followed by any number of 's). The new grammar derives , 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).
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
where is a single terminal and is a (possibly empty) string of non-terminals. The grammar must be -free (except possibly ). 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
- Pre-process: remove -productions, unit productions, and useless symbols. Convert the grammar to Chomsky Normal Form (CNF) ( or ) as a clean starting point.
- Order the non-terminals .
- Remove left recursion and substitute so every production's right-hand side starts with a higher-numbered non-terminal. For each , for each rule with , replace by all of its right-hand sides. Eliminate any resulting immediate left recursion using a new variable : (rewritten to avoid ).
- Back-substitute from the highest-numbered non-terminal downward. After step 3, 's productions begin with a terminal; substitute these into the productions of so that every production begins with a terminal.
- Fix the new variables similarly so their productions also begin with a terminal.
The result is an equivalent grammar in which every production is of the form , i.e. in Greibach Normal Form.
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
- = current state
- = the remaining (unread) portion of the input string
- = current contents of the stack (top symbol written leftmost)
A move is written when contains . The relation is the reflexive–transitive closure (zero or more moves).
Acceptance by Final State
The language accepted by final state is:
The input is accepted if, after consuming all of , the PDA is in some accepting state ; the stack contents are irrelevant.
Acceptance by Empty Stack
The language accepted by empty stack is:
Here the input is accepted if, after consuming all of , the stack becomes empty, regardless of the state. The set 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.
Explain the working of a multi-tape Turing Machine.
Multi-tape Turing Machine
A multi-tape Turing Machine has tapes (), 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 symbols currently under all heads, and depending on the current state and these symbols it:
- changes state,
- writes a (possibly new) symbol on each of the tapes,
- moves each head independently Left, Right, or Stays put.
Formally .
Advantage: extra tapes act as scratch/work space, often making algorithms simpler and faster. For example, 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 -tape TM can be simulated by a single-tape TM (storing the tracks/head positions on one tape). The simulation is at most a polynomial (quadratic) slowdown: steps of a -tape machine take steps on the single-tape machine. Hence multi-tape TMs recognize exactly the recursively enumerable languages, confirming the Church–Turing thesis.
What is a Universal Turing Machine? Explain its significance.
Universal Turing Machine (UTM)
A Universal Turing Machine is a single Turing Machine that can simulate the behaviour of any other Turing Machine on any input . It takes as input an encoding — a description of 's states and transition function together with the input — and then carries out, step by step, exactly what would do on :
That is, accepts iff accepts , halts iff halts, and loops iff 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.
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.
| Aspect | Recursive (Decidable) | Recursively Enumerable (Turing-recognizable) |
|---|---|---|
| TM behaviour | A TM always halts: accepts strings in and rejects (halts) strings not in | A TM halts and accepts strings in , but may loop forever on strings not in |
| Decision | The language is decidable — there is an algorithm that always answers yes/no | Only semi-decidable — yes-answers are guaranteed, no-answers may never come |
| Complement | Closed under complement: if is recursive, so is | Not closed under complement: r.e. does not imply r.e. |
| Relationship | Every recursive language is recursively enumerable | The converse is false — some r.e. languages are not recursive |
| Example | , any CFL, the membership problem for a TM that always halts | The language (acceptance / Halting problem ) is r.e. but not recursive |
Key fact: A language is recursive iff both and its complement are recursively enumerable. The Halting problem shows the inclusion Recursive Recursively Enumerable is strict.
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 where is the output alphabet and is the output function; they differ in how is defined.
Moore machine: output depends only on the current state.
Mealy machine: output depends on the current state and the current input.
Differences
| Mealy Machine | Moore Machine |
|---|---|
| Output associated with transitions (state + input) | Output associated with states only |
| For input of length , produces outputs | For input of length , produces 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 task | Usually needs more states |
| Output written on edges of the transition diagram | Output 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.
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):
- Union: if are regular, is regular. (RE: ; or an NFA with a new start state -linked to both.)
- Concatenation: is regular. (RE: ; link accepting states of to the start of .)
- Kleene Star: is regular. (RE: .)
- Complement: is regular. (Take a complete DFA and swap accepting / non-accepting states.)
- Intersection: is regular. (Product/cross construction of the two DFAs; also follows from union + complement by De Morgan: .)
- Difference: is regular.
- Reversal: is regular. (Reverse all edges, swap start/final.)
- 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 were non-regular for a regular , then cannot be regular).
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.