BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) Question Paper 2079 Nepal
This is the official BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) question paper for 2079, as set in the regular annual examination. It carries 100 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Theory of Computation (PU, CMP 264) 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 (Pokhara University) Theory of Computation (PU, CMP 264) 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) Distinguish between a Deterministic Finite Automaton (DFA) and a Non-deterministic Finite Automaton (NFA) with respect to their transition functions and computational power. (4)
(b) Consider the NFA over the alphabet with start state , accepting state , and the following transitions: , , . Convert into an equivalent DFA using the subset construction method, showing the resulting state table and the corresponding state diagram. (8)
(a) DFA vs NFA (4 marks)
| Aspect | DFA | NFA |
|---|---|---|
| Transition function | — exactly one next state for each (state, symbol) pair. | — a set of next states (possibly empty); may include -moves. |
| Determinism | No choice; computation is a single path. | Multiple choices; computation is a tree of paths. |
| Acceptance | Unique run; accept if it ends in a final state. | Accept if at least one run ends in a final state. |
| -moves | Not allowed. | Allowed. |
Computational power: DFA and NFA are equivalent — they recognize exactly the same class of languages (the regular languages). Every NFA can be converted to an equivalent DFA by subset construction. NFAs are often more compact (an -state NFA may need up to DFA states), but they accept no language a DFA cannot.
(b) Subset construction of (8 marks)
NFA: states , start , accept . , , . (All other moves ; no -moves.)
Start DFA state . Compute reachable subsets:
| DFA state | on 0 | on 1 |
|---|---|---|
- on 0 from : .
- on 1 from : .
- on 1 from : .
Renaming: (start), , (accepting, since it contains ).
| State | 0 | 1 | Accept? |
|---|---|---|---|
| no | |||
| no | |||
| yes |
State diagram (described): Start at . loops on and goes to on . loops on and goes to on . (double circle, accepting) goes to on and back to on .
The DFA accepts exactly those strings containing the substring 01 (the NFA's condition for reaching ), which matches the original NFA.
(a) Define a Context-Free Grammar (CFG) formally as a 4-tuple. Show that the grammar with productions is ambiguous by giving two distinct parse trees for the string . (6)
(b) Construct a Pushdown Automaton (PDA) that accepts the language by final state. Clearly specify the transition function and trace the acceptance of the string . (6)
(a) CFG definition and ambiguity (6 marks)
A Context-Free Grammar is a 4-tuple where:
- = finite set of variables (non-terminals),
- = finite set of terminals, ,
- = finite set of productions of the form with and ,
- = the start symbol.
Ambiguity: A grammar is ambiguous if some string has two or more distinct parse trees (equivalently, two distinct leftmost derivations).
For and the string :
Parse tree 1 — + applied last (groups as ):
E
/ | \
E + E
| /|\
id E * E
| |
id id
Parse tree 2 — * applied last (groups as ):
E
/ | \
E * E
/ |\ |
E + E id
| |
id id
Two different parse trees for the same string the grammar is ambiguous.
(b) PDA for by final state (6 marks)
PDA with , , , start , . Idea: push one per , pop one per ; accept when stack returns to after at least one matched pair.
Transitions (form ):
- — first .
- — subsequent 's.
- — first , start matching.
- — match remaining 's.
- — stack empty (of 's) accept.
Trace on aabb (config = (state, remaining input, stack), top on left):
| Step | State | Input left | Stack | Rule |
|---|---|---|---|---|
| 0 | start | |||
| 1 | (1) | |||
| 2 | (2) | |||
| 3 | (3) | |||
| 4 | (4) | |||
| 5 | (5) |
Input consumed and PDA is in final state aabb is accepted.
(a) Design a Turing Machine that accepts the language . Give the transition table and explain the working of your machine on the input . (8)
(b) State the Halting Problem and prove that it is undecidable. (4)
(a) Turing Machine for equal 's and 's (8 marks)
Idea: Repeatedly scan the tape, mark one unmatched (as ) and one unmatched (as ) per pass, crossing them off. If the tape becomes all //blank (no unmatched or remains), accept. The empty string is accepted.
States: (find an ), (move right seeking a ), (move left to start), , . Symbols ( = crossed-out ).
| State | |||||
|---|---|---|---|---|---|
Working: marks the leftmost unmatched as then in searches right for a to mark as ; or if it first meets a it marks it and in searches for a matching . rewinds to the left end and re-enters . When scans the whole tape and reaches with no unmatched or , it accepts.
Run on abba:
- at
awrite , go right:Xbba. - meets first
bwrite , go left:XYba. - rewinds to left end, re-enters .
- skips , meets
bwrite , go right:XYYa. - meets
awrite , go left:XYYX. - rewinds, scans
XYYXthen : no unmatched symbol accept. (abbahas 2 's and 2 's.)
(b) Halting Problem and undecidability (4 marks)
Halting Problem: Given the description of a Turing machine and an input , decide whether halts on . Formally .
Proof of undecidability (diagonalization): Suppose a TM decides : accepts if halts on , rejects otherwise. Build a TM that, on input :
- runs ;
- if says "halts," then loops forever;
- if says "does not halt," then halts.
Now run on its own description :
- If halts on , then reported "halts," so loops — contradiction.
- If does not halt on , then reported "does not halt," so halts — contradiction.
Both cases are contradictory, so cannot exist. Therefore the Halting Problem is undecidable.
(a) State the rules for constructing regular expressions and write a regular expression over for the language of all strings that contain at least two consecutive 's and end with a . (5)
(b) State the Pumping Lemma for regular languages and use it to prove that the language is not regular. (7)
(a) Regular-expression rules + construction (5 marks)
Inductive rules for regular expressions over alphabet :
- is a RE (denotes ), is a RE (denotes ), and each is a RE (denotes ). (Basis)
- If and are REs, then so are: union , concatenation , Kleene star , and parenthesization . (Induction)
- Nothing else is a RE. Precedence: .
Required language: all strings over that contain at least two consecutive 's (substring 00) and end with 1.
This forces an occurrence of 00 somewhere, allows any symbols around it, and ends in 1. (Equivalent forms are acceptable.)
(b) Pumping Lemma and non-regularity of (7 marks)
Pumping Lemma (regular languages): If is regular, there exists a constant (the pumping length) such that every string with can be written with:
- ,
- ,
- for all .
Proof that is not regular (by contradiction):
Assume is regular with pumping length . Choose , . By the lemma, with and .
Since , the first symbols of are all 's, so and consist only of 's. Write with .
Pump with : . This has 's but only 's, and since the counts differ, so .
This contradicts condition (3) of the pumping lemma. Hence is not regular.
Section B: Short Answer Questions
Attempt all / any as specified.
Design a DFA over the alphabet that accepts all strings in which the number represented by the binary string is divisible by (read most significant bit first). Draw the state diagram and briefly justify each state.
DFA for binary numbers divisible by 3 (MSB first)
Idea: Track the value of the prefix read so far modulo 3. Reading a bit updates the running value to , so the residue updates as . Three states represent the three possible remainders.
States: (remainder 0, start and accepting), (remainder 1), (remainder 2).
Transition table (using ):
| State (rem) | on 0 | on 1 |
|---|---|---|
| (0) | ||
| (1) | ||
| (2) |
Derivations: from on 0: ; on 1: . From on 0: ; on 1: . From on 0: ; on 1: .
State diagram (described): Three states . is start and double-circled (accept). Edges as in the table. The empty string and 0 map to (value 0, divisible by 3); e.g. 110 (=6) traces , ending accepting.
Justification of states: Each state is the equivalence class of all prefixes whose value that remainder mod 3; only the remainder matters for future divisibility, so exactly 3 states suffice, and acceptance is exactly remainder 0.
Convert the regular expression into an equivalent NFA with epsilon-transitions using Thompson's construction. Show each step of the construction.
Thompson's construction for
Thompson's construction builds an -NFA inductively, one operator at a time; each sub-NFA has exactly one start and one accept state.
Step 1 — atoms and :
- : .
- : .
Step 2 — union : add new start and accept :
- , (choose a branch),
- , (rejoin).
Step 3 — Kleene star : add new start and accept :
- (enter loop body once),
- (skip — accept empty),
- (repeat),
- (exit).
Step 4 — concatenation with then :
- Atom : ; atom : .
- Concatenate the star NFA, then , then by linking accept-to-start with (or by merging):
- ,
- .
Final -NFA: start state , single accept state .
ε ε a ε
s4 ---ε---> s3 region (a|b)* ---ε---> f4 ---ε---> s5 --a--> f5 ---ε---> s6 --b--> f6 (accept)
\
---ε--> f4 (skip loop)
Where the block inside the star is: , , , , with the star back-edge and exit .
The resulting NFA accepts any number of / symbols (the star) followed by the literal ab.
Convert the following context-free grammar into Chomsky Normal Form (CNF):
Convert to Chomsky Normal Form
Grammar: , , .
Step 1 — add new start symbol : .
Step 2 — remove -productions. Nullable: (from ), and (since ). Remove and add versions of productions with nullable symbols omitted.
- gives (drop each nullable ): .
- gives: .
- stays (but now non-nullable form); stays. Remove if introduced — was nullable only via , so no unit.
- stays.
Now: ; ; ; .
Step 3 — remove unit productions. Unit pairs: (drop, trivial), , , .
- : .
- : . : .
- Drop .
Now:
Step 4 — replace terminals in long bodies. Introduce . Replace in : .
Step 5 — break bodies longer than 2. has length 3; introduce , so where .
Resulting CNF grammar:
Every production is now of the form (two variables) or (single terminal), i.e. valid CNF.
Differentiate between deterministic and non-deterministic pushdown automata. Construct a PDA equivalent to the grammar and explain why this language cannot be accepted by any finite automaton.
Deterministic vs Non-deterministic PDA
| Aspect | DPDA | NPDA (NDPDA) |
|---|---|---|
| Transition | At most one applicable move per (state, input, stack-top); -moves restricted so no choice. | May have several applicable moves; explores all in parallel. |
| Power | Accept exactly the deterministic CFLs (a proper subset). | Accept all context-free languages. |
| Example gap | Cannot accept (even-length palindromes). | Can accept . |
So NPDAs are strictly more powerful than DPDAs (unlike finite automata, where NFA = DFA). Every DPDA language is context-free, but not every CFL is a DPDA language.
PDA equivalent to
This grammar generates . Construct a PDA (acceptance by empty stack), :
- — push on first .
- — push for each further .
- — pop one per .
- — empty stack to accept (handles and the matched case).
Trace aabb: — accepted. The empty string is accepted directly by rule 4.
Why no finite automaton accepts
requires counting an unbounded number of 's to match the same number of 's. A finite automaton has only finitely many states and no memory (no stack), so it cannot distinguish among the infinitely many prefixes . By the pumping lemma for regular languages, pumping unbalances the counts, proving is not regular. The PDA's stack supplies exactly the unbounded counting memory an FA lacks.
(a) Explain the formal definition of a standard (single-tape) Turing Machine as a 7-tuple. (3)
(b) Briefly describe a multi-tape Turing Machine and state whether it is more powerful than a single-tape Turing Machine, justifying your answer. (3)
(a) Standard Turing Machine as a 7-tuple (3 marks)
A (deterministic, single-tape) Turing Machine is where:
- = finite set of states;
- = input alphabet, with blank ;
- = tape alphabet, and ;
- = transition function (read symbol, write symbol, move head Left/Right);
- = start state;
- = accept state;
- = reject state ().
(b) Multi-tape Turing Machine (3 marks)
A multi-tape TM has tapes, each with its own independent read/write head. Its transition function reads the symbols under the heads at once and writes symbols, moving each head independently:
The input starts on tape 1; the other tapes start blank and serve as scratch memory.
Is it more powerful? No — it is equally powerful in terms of the languages it recognizes. Every multi-tape TM can be simulated by a single-tape TM (store the tapes' contents interleaved on one tape, marking head positions, and sweep the tape to simulate each step). Both models recognize exactly the recursively enumerable languages, confirming the Church–Turing thesis. The only difference is efficiency: a -step multi-tape computation costs steps on a single tape, so multi-tape gives a polynomial speedup but no extra computational power.
Differentiate between recursive (decidable) and recursively enumerable languages with the help of suitable examples. Explain the relationship between the two classes using a closure-under-complement argument.
Recursive vs Recursively Enumerable languages
Recursive (decidable) language: A language is recursive if there is a Turing machine that halts on every input and decides membership — it accepts every and rejects (halts) every . The machine is a total decider.
Recursively enumerable (RE / Turing-recognizable): is RE if there is a TM that accepts every , but on it may reject or run forever (it need not halt). The machine is a recognizer, not necessarily a decider.
| Recursive | Recursively Enumerable | |
|---|---|---|
| Halts on members | yes (accept) | yes (accept) |
| Halts on non-members | yes (reject) | not guaranteed (may loop) |
| Decision procedure | exists | not guaranteed |
Examples:
- Recursive: , or any CFL, or has states — membership is always decidable.
- RE but not recursive: accepts (the acceptance/halting problem) — recognizable by a universal TM that simulates on , but undecidable.
Relationship via closure under complement
- Every recursive language is RE (a decider is also a recognizer): .
- Recursive languages are closed under complement: if decides , swap its accept/reject states to decide (it still always halts).
- Key theorem: is recursive iff both and are RE. Run recognizers for and in parallel; on any input exactly one accepts, giving a decider that always halts.
- RE is not closed under complement. Since is RE but undecidable, its complement cannot be RE — otherwise would be recursive. Thus , and is an example of a language that is not even RE.
(a) Define the complexity classes and and explain what is meant by an -complete problem. (4)
(b) State the significance of the versus question and give one example of a well-known -complete problem. (3)
(a) P, NP, and NP-completeness (4 marks)
- (Polynomial time): the class of decision problems solvable by a deterministic Turing machine in time for some constant , where is the input size. These are the problems regarded as efficiently solvable.
- (Non-deterministic Polynomial time): the class of decision problems for which a proposed solution (certificate) can be verified by a deterministic TM in polynomial time; equivalently, solvable by a non-deterministic TM in polynomial time. Clearly .
- -complete: a problem is NP-complete if (1) , and (2) every problem in reduces to in polynomial time ( is NP-hard). NP-complete problems are the "hardest" in : if any one of them is in , then .
(b) Significance of P vs NP, and an example (3 marks)
Significance: The question asks whether every problem whose solution can be verified quickly can also be solved quickly. It is one of the seven Millennium Prize Problems. If , thousands of important optimization, scheduling, and cryptographic-breaking problems would have efficient algorithms; if (widely believed), no polynomial-time algorithm exists for NP-complete problems, which underpins the security of modern cryptography. It remains open.
Example of an NP-complete problem: The Boolean Satisfiability problem (SAT) — deciding whether a Boolean formula has a satisfying assignment — was the first proven NP-complete problem (Cook–Levin theorem). Other examples: the Travelling Salesman (decision) problem, 3-SAT, Vertex Cover, Hamiltonian Cycle, and Subset Sum.
Using the principle of mathematical induction, prove that for every integer , the number of distinct strings of length over an alphabet with is exactly . Clearly state the basis and the inductive step.
Proof by induction: number of strings of length over is
Let be the statement: the number of distinct strings of length over an alphabet with equals .
Basis (): A string of length 1 is just a single symbol from . There are exactly choices, and . So holds.
(Optional stronger basis : there is exactly one string of length 0, the empty string , and , so it also holds.)
Inductive hypothesis: Assume is true for some integer , i.e. there are exactly distinct strings of length .
Inductive step — show : Every string of length is obtained uniquely by taking a string of length and appending one symbol to its end, giving .
- By the inductive hypothesis there are choices for .
- There are choices for the appended symbol .
- Different pairs produce different strings, and every length- string arises from exactly one such pair.
By the multiplication (product) rule, the number of strings of length is
Thus holds.
Conclusion: By the principle of mathematical induction, holds for every integer : the number of distinct strings of length over an alphabet of size is exactly .
Frequently asked questions
- Where can I find the BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) question paper 2079?
- The full BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 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 (PU, CMP 264) 2079 paper come with solutions?
- Yes. Every question on this Theory of Computation (PU, CMP 264) 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 (Pokhara University) Theory of Computation (PU, CMP 264) 2079 paper?
- The BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 2079 paper carries 100 full marks and is meant to be completed in 180 minutes, across 12 questions.
- Is practising this Theory of Computation (PU, CMP 264) past paper free?
- Yes — reading and attempting this Theory of Computation (PU, CMP 264) past paper on Kekkei is completely free.