CSC262 ยท TU past paper
Theory of Computation 2076 question paper
The complete TU 2076 exam paper for Theory of Computation (CSC262), all 12 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- Q1.10 marksReduction of Regular Expression to ฮต โ NFAHideAnswer
Define the NFA with ฯตโtransition\epsilon-transitionฯตโtransition and ฯตโclosure\epsilon-closureฯตโclosure of a state. Show that for every regular expression r, representing a language L, there is ฯตโNFA\epsilon-NFAฯตโNFA accepting the same language. Also convert regular expression (a+b)ab into equivalent Finite Automata.[10]
NFA with ฮต-Transition, ฮต-Closure, and Regular Expression to FA Conversion
1. NFA with ฮต-Transition (ฮต-NFA)
An NFA with ฮต-transition (also called ฮต-NFA) is a Nondeterministic Finite Automaton that allows transitions on the empty string ฮต (without consuming any input symbol).
Formally, an ฮต-NFA is defined as a 5-tuple:
M = (Q, ฮฃ, ฮด, qโ, F)
where:
- Q = finite set of states
- ฮฃ = finite input alphabet
- ฮด : Q ร (ฮฃ โช {ฮต}) โ 2^Q = transition function (can take ฮต as input)
- qโ โ Q = start state
- F โ Q = set of final/accepting states
The key difference from a standard NFA is that the transition function accepts ฮต as a valid input, allowing the automaton to move from one state to another without reading any symbol.
2. ฮต-Closure of a State
The ฮต-closure of a state q is the set of all states reachable from q by following zero or more ฮต-transitions (including q itself).
ฮต-closure(q) = {p โ Q | p is reachable from q using only ฮต-transitions}
Properties:
- q is always in ฮต-closure(q) (reflexive)
- If p โ ฮต-closure(q) and r โ ฮต-closure(p), then r โ ฮต-closure(q) (transitive)
Example: If q --ฮต--> p --ฮต--> r, then ฮต-closure(q) = {q, p, r}
3. Theorem: For Every Regular Expression r, There Exists an ฮต-NFA Accepting L(r)
Proof by Structural Induction (Thompson's Construction Rules):
We show construction rules for each case of a regular expression.
Base Cases
Rule 1: r = โ (empty language)
โ[qโ] (no transitions, no final state)The ฮต-NFA has start state qโ with no accepting states.
Rule 2: r = ฮต (empty string)
โ[qโ] --ฮต--> ((q_f))One ฮต-transition from start to final state.
Rule 3: r = a (single symbol a โ ฮฃ)
โ[qโ] --a--> ((q_f))One transition on symbol a from start to final state.
Inductive Cases
Assume ฮต-NFAs N(r) and N(s) exist for regular expressions r and s.
Rule 4: r = rโ | rโ (Union / Alternation)
Create a new start state and new final state, connect with ฮต-transitions:
ฮต --> [N(rโ)] --> ฮต โ[qโ] --< >--> ((q_f)) ฮต --> [N(rโ)] --> ฮต- New start state qโ goes to start of N(rโ) and N(rโ) via ฮต
- Final states of N(rโ) and N(rโ) go to new final state q_f via ฮต
Rule 5: r = rโ . rโ (Concatenation)
Connect the final state of N(rโ) to the start state of N(rโ) via ฮต:
โ[N(rโ)] --ฮต--> [N(rโ)]-->((q_f))- Final state of N(rโ) becomes non-final
- ฮต-transition connects it to start of N(rโ)
Rule 6: r = rโ (Kleene Star / Closure)*
ฮต (loop back) โ___________โ โ[qโ] --ฮต--> [N(rโ)] --ฮต--> ((q_f)) |_________________________โ ฮต (skip, for empty string)- New start state qโ connects to start of N(rโ) via ฮต
- Final state of N(rโ) loops back to start of N(rโ) via ฮต
- New start state also connects directly to new final state via ฮต (to accept ฮต)
Since every regular expression is built from these base cases and operations, and we have shown an ฮต-NFA construction for each, by induction, every regular expression has an equivalent ฮต-NFA. โ
4. Convert Regular Expression (a+b)ab to Equivalent Finite Automaton
The regular expression is: (a+b)*ab*
This means: strings over {a,b} that contain at least one 'a', ending with zero or more b's -- more precisely, any string of a's and b's, followed by 'a', followed by zero or more b's.
Step 1: Break the expression into parts
Part Meaning (a+b)* Zero or more a's or b's (any string) a Single symbol a b* Zero or more b's
Step 2: Build ฮต-NFA for each part
Part 1: (a+b)*
a ฮต โ[qโ]โ ฮต [qโ] [qโ] --ฮต--> ((qโ)) ฮต โ[qโ]โ ฮต bWith loop: qโ --ฮต--> qโ (for the * closure), and qโ --ฮต--> qโ (for accepting zero repetitions of (a+b), i.e. the empty string). This gives the complete ฮต-NFA fragment for (a+b)*, with qโ as its start state and qโ as its accepting state.
Part 2: Single symbol a
โ[q5] --a--> ((q6))Part 3: b*
ฮต (loop back) โ___________โ โ[q7] --ฮต--> [q8] --b--> ((q9)) |_____________________โ ฮต (skip, for zero b's)
Step 3: Concatenate the Three Parts
By the concatenation rule (Rule 5 above), the accepting state of one block is joined to the start state of the next block with an ฮต-transition, and it stops being an accepting state in its own right (only the final block keeps an accepting state):
- qโ --ฮต--> qโ (end of the (a+b)* block feeds into the mandatory a)
- qโ --ฮต--> qโ (end of the mandatory a feeds into the b* block)
Step 4: Complete ฮต-NFA for (a+b)*ab*
State On ฮต On a On b q0 (start) q1, q2, q4 -- -- q1 -- q3 -- q2 -- -- q3 q3 q0 -- -- q4 q5 -- -- q5 -- q6 -- q6 q7 -- -- q7 q8, q9 -- -- q8 q9 -- q8 q9 (accept) -- -- -- Verification:
- On "ab": q0 --ฮต--> q4 (zero repetitions of (a+b)) --ฮต--> q5 --a--> q6 --ฮต--> q7 --ฮต--> q9 (zero b's). Accepted.
- On "aabb": q0 --ฮต--> q1 --a--> q3 --ฮต--> q0 --ฮต--> q4 --ฮต--> q5 --a--> q6 --ฮต--> q7 --ฮต--> q8 --b--> q8 --b--> q8 --ฮต--> q9. The symbols consumed, in order, are a (one turn of the star), a (the mandatory a), b, b (two turns of b*), i.e. exactly "aabb". Accepted.
This ฮต-NFA accepts precisely the language of (a+b)*ab*: any string over {a, b} (possibly empty), followed by a mandatory a, followed by zero or more b's. This completes the required conversion of the regular expression to an equivalent finite automaton via Thompson's construction.
- Q2.10 marksConversion of PDA by Final State to PDA acHideAnswer
How can you define the language accepted by a PDA? Explain how a PDA accepting language by empty stack is converted into an equivalent PDA accepting by final state and vice-versa.[10]
- Q3.10 marksIntroduction to Turing MachinesHideAnswer
Define a Turing machine. Construct a TM that accept $L = { wcw^R \mid w \in {0, 1} \text{ and } c \text{ is } \varepsilon \text{ or } 0 \text{ or } 1 }$. Show that string 0110 is accepted by this TM with sequence of Instantaneous Description (ID). [10]
- Q4.5 marksDeterministic Finite AutomataHideAnswer
Give the formal definition of DFA. Construct a DFA accepting all strings of {0, 1} with even number of 0's and even number of 1's. [5]
- Q5.5 marksChomsky Normal FormHideAnswer
Define Chomsky Normal Form and Greibach Normal Form in reference to CFG. Give a suitable example of each. [5]
- Q6.5 marksRegular ExpressionsHideAnswer
Give the regular expressions for following language over alphabet {0, 1}. a. Set of all strings with 2nd symbol from right is 1. b. Set of all strings starting with 00 or 11 and ending with 10 or 01. [5]
- Q7.5 marksPumping LemmaHideAnswer
Show that language is not a regular language. $L = { 0^m 1^m \mid m \geq 1 }$ [5]
- Q8.5 marksTuring Machine with Multiple TapesHideAnswer
Describe the Turing machines with multiple tape, multiple track and storage in state. [5]
- Q9.5 marksMethod for reduction of NFA to DFAHideAnswer
Construct a NFA accepting language of {0, 1} with each string ending with 01 and convert it into equivalent DFA. [5]
NFA Accepting Strings Ending with 01, and its Equivalent DFA
Part 1: Constructing the NFA
Language: L = { w | w โ {0,1}* and w ends with 01 }
Example strings: 01, 001, 101, 0001, 1101, ...
NFA States and Design
We need 3 states:
State Role q0 Start state (reading any symbol, staying in loop) q1 Just read '0' (possible start of ending "01") q2 Just read '01' -- Final/Accept state NFA Transition Diagram
0,1 0 1 โโโโโโโโ โโโโโโโโ โโโโโโโโ โ โผ โ โผ โ โผ (q0) โโ0โโโบ (q1) โโ1โโโบ ((q2)) โฒ โโโโโโโโโโโโโโโโโโโโโโโโโโโMore precisely:
- q0 loops on both 0 and 1 (to consume any prefix)
- q0 on input 0 also goes to q1 (non-deterministic choice)
- q1 on input 1 goes to q2 (accept)
- q2 has no outgoing transitions
NFA Transition Table
State Input 0 Input 1 โq0 {q0, q1} {q0} q1 {} {q2} *q2 {} {} โ = start state, * = final state
Part 2: Converting NFA to Equivalent DFA (Subset Construction)
Each DFA state represents a subset of NFA states.
Step 1: Start State
DFA start state = {q0}
Step 2: Compute Transitions for Each DFA State
For {q0}:
- On 0: ฮด(q0, 0) = {q0, q1} โ new state {q0, q1}
- On 1: ฮด(q0, 1) = {q0} โ state {q0}
For {q0, q1}:
- On 0: ฮด(q0,0) โช ฮด(q1,0) = {q0,q1} โช {} = {q0, q1}
- On 1: ฮด(q0,1) โช ฮด(q1,1) = {q0} โช {q2} = {q0, q2} โ new state
For {q0, q2}:
- On 0: ฮด(q0,0) โช ฮด(q2,0) = {q0,q1} โช {} = {q0, q1}
- On 1: ฮด(q0,1) โช ฮด(q2,1) = {q0} โช {} = {q0}
Step 3: DFA Transition Table
DFA State On 0 On 1 Final? โ A = {q0} B = {q0,q1} A = {q0} No B = {q0,q1} B = {q0,q1} C = {q0,q2} No *C = {q0,q2} B = {q0,q1} A = {q0} Yes (contains q2) C is a final state because it contains q2 (the NFA's final state).
Step 4: DFA Transition Diagram
0 0 โโโโโโโโโโโโ โโโโโโโโโโโ โ โผ โ โผ (A) โโ0โโโบ (B) โโ1โโโบ ((C)) โฒ 1 โ โ โโโโโโโโโโโโ 0 โ 1 โฒโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโSimplified transitions:
1 0 1 (A) โโโบ (A) (A) โโโบ (B) โโโบ (C) (B) โโโบ (B) (C) โโโบ (B) (C) โโ1โโโบ (A)Summary
- 3 DFA states are sufficient: A, B, C
- C = {q0, q2} is the only final state
- The DFA correctly accepts all strings over {0,1} that end with 01
- Q10.5 marksAcceptance of strings by PDAHideAnswer
Construct a PDA accepting language over {0, 1} representing strings with equal no of 0s and 1s. Show by sequence of IDs that 0101 is accepted by this PDA. [5]
- Q11.5 marksTime and Space complexity of A Turing MachHideAnswer
Define complexity of a Turing machine. Explain about big Oh, big Omega and big Theta notation used for complexity measurement. [5]
- Q12.5 marksIntractabilityHideAnswer
What do you mean by tractable and Intractable problems? Explain with reference to TM. [5]