BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) Question Paper 2079 Nepal
This is the official BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) question paper for 2079, as set in the regular annual examination. It carries 80 full marks and a time allowance of 180 minutes, across 11 questions. On Kekkei you can attempt this Theory of Computation (IOE, CT 502) 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 BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) exam or solving previous years' question papers, this 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all / any as specified.
(a) Define a Non-deterministic Finite Automaton (NFA) formally as a 5-tuple and explain how it differs from a Deterministic Finite Automaton (DFA). (b) Construct an NFA that accepts the language of all strings over that contain the substring . Convert the obtained NFA into an equivalent DFA using the subset construction method, clearly showing the transition table and the resulting state diagram.
(a) NFA Definition and Difference from DFA
A Non-deterministic Finite Automaton (NFA) is formally a 5-tuple:
where:
- — a finite set of states,
- — a finite input alphabet,
- — the transition function mapping a state and an input symbol (or ) to a set of states,
- — the start state,
- — the set of accepting (final) states.
Differences from a DFA:
| Aspect | DFA | NFA |
|---|---|---|
| Transition | (single state) | (set of states) |
| -moves | Not allowed | Allowed |
| Choices per symbol | Exactly one | Zero, one, or many |
| Acceptance | Unique path | Accepts if some path ends in |
Both recognize exactly the same class — the regular languages — but the NFA is often easier to design.
(b) NFA for strings containing substring 011
States: (start), (seen 0), (seen 01), (seen 011, accepting).
| State | 0 | 1 |
|---|---|---|
loops on both symbols (guessing the start of the pattern); once 011 is found, absorbs all further input.
Subset construction (NFA → DFA)
Start with and compute reachable subsets:
| DFA state | 0 | 1 |
|---|---|---|
DFA: start state ; accepting states (every subset containing ).
Resulting DFA state diagram (described)
- ,
- ,
- , (accept)
- are accepting and never leave the accepting region: each transitions among , so once
011has appeared the string is accepted regardless of the suffix.
This DFA accepts exactly the strings over containing 011.
(a) Define a Context-Free Grammar (CFG) and a Pushdown Automaton (PDA). Explain the equivalence between CFGs and PDAs. (b) Consider the grammar . Show that it generates the language and construct a PDA (accepting by empty stack) that recognizes this language, giving its complete set of transition rules.
(a) CFG, PDA, and their Equivalence
Context-Free Grammar (CFG): a 4-tuple where is a finite set of variables (non-terminals), the set of terminals (), a finite set of productions of the form with and , and the start symbol. The language is .
Pushdown Automaton (PDA): a 7-tuple , i.e. an NFA augmented with a stack, where is the stack alphabet, the initial stack symbol, and .
Equivalence: A language is context-free iff it is accepted by some PDA. Every CFG can be converted to an equivalent PDA (and vice versa). Moreover, acceptance by final state and acceptance by empty stack define the same class of languages. Hence CFGs and PDAs have exactly the same expressive power (the context-free languages).
(b) Grammar
It generates :
By induction. Base: . Inductive step: applying to wraps one on the left and one on the right, giving . Every derivation must end with , so every generated string has the form (), and each such string is derivable by uses of then . Therefore .
PDA accepting by empty stack. Idea: push a marker for each , pop one for each matching .
with transitions:
1. delta(q0, a, Z0) = { (q0, A Z0) } ; first a: push A
2. delta(q0, a, A) = { (q0, A A) } ; more a's: push A
3. delta(q0, b, A) = { (q1, e) } ; first b: pop one A
4. delta(q1, b, A) = { (q1, e) } ; more b's: pop A
5. delta(q1, e, Z0) = { (q1, e) } ; pop Z0 -> empty stack, accept
(Here e = .) After reading all 's the stack holds ; each pops one ; if counts match, after the last the stack is , which rule 5 pops, emptying the stack and accepting. Unequal counts leave the stack non-empty or block a transition, so they are rejected.
(a) Describe the formal model of a standard (single-tape) Turing machine and explain the Church-Turing thesis. (b) Design a Turing machine that accepts the language . Give the transition function and trace the computation of the machine on the input string .
(a) Standard Turing Machine and the Church-Turing Thesis
A (single-tape) Turing Machine is a 7-tuple:
- — finite set of states,
- — input alphabet (blank ),
- — tape alphabet, , ,
- — transition function (read a symbol, write a symbol, move head Left/Right),
- — start state, — halting states.
The machine has a two-way infinite tape and a read/write head. It halts when it enters or ; otherwise it may loop forever.
Church-Turing Thesis: every function that is effectively computable (computable by any mechanical/algorithmic procedure) can be computed by a Turing machine. Equivalently, the Turing machine captures the intuitive notion of an algorithm; all reasonable models of computation (λ-calculus, recursive functions, RAM, etc.) are equivalent in power to it. It is a thesis (not a provable theorem) because "effectively computable" is an informal notion.
(b) Turing Machine for
Strategy: repeatedly mark the leftmost unmarked as , then the leftmost as , then the leftmost as ; return to the start and repeat. Accept when no symbols remain unmarked.
Tape alphabet . Transition function:
q0: a -> X,R,q1 ; mark an a, go find a b
Y -> Y,R,q4 ; all a's done -> verify no extra b/c
q1: a -> a,R,q1 ; skip a's
Y -> Y,R,q1 ; skip already-marked Y's
b -> Y,R,q2 ; mark a b, go find a c
q2: b -> b,R,q2 ; skip b's
Z -> Z,R,q2 ; skip already-marked Z's
c -> Z,L,q3 ; mark a c, go back
q3: a,b,c,Y,Z -> same,L,q3 ; sweep left
X -> X,R,q0 ; back to start, repeat
q4: Y -> Y,R,q4 ; skip Y's
Z -> Z,R,q4 ; skip Z's
blank -> blank,R,qaccept ; nothing left -> accept
Any symbol read in a state with no rule (e.g. a stray , , or in , or a missing /) leads to .
Trace on input aabbcc
| Step | Tape (head in bold) | State |
|---|---|---|
| 0 | aabbcc | |
| Xabbcc | ||
| Xabbcc | ||
| XaYbcc | ||
| XaYbcc | ||
| XaYbZc | (after marking c, sweep left) | |
| sweep to X, then | ||
| 2nd pass | XaYbZc → X a YbZc, mark a→X | |
| XXYbZc, skip Y, mark b→Y | reaches | |
| XXYYZc → mark c→Z | ||
| sweep back to start | ||
| 3rd | XXYYZZ, head on Y | (no more a) → |
| skip Y's and Z's, reach | ||
| final | XXYYZZ |
All three symbols are consumed in equal numbers, so the machine accepts aabbcc ().
Section B: Short Answer Questions
Attempt all / any as specified.
(a) State the precedence and meaning of the regular expression operators. (b) Write regular expressions for: (i) all strings over whose length is a multiple of 3, and (ii) all strings over that begin and end with the same symbol.
(a) Regular Expression Operators: Precedence and Meaning
For expressions over an alphabet , the three operators in decreasing order of precedence are:
- Kleene star — zero or more repetitions of (highest precedence). Meaning: .
- Concatenation — a string of followed by a string of . Meaning: .
- Union (alternation) — a string in or (lowest precedence). Meaning: .
Parentheses override precedence. Also denotes the empty string and the empty language. Example: means .
(b) Regular Expressions
(i) Strings over of length a multiple of 3:
Each group contributes exactly 3 symbols, so the total length is (note of length 0 is included).
(ii) Strings over that begin and end with the same symbol:
The first two alternatives cover strings of length with matching ends; the single symbols and cover length-1 strings (whose first and last symbol coincide trivially).
State the Pumping Lemma for regular languages. Using it, prove that the language is not regular.
Pumping Lemma for Regular Languages
If is regular, then there exists a constant (the pumping length) such that every string with can be written as satisfying:
- (the middle part is non-empty),
- ,
- for all , .
Proof that is not regular
Assume, for contradiction, that is regular. Let be the pumping length. Choose
By the lemma, with and . Since the first symbols of are all 's, the substring lies entirely within the -block, so consists only of 's: with .
Now pump with :
Here the number of 's is = the number of 's, so .
This contradicts condition 3 of the pumping lemma. Hence our assumption is false, and is not regular.
Explain the Chomsky hierarchy of grammars. For each of the four types, give the form of production rules and the corresponding class of accepting automaton, illustrating with a suitable example for each type.
Chomsky Hierarchy of Grammars
Noam Chomsky classified grammars into four nested types by restricting the form of productions ( = variables, = terminal, = strings of symbols).
| Type | Name | Production form | Accepting automaton | Language class |
|---|---|---|---|---|
| 0 | Unrestricted | , contains variable | Turing Machine | Recursively enumerable |
| 1 | Context-Sensitive | , $ | \gamma | \ge1$ (non-contracting) |
| 2 | Context-Free | , | Pushdown Automaton | Context-free |
| 3 | Regular | or (right-linear) | Finite Automaton | Regular |
The classes are strictly nested: Regular Context-Free Context-Sensitive Recursively Enumerable.
Examples:
- Type 3 (Regular): generates . Accepted by a finite automaton.
- Type 2 (Context-Free): generates (not regular). Accepted by a PDA.
- Type 1 (Context-Sensitive): a grammar for (not context-free). Accepted by a linear-bounded automaton.
- Type 0 (Unrestricted): grammars generating any recursively enumerable language, e.g. encoding an arbitrary Turing machine's computation. Accepted by a Turing machine.
Define an ambiguous grammar. Show that the grammar is ambiguous by giving two distinct parse trees (or leftmost derivations) for the string , and suggest how the ambiguity can be removed.
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 or two distinct rightmost derivations).
The grammar is ambiguous
Consider the string . It has two different leftmost derivations / parse trees:
Derivation 1 (treats + as the outer operator → ):
Parse tree: root + with left child and right child the subtree .
Derivation 2 (treats * as the outer operator → ):
Parse tree: root * with left child the subtree and right child .
Two distinct parse trees for the same string ⇒ the grammar is ambiguous.
Removing the Ambiguity
Rewrite the grammar to enforce operator precedence (* binds tighter than +) and left-associativity, using separate non-terminals for each precedence level:
Now has a unique parse tree (with grouped first), so the grammar is unambiguous.
Differentiate between a decidable and an undecidable problem. State the Halting Problem and explain, with the essential argument, why it is undecidable.
Decidable vs Undecidable Problems
A decidable (recursive) problem is one for which there exists an algorithm (a Turing machine) that halts on every input and correctly answers "yes" or "no". Example: "Does a DFA accept a given string?"
An undecidable problem is one for which no such always-halting algorithm exists; no Turing machine can decide all instances correctly. Example: the Halting Problem.
The Halting Problem
Statement: Given an arbitrary Turing machine (program) and an input , decide whether halts (terminates) when run on . Formally, decide membership in .
Why it is Undecidable (essential argument)
Suppose, for contradiction, a TM decides : = yes if halts on , no otherwise (and always halts).
Build a machine that takes and does:
D(<M>):
if H(<M>, <M>) = yes then loop forever
else halt
Now run on its own description :
- If halts on , then yes, so by construction loops — contradiction.
- If loops on , then no, so by construction halts — contradiction.
Either case is contradictory, so the assumed cannot exist. This diagonalization argument proves the Halting Problem is undecidable.
Given the regular grammar with productions and , construct the equivalent finite automaton and describe the language it accepts.
Constructing the Finite Automaton
The right-linear grammar is:
Map each variable to a state ( state , state ); a production gives a transition , and makes an accepting state.
- ⟹
- ⟹
- ⟹ is a final state
- ⟹
- ⟹
Transition table (start = , final = ):
| State | a | b |
|---|---|---|
This is a DFA with two states.
Language Accepted
Reading a never changes the state (, ); reading an toggles between and . So the automaton is in state exactly when the number of 's read so far is odd, and in (the accepting state) when it is even.
Therefore the accepted language is:
(the number of 's is unrestricted, and , with zero 's, is accepted).
Convert the following context-free grammar into Chomsky Normal Form (CNF): , , . Show all intermediate steps including removal of -productions and unit productions.
Converting to Chomsky Normal Form
Start grammar:
Step 1 — Add a new start symbol
, keeping all old rules (so the start symbol never appears on a RHS).
Step 2 — Remove -productions
Nullable variables: (from ). has but is terminal, so is not nullable; is not nullable. Remove and add versions of rules with omitted:
- ⟹ also (drop the )
- ⟹ also
- ⟹ also
- ⟹ also (kept, since )
Now:
Step 3 — Remove unit productions
Unit pairs: and .
- Replace by 's rules: (and keep ).
- Replace by 's rules: .
Result:
Step 4 — Replace terminals in long RHS
Introduce and , substituting them wherever a terminal sits in a string of length :
- ,
Step 5 — Break RHS longer than 2 into binary
Introduce auxiliary variables for length-3 right-hand sides:
- : let , then , .
- : let , then , .
- : let , then .
Final CNF grammar
Every production now has the form or (with the single allowed exception because the start symbol does not appear on any RHS), so the grammar is in CNF.
Distinguish between recursive (decidable) languages and recursively enumerable languages. Explain why every recursive language is recursively enumerable but the converse is not necessarily true.
Recursive vs Recursively Enumerable Languages
Recursive (decidable) language: a language for which there is a Turing machine that always halts and decides membership — it accepts every and rejects (halts and says "no") every .
Recursively enumerable (RE / Turing-recognizable) language: a language for which there is a Turing machine that accepts (halts) every , but on it may either reject or loop forever (run without halting).
| Property | Recursive | Recursively Enumerable |
|---|---|---|
| TM behaviour | Always halts (decider) | Halts on members; may loop on non-members (recognizer) |
| Decision possible | Yes | Membership semi-decidable only |
| Closed under complement | Yes | No |
Why Recursive ⟹ Recursively Enumerable
If is recursive, it has a decider that halts on all inputs. This same is also a recognizer: it accepts exactly the strings of (and halts on them). A decider is a special case of a recognizer, so every recursive language is recursively enumerable.
Why the Converse Fails
There exist RE languages that are not recursive — the classic example is
A universal TM can recognize (simulate on and accept if it accepts), so it is RE. But it is undecidable (no always-halting decider exists, by the Halting Problem). Hence it is RE but not recursive.
Key theoretical fact: is recursive iff both and its complement are recursively enumerable. If "RE ⟹ recursive" held for all languages, every RE language would be decidable, contradicting the existence of . Therefore RE is a strictly larger class, and the converse does not hold.
Frequently asked questions
- Where can I find the BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) question paper 2079?
- The full BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2079 (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 (IOE, CT 502) 2079 paper come with solutions?
- Yes. Every question on this Theory of Computation (IOE, CT 502) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
- How many marks is the BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2079 paper?
- The BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2079 paper carries 80 full marks and is meant to be completed in 180 minutes, across 11 questions.
- Is practising this Theory of Computation (IOE, CT 502) past paper free?
- Yes — reading and attempting this Theory of Computation (IOE, CT 502) past paper on Kekkei is completely free.