BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) Question Paper 2078 Nepal
This is the official BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) question paper for 2078, 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 2078 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), clearly stating the role of the transition function in each. (5)
(b) Consider the NFA with -transitions over the alphabet that accepts strings containing the substring 01 or ending in 00. Construct an equivalent DFA using the subset (powerset) construction method, showing the resulting state-transition table and the final transition diagram. (10)
(a) DFA vs NFA (5 marks)
| Aspect | DFA | NFA |
|---|---|---|
| Transition function | — exactly one next state for each (state, symbol) pair | — a set of next states (0, 1 or more), and -moves allowed |
| Determinism | Next move is uniquely determined | Several moves may be possible; machine "guesses" |
| -moves | Not allowed | Allowed |
| Acceptance | Single computation path; accept if it ends in a final state | Accept if some path ends in a final state |
| Implementation | Directly executable | Needs simulation / conversion to DFA |
Role of the transition function: In a DFA, is a total function returning a single state, so the run is deterministic. In an NFA, returns a set of states, so from one configuration the machine may proceed along many branches in parallel. Both recognise exactly the regular languages (Rabin–Scott theorem), and every NFA can be converted to an equivalent DFA by subset construction.
(b) NFA → DFA by subset construction (10 marks)
We want strings over that contain 01 OR end in 00. An NFA for this (states for the two patterns merged) has the following -free transitions. Let the start state be . We design directly:
- : looking for either pattern
- : just saw a
0(potential start of01or00) - : substring
01found — accept (and stay accepting) - : saw
00so far — accept, but pattern may be broken by later input unless string ends here
NFA transition relation :
| State | on 0 | on 1 |
|---|---|---|
| (final) | ||
| (final) |
Final states of : (note accepts only when the string ends right after 00).
Subset construction. Start = .
| DFA state | on 0 | on 1 |
|---|---|---|
| (final) | ||
| (final) | ||
| (final) |
Final (accepting) DFA states: every subset containing or , i.e. (contains ), (contain ). is accepting because reaching it means 00 was just read.
Transition diagram (described):
- Start arrow into .
- , .
- , .
- , .
- , (self-loop).
- , .
- (self-loop), .
- Double circles (final): .
Once the DFA enters (substring 01 seen) it can never leave the accepting region, exactly capturing the "contains 01" condition, while capture "ends in 00".
(a) Define a Context-Free Grammar (CFG) formally as a 4-tuple. Design a CFG that generates the language and show a leftmost derivation for the string aabccbb... if it belongs to (justify your answer). (7)
(b) Convert the following grammar into Chomsky Normal Form (CNF), showing each step (removal of -productions, unit productions, and useless symbols): (8)
(a) CFG definition and design (7 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 ,
- = start symbol.
Grammar for :
Here the -rules generate matching outer pairs (), and generates the matched inner pairs ().
Is aabccbb in ? A string of must have the strict order : all 's, then 's, then 's, then 's, with and . The string aabccbb has letters in the order — a b appears after c, and there is no d. So the order is violated and . Hence aabccbb , and no derivation exists.
(For completeness, a valid string such as aabccd has the leftmost derivation:
? — note must equal . Take aabccd is invalid too since . A correct member is aabbccdd:*
(b) Conversion to Chomsky Normal Form (8 marks)
Given .
Step 1 — Add new start symbol. (so the start symbol never appears on a RHS).
Step 2 — Remove -productions. Nullable variables: (from ). does not become nullable (the stays). Substitute nullable in all RHSs and drop :
- (drop one or both … here only outer/inner in is the middle ): with the removed gives . So .
- (remove from gives )
- (delete each nullable )
Step 3 — Remove unit productions. Units: , .
- inherits 's rules: .
- ⇒ inherits 's rules: . Now .
Step 4 — Remove useless symbols. All of are reachable and generate terminal strings, so none are removed.
Step 5 — Make all bodies length-2 of variables, or a single terminal. Introduce terminal variables , , and break long bodies with helper variables.
Final CNF grammar:
S0 -> A C1 | A B (C1 -> S B)
S -> A C1 | A B
A -> X_a C2 | X_a A | a (C2 -> A S)
B -> S C3 | S X_b | X_b S | b | X_b X_b
| X_a C2 | X_a A | a
(C3 -> X_b S)
C1 -> S B
C2 -> A S
C3 -> X_b S
X_a -> a
X_b -> b
Every production now has the form (two variables) or (single terminal), so the grammar is in Chomsky Normal Form.
(a) Describe the formal model of a standard (single-tape) Turing Machine as a 7-tuple and explain how it accepts, rejects, or loops on an input string. (5)
(b) Design a Turing Machine that accepts the language , where denotes the reverse of . Give the complete transition table and trace the computation of the machine on the input string abcba. (10)
(a) Formal model of a single-tape Turing Machine (5 marks)
A standard Turing Machine is a 7-tuple where:
- = finite set of states,
- = input alphabet (blank ),
- = tape alphabet, and ,
- = transition function (read symbol, write symbol, move head Left/Right),
- = start state,
- = accepting and rejecting (halting) states, .
Behaviour on input : starts in with on the tape and head on the first symbol. At each step it reads the current cell, writes a symbol, moves L or R, and changes state per . There are three outcomes:
- Accept — it reaches (halts, );
- Reject — it reaches (halts, );
- Loop — it never halts.
A language is recursively enumerable if some TM accepts it; it is recursive (decidable) if some TM halts on every input (never loops).
(b) TM for (10 marks)
Idea: Match the outermost symbols against the innermost, working from both ends toward the centre c. Read and erase (mark) the first unmarked symbol, then move right to the corresponding last unmarked symbol and check it equals the one remembered. The single center c must remain when all of are matched.
Let mark a consumed cell. States: (start/find left symbol), (carry remembered symbol rightward), (after matching, return left), (check center), , .
Transition table (entry = write, move, next state):
| State | a | b | c | X | |
|---|---|---|---|---|---|
| move L, check a | |||||
| move L, check b | |||||
| (need a at right end) | (last sym is a) | (b) | — | — | — |
| (need b at right end) | (a) | — | — | — | |
| — | |||||
| — |
(In words: scan right to the rightmost unmarked symbol; states verify that symbol matches the remembered one and mark it; rewinds to the left end; checks that only the single c remains, then accepts.)
Trace on abcba (tape shown, head position underlined conceptually; = matched):
a b c b a, : reada→ mark, remember a, go right:X b c b a, .- scans right over
b,c,bto lasta; matches remembereda→ mark:X b c b X, return left. - Back at left, reads
b→ mark, remember b:X X c b X, . - scans right to last unmarked
b; matches → mark:X X c X X, return left. - reads
c→ enter center-check : tapeX X c X X, only the singlecis unmatched, surrounding all → accept.
Since every / on the left matched its mirror on the right and exactly one c separates them, abcba (, ) is accepted.
(a) Explain the formal definition of a Pushdown Automaton (PDA) and distinguish between acceptance by final state and acceptance by empty stack. (5)
(b) Construct a PDA that accepts the language by empty stack. Give the transition function and show the sequence of instantaneous descriptions (moves) for the input string aabbbb. (10)
(a) PDA definition; final state vs empty stack (5 marks)
A Pushdown Automaton is a 7-tuple where:
- = finite set of states,
- = input alphabet,
- = stack alphabet,
- finite subsets of (transition function),
- = start state,
- = initial stack symbol,
- = set of final states.
A PDA augments a finite control with an unbounded stack (LIFO), giving it the extra memory needed to recognise context-free languages.
Acceptance by final state: the input is accepted if, after reading all input, the PDA is in some state of (stack contents irrelevant):
Acceptance by empty stack: the input is accepted if, after reading all input, the stack is empty (final state irrelevant):
The two modes recognise the same class (context-free languages); each can be converted to the other.
(b) PDA for by empty stack (10 marks)
Idea: For each a, push two stack symbols; for each b, pop one. Then a's push markers and b's pop them, leaving the stack empty exactly when the count matches.
Let (empty-stack acceptance).
Transition function:
- — first
a: push two 's above . - — each further
a: push two more 's. - — first
b: pop one , switch to . - — each further
b: pop one . - — when all 's gone, pop to empty the stack.
Moves (instantaneous descriptions) on aabbbb (, so b's):
All input is consumed and the stack is empty, so aabbbb is accepted. The two a's pushed four 's, the four b's popped them, and was finally popped — confirming .
Section B: Short Answer Questions
Attempt all / any as specified.
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 split as satisfying:
- (i.e. ),
- ,
- for all .
Proof that is not regular
Assume, for contradiction, that is regular with pumping length .
Choose . Then , so and .
By the lemma, with and . Since the first symbols of are all a's, both and lie within the -block, so for some .
Now pump down with : .
The number of a's is , while the number of b's is still . So , which violates the requirement . Hence .
This contradicts the pumping lemma. Therefore is not regular.
(a) Write regular expressions over for: (i) all strings of even length, and (ii) all strings in which every 0 is immediately followed by at least one 1. (4)
(b) State the identities used to simplify regular expressions and use them to simplify . (3)
(a) Regular expressions (4 marks)
(i) All strings of even length over — any two symbols repeated zero or more times:
(The empty string, of length 0, is included.)
(ii) Every 0 is immediately followed by at least one 1. A 0 may never be the last symbol and never be directly followed by another 0. Equivalently, every 0 comes as the block 01. Such strings are made of the blocks 1 and 01 repeated:
(b) Identities for regular expressions and simplification (3 marks)
Useful algebraic identities (with = empty set, = empty string):
- (idempotence of )
- (identity of concatenation)
- ,
- ,
Simplify :
using the identity on each factor. The resulting expression denotes all strings over containing exactly one 1.
Differentiate between a decidable and an undecidable problem. State the Halting Problem and give an outline of the argument (proof by contradiction) showing that 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 answers "yes" or "no" correctly. Example: "Does DFA accept string ?"
- An undecidable problem is one for which no such always-halting algorithm exists; any TM that decides it must loop forever on at least some inputs. Undecidable problems may still be recognisable (semi-decidable) if a TM halts and accepts on "yes" instances but may loop on "no" instances.
The Halting Problem
Statement: Given (an encoding of) an arbitrary Turing machine and an input string , decide whether halts when run on . Formally, decide membership in
The Halting Problem is undecidable.
Proof outline (by contradiction / diagonalization):
- Suppose a TM decides : halts and outputs "halts" if halts on , and "loops" otherwise.
- Construct a new machine that takes input and runs on (i.e. asks whether halts on its own description):
- 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 loops on — contradiction.
- If loops on , then by construction halts on — contradiction.
- Either way we reach a contradiction, so the assumed decider cannot exist.
Therefore the Halting Problem is undecidable.
(a) Define the complexity classes P, NP, and NP-Complete, and explain the significance of the question. (4)
(b) What is a polynomial-time reduction? Explain its role in proving that a problem is NP-complete. (3)
(a) P, NP, NP-Complete and the P =? NP question (4 marks)
- P (Polynomial time): the class of decision problems solvable by a deterministic Turing machine in time polynomial in the input size, . These are the "efficiently solvable" problems (e.g. sorting, shortest path, primality).
- NP (Nondeterministic 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 nondeterministic TM in polynomial time. .
- NP-Complete: a problem is NP-complete if (i) , and (ii) every problem in NP reduces to in polynomial time ( is NP-hard). These are the "hardest" problems in NP; SAT was the first proved NP-complete (Cook–Levin theorem).
Significance of : It asks whether every problem whose solution can be verified quickly can also be solved quickly. If , every NP-complete problem (SAT, TSP, etc.) would have an efficient algorithm, with huge consequences (e.g. cryptography would break). It is one of the major open problems in computer science; it is widely conjectured that .
(b) Polynomial-time reduction and its role (3 marks)
A polynomial-time (many-one) reduction from problem to problem , written , is a function computable in polynomial time such that for every input :
It transforms instances of into instances of while preserving yes/no answers, in polynomial time.
Role in NP-completeness proofs: To prove a new problem is NP-complete we (1) show , and (2) pick a known NP-complete problem and show . Because every problem in NP already reduces to , and reductions compose, this makes NP-hard; together with , is NP-complete. The reduction "transfers hardness": if had a polynomial algorithm, so would and hence all of NP.
Differentiate between a Moore machine and a Mealy machine. Design a Mealy machine over that outputs 1 whenever the input sequence ends in the substring 101, and 0 otherwise.
Moore vs Mealy machine
| Aspect | Moore machine | Mealy machine |
|---|---|---|
| Output depends on | State only | State and current input |
| Output function | ||
| Output associated with | states (nodes) | transitions (edges) |
| Output for input of length | symbols (includes initial-state output) | symbols |
| Reaction speed | one cycle delay | immediate (same cycle) |
| Typically | needs more states | fewer states |
Both are finite-state transducers and are equivalent in expressive power (each can be converted to the other).
Mealy machine that outputs 1 when input ends in 101
We track how much of the suffix 101 has been seen. Output is on each transition (1 only when the move completes 101).
States:
- — no useful suffix (start)
- — last symbol matched
1(prefix1of101) - — last symbols matched
10(prefix10)
Transition / output table (next state, output):
| State | input 0 | input 1 |
|---|---|---|
| , 0 | , 0 | |
| , 0 | , 0 | |
| , 0 | , 1 |
Explanation of key edges:
- From (
10seen) on input1we complete101→ output 1, and the trailing1is itself a fresh prefix, so we go to . - On any
1we move to (a1always starts a new potential match), except the accepting edge above which also lands in . - On
0from we have10→ go to ; on0from the partial match breaks → .
Trace on 1101: . Output stream 0001 — the final 1 correctly signals that the input ends in 101.
Define an ambiguous grammar. Show that the grammar is ambiguous by giving two distinct parse trees for the string id + id * id.
Ambiguous grammar
A context-free grammar is ambiguous if there exists at least one string that has two or more distinct parse trees (equivalently, two distinct leftmost derivations, or two distinct rightmost derivations). Ambiguity is a property of the grammar, not of the language.
Showing is ambiguous
The string id + id * id has two different parse trees because the grammar does not fix the precedence of + and *.
Parse tree 1 — interprets as (multiplication grouped first):
E
/ | \
E + E
| /|\
id E * E
| |
id id
Leftmost derivation: .
Parse tree 2 — interprets as (addition grouped first):
E
/ | \
E * E
/|\ |
E + E id
| |
id id
Leftmost derivation: .
Both trees derive the same terminal string id + id * id but have different structures (root operator + vs *). Since one string has two distinct parse trees, the grammar is ambiguous.
(This is usually fixed by introducing precedence/associativity levels: .)
(a) State and briefly justify any three closure properties of regular languages (e.g. under union, concatenation, and complementation). (4)
(b) Define the terms recursive language and recursively enumerable language, and state the relationship between them. (3)
(a) Three closure properties of regular languages (4 marks)
Let be regular languages over .
- Union: is regular. Justification: given NFAs (or regular expressions) for them, describes the union; equivalently a new start state with -moves to both NFAs accepts .
- Concatenation: is regular. Justification: the regular expression denotes it; or link the final states of the first NFA by -moves to the start of the second.
- Complementation: is regular. Justification: take a complete DFA for and swap accepting and non-accepting states; the resulting DFA accepts exactly the strings rejects.
(Other closures: intersection, Kleene star, reversal, difference — all regular.)
(b) Recursive and recursively enumerable languages (3 marks)
- A language is recursive (decidable) if there is a Turing machine that halts on every input and accepts exactly the strings in (it answers yes/no for all inputs and always terminates).
- A language is recursively enumerable (RE / Turing-recognisable) if there is a Turing machine that accepts (halts on) every string in , but on strings not in it may either reject or loop forever.
Relationship: Every recursive language is recursively enumerable, i.e. Recursive RE. The containment is strict: there exist RE languages that are not recursive (e.g. the language of the Halting Problem). Also, is recursive iff both and its complement are recursively enumerable.
(a) State the Church-Turing thesis and explain its significance in the theory of computation. (4)
(b) Briefly explain how a multi-tape Turing machine is equivalent in computational power to a single-tape Turing machine. (3)
(a) Church–Turing Thesis (4 marks)
Statement: Every function that is effectively computable (computable by any well-defined mechanical/algorithmic procedure) can be computed by a Turing machine. In other words, the intuitive notion of "algorithm" coincides exactly with what Turing machines can compute.
It is a thesis (hypothesis), not a theorem, because "effectively computable" is an informal notion that cannot be proved equal to a formal model. Its strong support comes from the fact that every reasonable model of computation proposed — -calculus, recursive functions, RAM machines, while-programs, modern programming languages — has been shown equivalent in power to the Turing machine.
Significance:
- It justifies using the Turing machine as the standard definition of computability and algorithm.
- It lets us prove a problem is unsolvable by any algorithm by showing no Turing machine solves it (e.g. the Halting Problem).
- It underpins the whole theory of decidability and the classification of problems.
(b) Multi-tape TM equivalence to single-tape TM (3 marks)
A multi-tape TM has tapes each with its own independent head; one step reads/writes/moves all heads. It is clearly at least as powerful as a single-tape TM.
Single-tape simulation: A single-tape TM can simulate a -tape TM by storing the contents of all tapes on its one tape, separated by a delimiter , and marking each tape's head position with a special "dotted" symbol:
To simulate one step of , sweeps left-to-right over the whole tape to read the marked symbols, then sweeps again to write the new symbols and shift the dot markers, expanding the tape if a head runs off its region.
Conclusion: recognises exactly the same language as , so multi-tape and single-tape TMs are equivalent in computational power (they recognise the same class — the recursively enumerable languages). The only cost is efficiency: steps of take steps on .
Frequently asked questions
- Where can I find the BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) question paper 2078?
- The full BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 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 (PU, CMP 264) 2078 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) 2078 paper?
- The BE Computer Engineering (Pokhara University) Theory of Computation (PU, CMP 264) 2078 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.