CSC262 · TU past paper
Theory of Computation 2081 question paper
The complete TU 2081 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.
- 110 marksConversion of CFG to PDAHideAnswer
Mention the transition function of PDA. List the two ways that PDA accepts the string. Convert the following CFG to PDA.S→AS∣εS \rightarrow AS \mid \varepsilonS→AS∣εA→Ab∣Bb∣abA \rightarrow Ab \mid Bb \mid abA→Ab∣Bb∣ab[10]
Pushdown Automata (PDA) - Transition Function, Acceptance, and CFG Conversion
1. Transition Function of PDA
A Pushdown Automaton (PDA) is defined as a 7-tuple:
$$PDA = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$$
Where:
- $Q$ = finite set of states
- $\Sigma$ = input alphabet
- $\Gamma$ = stack alphabet
- $\delta$ = transition function
- $q_0$ = initial state
- $Z_0$ = initial stack symbol
- $F$ = set of final/accepting states
Transition Function $\delta$:
$$\delta : Q \times (\Sigma \cup {\varepsilon}) \times \Gamma \rightarrow \mathcal{P}(Q \times \Gamma^*)$$
Interpretation: Given a current state $q \in Q$, a current input symbol $a \in \Sigma$ (or $\varepsilon$), and the top of stack symbol $X \in \Gamma$, the transition function returns a set of pairs $(p, \gamma)$ where:
- $p$ is the new state
- $\gamma \in \Gamma^*$ is the string that replaces $X$ on the stack
Notation: $\delta(q, a, X) = {(p, \gamma), \ldots}$
2. Two Ways PDA Accepts a String
A PDA can accept a string in two ways:
Way 1: Acceptance by Final State
- A string $w$ is accepted if, after reading the entire input $w$, the PDA is in a final (accepting) state $q \in F$.
- The stack content does not matter at the time of acceptance.
- Formally: $(q_0, w, Z_0) \vdash^* (q_f, \varepsilon, \gamma)$ for some $q_f \in F$ and $\gamma \in \Gamma^*$
Way 2: Acceptance by Empty Stack
- A string $w$ is accepted if, after reading the entire input $w$, the stack becomes empty.
- The state does not need to be a final state.
- Formally: $(q_0, w, Z_0) \vdash^* (q, \varepsilon, \varepsilon)$ for any state $q \in Q$
Note: Both methods are equivalent in power; any language accepted by one method can be accepted by the other.
3. Converting the Given CFG to PDA
Given Grammar:
$$S \rightarrow AS \mid \varepsilon$$ $$A \rightarrow Ab \mid Bb \mid ab$$ $$B \rightarrow \text{(not explicitly given, assumed terminal or derived)}$$
Note: Variable $B$ appears in $A \rightarrow Bb$ but no production for $B$ is given. We include it as-is and handle it in the PDA transitions. It is likely a terminal or a typo for a variable; we treat $B$ as a variable with no further productions (or it may be a terminal symbol in some interpretations). We proceed with the given grammar.
Method: CFG to PDA (Acceptance by Empty Stack)
Standard Construction:
For any CFG, we construct a PDA with:
- States: ${q_0, q_1, q_2}$ (typically three states: $q_0$ to push start symbol, $q_1$ as the main loop state, $q_2$ as accepting state)
- Or more commonly, a single-state PDA ${q}$ is used for simplicity.
Rules for conversion:
CFG Rule PDA Transition For each production $A \rightarrow \alpha$ $\delta(q, \varepsilon, A) = {(q, \alpha)}$ (pop $A$, push $\alpha$ reversed) For each terminal $a \in \Sigma$ $\delta(q, a, a) = {(q, \varepsilon)}$ (match and pop)
Step-by-Step PDA Construction
PDA: $M = ({q_0, q_1}, {a, b}, {S, A, B, a, b, Z_0}, \delta, q_0, Z_0, {q_1})$
Initialization transitions:
$$\delta(q_0, \varepsilon, Z_0) = {(q_1, SZ_0)}$$
This pushes the start symbol $S$ onto the stack and moves to the working state $q_1$.
Production Rules $\rightarrow$ PDA Transitions
For variable $S$:
Production PDA Transition $S \rightarrow AS$ $\delta(q_1, \varepsilon, S) \ni (q_1, AS)$ $S \rightarrow \varepsilon$ $\delta(q_1, \varepsilon, S) \ni (q_1, \varepsilon)$ So: $\delta(q_1, \varepsilon, S) = {(q_1, AS),\ (q_1, \varepsilon)}$
For variable $A$:
Production PDA Transition $A \rightarrow Ab$ $\delta(q_1, \varepsilon, A) \ni (q_1, Ab)$ $A \rightarrow Bb$ $\delta(q_1, \varepsilon, A) \ni (q_1, Bb)$ $A \rightarrow ab$ $\delta(q_1, \varepsilon, A) \ni (q_1, ab)$ So: $\delta(q_1, \varepsilon, A) = {(q_1, Ab),\ (q_1, Bb),\ (q_1, ab)}$
For variable $B$: the grammar gives no production for $B$, so there is no transition $\delta(q_1, \varepsilon, B)$. Any derivation that uses $A \to Bb$ can therefore never remove $B$ from the stack and never finishes, so that alternative contributes no strings to the language; in effect only $A \to Ab \mid ab$ matter for what the PDA actually accepts.
Terminal matching transitions (match input symbol against stack top, then pop both):
$$\delta(q_1, a, a) = {(q_1, \varepsilon)}$$ $$\delta(q_1, b, b) = {(q_1, \varepsilon)}$$
Acceptance by empty stack:
$$\delta(q_1, \varepsilon, Z_0) = {(q_1, \varepsilon)}$$
Once $Z_0$ itself is popped with no more input to read, the stack is empty and the string is accepted.
Complete PDA
$$M = ({q_0, q_1}, {a, b}, {S, A, B, a, b, Z_0}, \delta, q_0, Z_0, {q_1})$$
with transition function
$$\delta(q_0, \varepsilon, Z_0) = {(q_1, SZ_0)}$$ $$\delta(q_1, \varepsilon, S) = {(q_1, AS),\ (q_1, \varepsilon)}$$ $$\delta(q_1, \varepsilon, A) = {(q_1, Ab),\ (q_1, ab)}$$ $$\delta(q_1, a, a) = {(q_1, \varepsilon)}$$ $$\delta(q_1, b, b) = {(q_1, \varepsilon)}$$ $$\delta(q_1, \varepsilon, Z_0) = {(q_1, \varepsilon)}$$
($B$ is kept in the stack alphabet only because it appears in the given grammar; since it has no production, it never actually gets pushed by any transition that leads to acceptance.)
Sample Acceptance Trace for $w = ab$
$$(q_0,\ ab,\ Z_0) \vdash (q_1,\ ab,\ SZ_0) \vdash (q_1,\ ab,\ ASZ_0) \vdash (q_1,\ ab,\ abSZ_0)$$ $$\vdash (q_1,\ b,\ bSZ_0) \vdash (q_1,\ \varepsilon,\ SZ_0) \vdash (q_1,\ \varepsilon,\ Z_0) \vdash (q_1,\ \varepsilon,\ \varepsilon)$$
The input is fully consumed and the stack is empty, so $w = ab$ is accepted, both by the empty-stack criterion and by the final-state criterion (since $q_1 \in F$). This completes the construction of a PDA equivalent to the given CFG.
- 210 marksNumericalMinimization of Finite State MachinesHideAnswer
List any two regular operators. Minimize the following finite state machine using Table Filling algorithm.[10]
Regular Operators and DFA Minimization Using Table Filling Algorithm
Part 1: Two Regular Operators
Regular operators are the operations used to construct regular expressions from smaller ones. Any two of the following are acceptable:
-
Union (
|or+): If $R$ and $S$ are regular expressions, then $R + S$ denotes the set of strings belonging to either $R$ or $S$.- Example: $(a \mid b)$ denotes ${a, b}$
-
Concatenation (
.): If $R$ and $S$ are regular expressions, then $RS$ denotes strings formed by a string of $R$ followed by a string of $S$.- Example: $ab$ denotes ${ab}$
-
Kleene Star (
*): If $R$ is a regular expression, then $R^{*}$ denotes zero or more concatenations of $R$.- Example: $a^{*}$ denotes ${\varepsilon, a, aa, aaa, \ldots}$
Part 2: DFA Minimization Using Table Filling
Given Data (extracted transition table)
State 0 1 $\to A$ B C $B$ A D $C$ E F $D$ E F $E$ E F $*F$ F F - Start state: $A$
- Final state(s): ${F}$
Note: The problem statement references a machine whose diagram/table is not fully reproduced in the prompt. The solution uses the transition table extracted above. If the intended machine differs, the extracted table above is what this solution assumes.
Step 1: Initialize the triangular table
Mark every pair where exactly one state is final. Final = ${F}$.
Marked pairs (one is $F$): $(A,F), (B,F), (C,F), (D,F), (E,F)$.
B | _ | C | _ | _ | D | _ | _ | _ | E | _ | _ | _ | _ | F | X | X | X | X | X | | A | B | C | D | E |
Step 2: Iterative marking
For each unmarked pair, check transitions on $0$ and $1$; mark if any successor pair is marked.
Pass 1:
- $(A,B)$: $0\to(B,A)$ unmarked, $1\to(C,D)$ unmarked → unmarked
- $(A,C)$: $1\to(C,F)$ marked → MARK
- $(A,D)$: $1\to(C,F)$ marked → MARK
- $(A,E)$: $1\to(C,F)$ marked → MARK
- $(B,C)$: $0\to(A,E)$ marked → MARK
- $(B,D)$: $0\to(A,E)$ marked → MARK
- $(B,E)$: $0\to(A,E)$ marked → MARK
- $(C,D)$: $0\to(E,E)$ same, $1\to(F,F)$ same → unmarked
- $(C,E)$: $0\to(E,E)$ same, $1\to(F,F)$ same → unmarked
- $(D,E)$: $0\to(E,E)$ same, $1\to(F,F)$ same → unmarked
Pass 2 (re-check remaining unmarked pairs):
- $(A,B)$: $0\to(A,B)$ still unmarked, $1\to(C,D)$ still unmarked → remains unmarked
- $(C,D)$: both transitions to same states → remains unmarked
- $(C,E)$: both transitions to same states → remains unmarked
- $(D,E)$: both transitions to same states → remains unmarked
No further changes → algorithm terminates.
Final table:
B | _ | C | X | X | D | X | X | _ | E | X | X | _ | _ | F | X | X | X | X | X | | A | B | C | D | E |
Step 3: Group equivalent (unmarked) states
Unmarked pairs: $(A,B)$, $(C,D)$, $(C,E)$, $(D,E)$.
- $A \equiv B$
- $C \equiv D \equiv E$
- $F$ (alone)
Equivalence classes: $${A, B}, \quad {C, D, E}, \quad {F}$$
Step 4: Minimized DFA
Let:
- $P = {A, B}$ (start state)
- $Q = {C, D, E}$
- $R = {F}$ (final state)
Compute transitions (using any representative):
- $P$: on $0$, $\delta(A,0)=B\in P$; on $1$, $\delta(A,1)=C\in Q$
- $Q$: on $0$, $\delta(C,0)=E\in Q$; on $1$, $\delta(C,1)=F\in R$
- $R$: on $0$, $\delta(F,0)=F\in R$; on $1$, $\delta(F,1)=F\in R$
Minimized transition table:
State 0 1 $\to P$ P Q $Q$ Q R $*R$ R R The minimized DFA has 3 states: ${A,B}$, ${C,D,E}$, ${F}$.
-
- 310 marksNumericalEncoding of Turing MachineHideAnswer
Define Turing machine as enumerators of strings of a language. Encode the Turing machine TM = ({q0, q1, q2}, {a, b}, {a, b, B}, δ, q2, B, F) with input w = ba and δ is defined as follows: δ(q0, b) → (q1, b, R), δ(q1, a) → (q2, a, R), δ(q2, a) → (q1, a, R), δ(q2, b) → (q2, b, L)[10]
Turing Machine as Enumerator and Encoding
Part 1: Turing Machine as an Enumerator
A Turing machine used as an enumerator is a variant of the standard TM equipped with a work tape and a separate output tape (printer). Instead of taking an input and accepting/rejecting it, an enumerator $E$ starts on a blank tape and generates (lists) the strings of a language.
Working principle
- $E$ starts with all tapes blank (no input is provided).
- It computes, occasionally printing a string on the output tape followed by a separator symbol #.
- The set of all strings printed constitutes the language enumerated by $E$:
$$L(E) = {, w \mid E \text{ eventually prints } w \text{ on the output tape} ,}$$
- Strings may be printed in any order and may repeat.
Key theorem
A language $L$ is recursively enumerable (Turing recognizable) if and only if some enumerator $E$ enumerates it. Hence enumerators and recognizers define the same class of languages.
Part 2: Encoding the Given Turing Machine
Given data (extracted)
- States: $Q = {q_0, q_1, q_2}$
- Input alphabet: $\Sigma = {a, b}$
- Tape alphabet: $\Gamma = {a, b, B}$
- Start state: $q_2$
- Blank: $B$
- Final states: $F$ (not explicitly listed in question)
- Input: $w = ba$
- Transitions:
- $\delta(q_0, b) \to (q_1, b, R)$
- $\delta(q_1, a) \to (q_2, a, R)$
- $\delta(q_2, a) \to (q_1, a, R)$
- $\delta(q_2, b) \to (q_2, b, L)$
Note: the set $F$ of final states is not given, so it cannot be encoded. The encoding below covers states, symbols and transitions, which is what the data supports.
Step 1: Encode states (unary in 1's)
State Code $q_0$ $1$ $q_1$ $11$ $q_2$ $111$ Step 2: Encode tape symbols
Symbol Code $a$ $1$ $b$ $11$ $B$ $111$ Step 3: Encode directions
Direction Code $L$ $1$ $R$ $11$ Step 4: Encoding scheme
Each transition $\delta(q, s) \to (q', s', D)$ is encoded (fields separated by single $0$) as:
$$\text{code}(q),0,\text{code}(s),0,\text{code}(q'),0,\text{code}(s'),0,\text{code}(D)$$
T1: $\delta(q_0, b) \to (q_1, b, R)$ $$1,0,11,0,11,0,11,0,11$$
T2: $\delta(q_1, a) \to (q_2, a, R)$ $$11,0,1,0,111,0,1,0,11$$
T3: $\delta(q_2, a) \to (q_1, a, R)$ $$111,0,1,0,11,0,1,0,11$$
T4: $\delta(q_2, b) \to (q_2, b, L)$ $$111,0,11,0,111,0,11,0,1$$
Step 5: Full encoding (transitions separated by $00$)
$$\boxed{1,0,11,0,11,0,11,0,11 ; 00 ; 11,0,1,0,111,0,1,0,11 ; 00 ; 111,0,1,0,11,0,1,0,11 ; 00 ; 111,0,11,0,111,0,11,0,1}$$
Step 6: Trace on input $w = ba$ (start state $q_2$)
Tape: $B,b,a,B$, head on first symbol $b$, state $q_2$.
- Config 1: State $q_2$, read $b$. Apply $\delta(q_2,b)\to(q_2,b,L)$: write $b$, move Left. Head now on the blank $B$ to the left of $b$.
- Config 2: State $q_2$, read $B$. There is no transition for $(q_2, B)$, so the machine halts here.
Since $F$ is not specified, whether this halting configuration is accepting cannot be determined. With the given transitions, the computation halts after one move on the left blank, having never moved right into the $a$. Thus for start state $q_2$ the input $ba$ is not processed to completion in an accepting sense.
(Remark: if the intended start state were $q_0$, the trace would be $q_0 b a \Rightarrow q_1 a \Rightarrow q_2$ (blank) and halt for lack of a $(q_2,B)$ rule. The question explicitly gives start state $q_2$, so the trace above is the correct one for the stated data.)
Final result
- Enumerator: TM with output tape listing all strings of $L$, equivalent to recursive enumerability.
- Encoded string of the machine is the boxed binary string in Step 5.
- 45 marksPositive Closure of AlphabetHideAnswer
Does machine always refer to hardware? Justify. Define positive closure and Kleene closure. [5]
--- No, a machine does not always refer to hardware. In the context of Theory of Computation (TOC), the term "machine" refers to an abstract model rather than a physical hardware device. Abstract Model: An abstract model of a computer sy...
- 55 marksUndecidable ProblemsHideAnswer
What is undecidable problem? Discuss about Post Correspondence Problem. [5]
--- A problem is undecidable if there is no Turing machine which will always halt in a finite amount of time to give an answer as 'yes' or 'no'. An undecidable problem has no algorithm to determine the answer for a given input. More form...
- 65 marksNumericalLeftmost and RightmostHideAnswer
Define the language of a grammar. For the grammar , show the leftmost derivation for the string 00100 with its parse tree. S→0S0∣1∣εS \rightarrow 0S0 \mid 1 \mid \varepsilonS→0S0∣1∣ε[5]
Language of a Grammar and Leftmost Derivation of 00100
Step 1 - Given Data
- Grammar $G$ with productions: $$S \rightarrow 0S0 \mid 1 \mid \varepsilon$$
- Start symbol: $S$
- Terminals: ${0, 1}$
- Non-terminal: ${S}$
- Target string: $00100$
All data is present and readable.
Step 2 - Solution
Definition: Language of a Grammar
For a grammar $G = (V, T, P, S)$ where $V$ is the set of variables (non-terminals), $T$ the set of terminals, $P$ the set of productions, and $S$ the start symbol, the language of the grammar, written $L(G)$, is the set of all terminal strings derivable from $S$:
$$L(G) = {, w \in T^* \mid S \Rightarrow^* w ,}$$
where $\Rightarrow^*$ denotes derivation in zero or more steps. Only strings consisting entirely of terminals belong to $L(G)$.
Leftmost Derivation of 00100
In a leftmost derivation, the leftmost non-terminal is expanded at each step. Since there is only one non-terminal $S$, this is straightforward.
$$S \Rightarrow 0S0 \quad (S \rightarrow 0S0)$$ $$\Rightarrow 00S00 \quad (S \rightarrow 0S0)$$ $$\Rightarrow 00100 \quad (S \rightarrow 1)$$
Complete derivation:
$$S \Rightarrow 0S0 \Rightarrow 00S00 \Rightarrow 00100$$
Therefore $00100 \in L(G)$.
Verification of leaf string: outer pair $0\ldots0$, inner pair $0\ldots0$, centre $1$ gives $0,0,1,0,0 = 00100$ ✓
Parse Tree for 00100
S / | \ 0 S 0 / | \ 0 S 0 | 1Reading the leaves left to right: $0,\ 0,\ 1,\ 0,\ 0 = 00100$ ✓
Summary Table
Step Sentential Form Production 1 $S$ start 2 $0S0$ $S \rightarrow 0S0$ 3 $00S00$ $S \rightarrow 0S0$ 4 $00100$ $S \rightarrow 1$ The string $00100$ is derived in 3 steps, confirming $00100 \in L(G)$.
- 75 marksEpsilon Closure of a StateHideAnswer
Define ε\varepsilonε-closure of a state. Differentiate between Moore and Mealy machine. [5]
ε-closure of a State and Difference Between Moore and Mealy Machine
Part 1: ε-closure of a State
Definition:
ε-closure of a state is the set of all states that can be reached from a particular state without reading any input symbol, i.e., by reading only ε (epsilon) transitions.
Formally, for a state
q, the ε-closure(q) includes:- The state
qitself - All states reachable from
qby following one or more ε-transitions
Example:
If state A has ε-transitions to B, and B has an ε-transition to C, then:
ε-closure(A) = {A, B, C}Key Points:
- Every state is always in its own ε-closure.
- ε-closure is used when converting ε-NFA to DFA, where the start state of the DFA is taken as ε-closure of the start state of the ε-NFA.
Part 2: Difference Between Moore Machine and Mealy Machine
Both are finite state machines (FSMs) that produce output, but they differ in how output is generated.
Basis Mealy Machine Moore Machine Output depends on Both present state and present input Only the present state Number of states Generally fewer states Generally more states Number of outputs For n inputs, there are n outputs For n inputs, there are n+1 outputs Output function Function of transitions; changes when input logic on present state changes Function of current state; changes at clock edges when state changes occur Reaction speed Reacts faster to inputs (same number of clock cycles) Reacts slower to inputs (generally one clock cycle later) Final states No final states in Mealy machine Final states are present in Moore machine Output placement Output is placed on transitions Output is placed on states
Summary
- ε-closure captures all states reachable via epsilon moves alone, and is fundamental to converting ε-NFA to DFA.
- Mealy machine produces output based on both state and input (faster, fewer states), while Moore machine produces output based only on the current state (slower, more states).
- The state
- 85 marksEquivalence of regular grammar and finite HideAnswer
Represent the following regular grammar to finite automata. S→aA∣aB∣εS \rightarrow aA \mid aB \mid \varepsilonS→aA∣aB∣εA→aA∣aSA \rightarrow aA \mid aSA→aA∣aSB→bB∣εB \rightarrow bB \mid \varepsilonB→bB∣ε[5]
Production Rules ------ S → aA \ aB \ ε A → aA \ aS B → bB \ ε --- Each non-terminal in the grammar becomes a state in the FA. We also need a dead/final state for terminals. - States: S, A, B, F (where F is the final/accepting state) - S...
- 95 marksNumericalDeterministic Finite AutomataHideAnswer
Design the DFA that accepts binary string ending with '00' and show its extended transition function for the string 111000. [5]
DFA Accepting Binary Strings Ending with '00'
STEP 1 - EXTRACT (Given Data)
- Alphabet: $\Sigma = {0, 1}$
- Language: $L = {w \in \Sigma^* \mid w \text{ ends with } 00}$
- Test string for extended transition function: $111000$
No numeric data missing; the problem is fully solvable.
STEP 2 - SOLVE
Part 1: DFA Design
We track the relevant suffix (last two symbols). Three states suffice:
State Meaning $q_0$ Start; string is empty or does not end in a useful $0$ $q_1$ String currently ends with exactly one $0$ $q_2$ String ends with $00$ (Accepting) Formal 5-tuple: $$M = ({q_0, q_1, q_2},\ {0,1},\ \delta,\ q_0,\ {q_2})$$
Transition Table:
State 0 1 $\to q_0$ $q_1$ $q_0$ $q_1$ $q_2$ $q_0$ $*q_2$ $q_2$ $q_0$ Transition Function:
- $\delta(q_0, 0) = q_1,\quad \delta(q_0, 1) = q_0$
- $\delta(q_1, 0) = q_2,\quad \delta(q_1, 1) = q_0$
- $\delta(q_2, 0) = q_2,\quad \delta(q_2, 1) = q_0$
State Diagram (description):
1 1 (loop) (self on q2 via 1 back to q0) ┌────┐ ↓ │ →( q0 )──0──▶( q1 )──0──▶(( q2 ))──0──▶ (self loop 0) ▲ │ │ └─────1──────┘ │ ▲──────────────1───────────┘- $q_0$: on $1$ self-loop; on $0 \to q_1$
- $q_1$: on $0 \to q_2$; on $1 \to q_0$
- $q_2$ (accepting): on $0$ self-loop; on $1 \to q_0$
Part 2: Extended Transition Function $\delta^*(q_0, 111000)$
Definition: $$\delta^(q, \varepsilon) = q, \qquad \delta^(q, wa) = \delta(\delta^*(q, w), a)$$
Step Expression Computation Result 0 $\delta^*(q_0, \varepsilon)$ base case $q_0$ 1 $\delta^*(q_0, 1)$ $\delta(q_0, 1)$ $q_0$ 2 $\delta^*(q_0, 11)$ $\delta(q_0, 1)$ $q_0$ 3 $\delta^*(q_0, 111)$ $\delta(q_0, 1)$ $q_0$ 4 $\delta^*(q_0, 1110)$ $\delta(q_0, 0)$ $q_1$ 5 $\delta^*(q_0, 11100)$ $\delta(q_1, 0)$ $q_2$ 6 $\delta^*(q_0, 111000)$ $\delta(q_2, 0)$ $q_2$ Result
$$\delta^*(q_0,\ 111000) = q_2$$
Since $q_2$ is the accepting state, the string $111000$ (which ends in $00$) is accepted. The DFA design is verified correct.
- 105 marksChomsky Normal FormHideAnswer
Convert the following grammar to CNF. S→AAB,A→aA∣ε,B→ab∣aS \rightarrow AAB, \quad A \rightarrow aA \mid \varepsilon, \quad B \rightarrow ab \mid aS→AAB,A→aA∣ε,B→ab∣a[5]
$$S \rightarrow AAB, \quad A \rightarrow aA \mid \varepsilon, \quad B \rightarrow ab \mid a$$ --- CNF requires: Every production is either of the form A → BC (two non-terminals) or A → a (single terminal). No null productions (except pos...
- 115 marksNumericalAcceptance of a string by a Turing MachineHideAnswer
Turing Machine Analysis
Turing Machine: Testing String "())))"
STEP 1 - EXTRACT (Given Data)
Input string:
())))=( ) ) ) )(1 open bracket, 4 close brackets)Transition Table:
State ()XYB$q_0$ X, R, $q_1$ - - -, -, $q_0$ (stay) -, -, $q_4$ $q_1$ - X, L, $q_2$ - Y, L, $q_2$ Y, L, $q_2$ $q_2$ - - X, R, $q_0$ Y, R, $q_3$ -, R, $q_4$ $q_3$ -, -, $q_3$ - - -, -, $q_3$ -, R, $q_4$ - Start state: $q_0$
- Accept state: $q_4$
- $B$ = blank
Note on ambiguity: The table is malformed in the LaTeX. The $q_0$ column headings mix up which symbol triggers each action. The intended machine is the classic balanced-parenthesis TM: on $q_0$ reading
(write X and go right to $q_1$; skip over already-marked X's; halt-accept on blank. The result (accept/reject) does not depend on these cosmetic issues, so I trace using the standard interpretation.
STEP 2 - SOLVE
Initial tape (head at position 1, state $q_0$):
( ) ) ) ) ^Trace
Step State Pos Read Action Resulting Tape 1 $q_0$ 1 (X, R, $q_1$ X ) ) ) )2 $q_1$ 2 )X, L, $q_2$ X X ) ) )3 $q_2$ 1 XX, R, $q_0$ X X ) ) )4 $q_0$ 2 X(skip right, stay $q_0$) X X ) ) )5 $q_0$ 3 )No transition defined HALT At step 5, in state $q_0$ the head reads
). The machine needs to find another(to pair with the remaining)symbols, but there are none. State $q_0$ has no rule for reading)(there is no unmarked(left).The machine halts without reaching the accept state $q_4$.
Result: STRING IS REJECTED ✗
Reason: The string
())))has $1$ opening bracket and $4$ closing brackets: it is unbalanced. After the TM matches the single(with one), three unmatched)remain with no(to pair them. The machine crashes in $q_0$, so())))is not accepted.
Transition Diagram
(→X,R )→X,L / Y→Y,L / B→Y,L ──►( q0 )───────────────►( q1 )───────────────►( q2 ) │ ▲ │ │ │ X→X,R (match found, restart) │ │ └──────────────────────────────────────────┘ │ │ Y→Y,R │ Y→Y,R │ ▼ │ B→(no move) ( q3 ) ▼ │ B→R (( q4 )) ◄───────── B→R ────────────────────────┘ ACCEPT- $q_4$ (double circle) is the accept state.
- Acceptance requires reaching $q_4$ on a blank after all brackets are matched.
- For
()))), the machine never reaches $q_4$.
Conclusion
The string
())))is REJECTED because it is unbalanced (1 open vs 4 close); the machine halts in $q_0$ with no applicable transition on). - 125 marksComplexity ClassesHideAnswer
Differentiate between Class P and Class NP problem. Mention the transition function of DFA, NFA, and ε-NFA. [5]
--- Basis Class P Class NP --------- Full Form Polynomial Time Non-deterministic Polynomial Time Definition Set of decision problems solvable by a deterministic Turing machine in polynomial time O(n^k) Set of decision problems solvable b...