BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) Question Paper 2078 Nepal
This is the official BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) question paper for 2078, 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 2078 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 the role of each component. State how an NFA differs from a DFA.
(b) Consider the NFA with -transitions over the alphabet that accepts all strings containing the substring aba. Using the subset construction algorithm, convert the given NFA into an equivalent DFA. Show the transition table and draw the resulting DFA, clearly marking the start and final states.
(a) Formal definition of an NFA
A Non-deterministic Finite Automaton (NFA) is a 5-tuple
where:
- — a finite, non-empty set of states.
- — a finite input alphabet (the symbols the machine reads).
- — the transition function . For a given state and input symbol it returns a set of possible next states (possibly empty), and -moves allow changing state without reading input.
- — the start (initial) state.
- — the set of final (accepting) states.
A string is accepted if at least one computation path ends in a state of .
NFA vs DFA
| Feature | DFA | NFA |
|---|---|---|
| Transition | (exactly one next state) | (a set of states) |
| -moves | Not allowed | Allowed |
| Choice | Deterministic (one path) | Non-deterministic (many paths) |
| Acceptance | The single path ends in | Some path ends in |
Both accept exactly the regular languages — they are equivalent in power.
(b) NFA for strings containing aba, then subset construction
NFA with states , start , final :
| State | ||
|---|---|---|
State loops on every symbol (still searching); recognises aba; is a trap-accept state. (No -transitions are actually needed, so -closure of each state is the state itself.)
Subset construction
Start subset .
| DFA state | Subset | ||
|---|---|---|---|
| (start) | |||
| * | |||
| * | |||
| * |
Final states are all subsets containing : .
Resulting DFA (described)
- Start state: .
- Accepting states (double circle): .
- Transitions as in the table. Once any accepting state is reached (substring
abaseen) the machine stays among accepting states forever, since every subsequent subset still contains .
This DFA accepts exactly the strings over that contain the substring aba.
(a) Consider the context-free grammar with productions:
Show the leftmost derivation and draw the parse tree for the string aabbab. State the language generated by this grammar.
(b) Construct a Pushdown Automaton (PDA) that accepts the language by final state. Describe its transition function and trace the moves of your PDA on the input string aaabbb.
(a) Derivation, parse tree and for
Leftmost derivation of aabbab:
So aabbab , two balanced blocks concatenated.
Parse tree (described):
S
/ \
S S
/|\ /|\
a S b a S b
| |
S S
/|\ |
a S b ε
|
ε
- Root .
- Left (innermost ).
- Right (with ).
Language generated:
i.e. the set of all strings in which every prefix has and the whole string has — the balanced / Dyck language over .
(b) PDA for (acceptance by final state)
with , , , start state , start stack symbol , .
Transition function:
- — push first .
- — push an for each .
- — on first , pop one , go to .
- — pop one per .
- — stack back to (equal 's and 's): accept.
Trace on aaabbb (notation: (state, remaining input, stack), top of stack on the left):
| Step | Configuration | Rule |
|---|---|---|
| 0 | start | |
| 1 | (1) | |
| 2 | (2) | |
| 3 | (2) | |
| 4 | (3) | |
| 5 | (4) | |
| 6 | (4) | |
| 7 | (5) |
Input consumed and machine in final state ⇒ aaabbb is accepted.
(a) Design a Turing Machine that accepts the language . Give the formal definition (states, tape symbols, transition function) and show the sequence of configurations (instantaneous descriptions) when the machine processes the input aabbcc.
(b) State the Halting Problem and prove that it is undecidable. Explain the significance of this result in the theory of computation.
(a) Turing Machine for
Idea: repeatedly cross off the leftmost unmarked (write ), then the leftmost (write ), then the leftmost (write ); return to the left and repeat until none remain. Accept if everything is matched.
Formal definition :
- ( = blank)
- start ,
Transition function (Right = R, Left = L):
q0 a -> q1, X, R (mark an a, go find a b)
q0 Y -> q4, Y, R (no a's left; verify only Y,Z remain)
q1 a -> q1, a, R (skip a's)
q1 Y -> q1, Y, R (skip already-marked Y)
q1 b -> q2, Y, R (mark a b, go find a c)
q2 b -> q2, b, R (skip b's)
q2 Z -> q2, Z, R (skip marked Z)
q2 c -> q3, Z, L (mark a c, turn around)
q3 (a|b|Y|Z) -> q3, same, L (walk left)
q3 X -> q0, X, R (back at left boundary, repeat)
q4 Y -> q4, Y, R (scan remaining Y's)
q4 Z -> q4, Z, R (scan remaining Z's)
q4 B -> qacc, B, R (all matched -> accept)
Any missing transition (e.g. seeing when expecting only , or a before a ) goes to , ensuring strings like or are rejected.
Sequence of configurations (IDs) for input aabbcc (current state shown just left of the scanned symbol):
q0 a a b b c c
X q1 a b b c c
X a q1 b b c c
X a Y q2 b c c
X a Y b q2 c c
X a Y q3 b Z c (mark c->Z, move L)
X a q3 Y b Z c
X q3 a Y b Z c
q3 X a Y b Z c
X q0 a Y b Z c
X X q1 Y b Z c (mark a->X)
X X Y q1 b Z c
X X Y Y q2 Z c (mark b->Y)
X X Y Y Z q2 c
X X Y Y q3 Z Z (mark c->Z, move L)
X X Y q3 Y Z Z
X X q3 Y Y Z Z
X q3 X Y Y Z Z
X X q0 Y Y Z Z (no a's left)
X X Y q4 Y Z Z
X X Y Y q4 Z Z
X X Y Y Z q4 Z
X X Y Y Z Z q4 B
X X Y Y Z Z B qacc -> ACCEPT
(b) The Halting Problem and its undecidability
Statement. Given the encoding of an arbitrary Turing machine and an input , decide whether halts on . Formally, decide membership in
The Halting Problem asks for an algorithm (a TM that always halts) deciding .
Proof of undecidability (diagonalization / contradiction).
Assume, for contradiction, that a TM decides :
Construct a TM that takes a single input and runs :
- If says " halts on ", then loops forever.
- If says " loops on ", then halts.
Now run on its own description :
- If halts on , then by construction said it loops, so must loop — contradiction.
- If loops on , then said it halts, so must halt — contradiction.
Either way we reach a contradiction, so the assumed decider cannot exist. Hence the Halting Problem is undecidable.
Significance.
- It is the first concrete, natural problem proven algorithmically unsolvable, establishing a hard limit on what computers can do.
- It shows the class of recursively enumerable languages strictly contains the recursive (decidable) languages ( is r.e. but not recursive).
- Via reduction, undecidability of propagates to many practical problems (program verification, equivalence of programs, Rice's theorem properties), proving no general algorithm can decide them.
Explain the Chomsky hierarchy of grammars. For each of the four types (Type 0, Type 1, Type 2, Type 3), describe the form of the production rules, the class of language generated, and the corresponding accepting automaton. Illustrate each grammar type with one suitable example.
The Chomsky Hierarchy of Grammars
Proposed by Noam Chomsky (1956), it classifies grammars (and the languages/automata they correspond to) into four nested types by restricting the form of productions . Each class strictly contains the next:
Type 0 — Unrestricted (Recursively Enumerable)
- Productions: with and containing at least one variable. No restriction.
- Language class: Recursively enumerable languages.
- Automaton: Turing Machine.
- Example: Any TM-recognisable language, e.g. via context-sensitive-style rules with deletion; e.g. (with extra erasing rules).
Type 1 — Context-Sensitive
- Productions: with (non-contracting); equivalently with . ( allowed if unused on RHS.)
- Language class: Context-sensitive languages.
- Automaton: Linear Bounded Automaton (LBA) — a TM whose tape is bounded by the input length.
- Example: , generated by a context-sensitive grammar such as .
Type 2 — Context-Free
- Productions: where (single variable on the left) and .
- Language class: Context-free languages.
- Automaton: Pushdown Automaton (PDA).
- Example: , generated by .
Type 3 — Regular
- Productions: right-linear or (or all left-linear), .
- Language class: Regular languages.
- Automaton: Finite Automaton (DFA/NFA).
- Example: (strings of 's ending in one ), generated by .
Summary table
| Type | Grammar | Production form | Language | Automaton |
|---|---|---|---|---|
| 0 | Unrestricted | Recursively enumerable | Turing Machine | |
| 1 | Context-sensitive | $ | \alpha | \le |
| 2 | Context-free | Context-free | Pushdown Automaton | |
| 3 | Regular | Regular | Finite Automaton |
Section B: Short Answer Questions
Attempt all / any as specified.
(a) Write a regular expression for the language over consisting of all strings that have an even number of 0's and end with 1.
(b) State Arden's theorem and use it to find the regular expression accepted by a finite automaton with states where is the start state, , , and is the final state with .
(a) Even number of 0's and ending in 1
A block containing an even number of 0's (any number of 1's interspersed) is described by , i.e. 0's come in pairs. The string must then end in 1, so append at least one 1:
Equivalently . This guarantees an even count of 0's and a final symbol 1.
(b) Arden's Theorem
Statement. For regular expressions and where does not contain (does not generate) the empty string , the equation
has the unique solution
Applying it to the given automaton
States: start , final . Transitions: , , , .
Write equations for strings reaching each state (each variable = set of strings ending in that state):
Solve with Arden ():
Solve ():
Since is the only final state, the regular expression accepted by the automaton is
i.e. all strings consisting of zero or more 's, then a , then any string over .
State the pumping lemma for regular languages. Using the pumping lemma, 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),
- (the pumped part lies within the first symbols),
- for all (pumping keeps the string in ).
Proof that is not regular
Assume is regular, and let be the pumping length.
Choose the string
By the lemma, with and . Since the first symbols of are all 's, both and lie entirely within the -block. So
Pump with :
Since , this string has more 's than 's, so . This contradicts condition 3 of the pumping lemma.
Therefore our assumption is false, and is not regular.
(a) Define an ambiguous grammar. Show that the grammar is ambiguous by giving two distinct parse trees for the string id + id * id.
(b) Briefly explain how the ambiguity in this grammar can be removed.
(a) Ambiguous grammar
A context-free grammar is ambiguous if there exists at least one string that has two or more distinct parse (derivation) trees — equivalently, two distinct leftmost (or two distinct rightmost) derivations.
Showing is ambiguous using the string id + id * id:
Parse tree 1 (addition at the root — interprets as id + (id * id)):
E
/ | \
E + E
| / | \
id E * E
| |
id id
Parse tree 2 (multiplication at the root — interprets as (id + id) * id):
E
/ | \
E * E
/|\ |
E + E id
| |
id id
Both trees derive the same string id + id * id but have different structure (and different evaluation: vs ). Two distinct parse trees exist, hence the grammar is ambiguous.
(b) Removing the ambiguity
The ambiguity is removed by encoding operator precedence and associativity into the grammar using a hierarchy of non-terminals (one level per precedence) and making them left-recursive for left associativity:
E -> E + T | T (+ has lowest precedence, left-associative)
T -> T * F | F (* binds tighter than +)
F -> ( E ) | id (highest precedence: parentheses / atoms)
Now id + id * id has a unique parse tree: /* (the level) must be built before (the level), forcing the multiplication to be grouped first (). Since every string now has exactly one parse tree, the grammar is unambiguous.
Convert the following context-free grammar into Chomsky Normal Form (CNF), showing each step of the conversion:
Convert to Chomsky Normal Form
Given grammar:
CNF requires every production to be of the form (two variables) or (single terminal); only the start symbol may derive , and it must not appear on any right-hand side.
Step 1 — Add a new start symbol
Step 2 — Remove -productions
Nullable variables: (directly), and (via ). Remove and add versions of rules with nullable symbols omitted:
- : omitting nullable 's gives .
- : omitting gives .
- : nullable but dropping it gives empty, not added (would be , discard).
Result:
Step 3 — Remove unit productions
Unit pairs and substitution:
- : delete (trivial).
- ⇒ inherits 's rules: .
- ⇒ ; ⇒ inherits 's rules: .
Now:
Step 4 — Replace terminals in long rules and break up bodies of length > 2
Introduce and use it inside mixed/long bodies. Replace with . Break the ternary by introducing , so .
Let .
Final CNF grammar:
Every production is now or , so the grammar is in Chomsky Normal Form.
Differentiate between a Mealy machine and a Moore machine with respect to output behaviour. Design a Moore machine over that outputs the residue (remainder) of the input binary number when divided by 3.
Mealy vs Moore machines (output behaviour)
| Aspect | Moore machine | Mealy machine |
|---|---|---|
| Output depends on | the state only | the state and current input |
| Output written | (one symbol per state) | (one symbol per transition) |
| Output for input of length | symbols (includes the start state's output) | symbols |
| Reaction to input change | delayed by one clock (state must change first) | immediate (same clock) |
| Typical size | usually more states | usually fewer states |
Moore machine: residue of a binary number mod 3
Reading the binary input most-significant bit first, the value-so-far updates as , so the remainder mod 3 updates as . Use three states, one per residue, and output the residue of the state.
States / outputs: (residue 0, output 0), (residue 1, output 1), (residue 2, output 2). Start state (empty input ⇒ residue 0).
Transition table (next state ):
| State (residue) | Output | input 0 | input 1 |
|---|---|---|---|
| (0) | 0 | () | () |
| (1) | 1 | () | () |
| (2) | 2 | () | () |
Reasoning for on input 0: . On input 1: . Similarly for the others.
Example: input 110 (decimal 6). , final output 0 = . Correct. Because it is a Moore machine, the output is simply the label of the state reached after reading the whole string.
(a) Distinguish between a recursive language and a recursively enumerable language.
(b) State Rice's theorem and give one example of a non-trivial property of recursively enumerable languages that is undecidable as a consequence of it.
(a) Recursive vs Recursively Enumerable languages
| Recursive (decidable) | Recursively enumerable (r.e.) | |
|---|---|---|
| Deciding TM | A TM that halts on every input, accepting members and rejecting non-members | A TM that halts and accepts members, but may loop forever on non-members |
| Membership | Always decidable (algorithm gives yes/no) | Semi-decidable (yes is detectable; no may never be reported) |
| Closure under complement | Closed (recursive languages are closed under complement) | Not closed under complement |
| Relationship | Every recursive language is r.e. | r.e. strictly contains recursive (e.g. is r.e. but not recursive) |
Key fact: is recursive iff both and its complement are recursively enumerable.
(b) Rice's Theorem
Statement. Any non-trivial property of the language recognised by a Turing machine is undecidable. A property of r.e. languages is non-trivial if it is true for at least one r.e. language and false for at least one other (i.e. neither always true nor always false). Formally, the set
is undecidable whenever is non-trivial.
Example of an undecidable property (by Rice's theorem):
- "Is ?" (the emptiness problem) — non-trivial, hence undecidable.
Other consequences: "Is regular?", "Is finite?", "Does contain a particular string ?" — all undecidable, since each is a non-trivial property of the recognised language.
(a) Explain the difference between a deterministic PDA (DPDA) and a non-deterministic PDA (NPDA), and state which class of languages each accepts.
(b) State the pumping lemma for context-free languages and explain how it is used to show that a language is not context-free.
(a) DPDA vs NPDA
| Deterministic PDA (DPDA) | Non-deterministic PDA (NPDA) | |
|---|---|---|
| Transition | At most one move possible in any configuration; no choice. (At most one of an input-move or a corresponding -move applies.) | A configuration may allow several moves (a set of next configurations). |
| Languages accepted | Deterministic context-free languages (DCFL) — a proper subset of CFLs | All context-free languages (CFL) |
| Power | Strictly weaker | Strictly more powerful |
| Example only NPDA handles | (even-length palindromes) needs non-determinism | — |
Unlike finite automata (where DFA = NFA in power), for PDAs NPDA is strictly more powerful than DPDA: e.g. the language of even-length palindromes is context-free but not deterministic context-free.
(b) Pumping Lemma for Context-Free Languages
If is context-free, there is a constant (pumping length) such that every with can be written as
satisfying:
- ,
- (i.e. and are not both empty),
- for all .
How it is used (proof by contradiction). To show a language is not context-free:
- Assume is context-free with pumping length .
- Choose a specific string with (chosen cleverly).
- For every allowed decomposition with and , find some (usually or ) such that .
- This contradicts condition 3, so the assumption fails and is not context-free.
Illustration: for , take ; since , spans at most two of the three symbol blocks, so pumping () unbalances the counts and the result leaves — proving is not context-free.
Frequently asked questions
- Where can I find the BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) question paper 2078?
- The full BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2078 (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) 2078 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) 2078 paper?
- The BE Computer Engineering (IOE, TU) Theory of Computation (IOE, CT 502) 2078 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.