CSC262 · Exam intelligence
Theory of Computation important questions
From 6 past TU papers: which questions keep coming back, how much they carry, and what is most likely to show up next. Every question links to a model answer.
Most likely in the next examStatistical
Ranked by how often a topic is asked, its marks weight, and whether it is due after skipping the 2081 paper. No guarantees; study the whole syllabus.
1asked 4xavg 5 marks · due (skipped 2081) · Regular ExpressionsAnswerHideConstruct regular expression over {1,2,...,9} that represents a. strings of even numbers with length 4 starting with 2 and ending with 8. b. strings starting with odd numbers and ending with even numbers. [5]
Construct regular expression over {1,2,...,9} that represents a. strings of even numbers with length 4 starting with 2 and ending with 8. b. strings starting with odd numbers and ending with even numbers. [5]
- Concatenation (.): places symbols/expressions one after another - Union (+): matches either expression - Kleene Star (): zero or more repetitions - Kleene Plus (+): one or more repetitions --- Constraints: - Length exactly 4 - First sy...
2asked 4xavg 5 marks · due (skipped 2081) · IntractabilityAnswerHideWhat is intractability? Define time and space complexity of turing machine. [5]
What is intractability? Define time and space complexity of turing machine. [5]
Intractability and Time/Space Complexity of Turing Machine
Intractability
Intractability is a concept used to classify problems that cannot be solved in polynomial time but instead require exponential time algorithms.
- Problems that can be solved within reasonable time and space constraints are called tractable problems.
- Problems that cannot be solved in polynomial time but require exponential time algorithms are called intractable (or hard) problems.
An algorithm whose complexity measure increases with input size n no more rapidly than a polynomial in n is said to be polynomially bounded. An algorithm whose complexity grows exponentially is said to be exponentially bounded, and such problems fall under intractability.
Example: Problems like the Travelling Salesman Problem (decision version) are considered intractable as no known polynomial-time algorithm exists for them.
Time and Space Complexity of a Turing Machine
When a Turing Machine (TM) answers a specific instance of a decision problem:
- Time is measured as the number of moves made during computation.
- Space is measured as the number of tape squares used during computation.
The most natural measure of input size is the length of the input string. The worst case is considered, i.e., the maximum time or space required for any input string of that length.
Time Complexity
Let T be a Turing Machine. The time complexity of T is the function T_t defined on the natural numbers as:
For n ∈ N, T_t(n) is the maximum number of moves T can make on any input string of length n.
- If there exists an input string x such that |x| = n and T loops forever on input x, then T_t(n) is undefined.
Space Complexity
The space complexity of T is the function S_t defined as:
S_t(n) is the maximum number of tape squares used by T for any input string of length n.
- If T is a multi-tape TM, the number of tape squares means the maximum of the number of squares used across individual tapes.
- If for some input of length n, T loops forever, then S_t(n) is undefined.
Summary Table
| Measure | Definition |
|---|---|
| Time Complexity T_t(n) | Maximum number of moves on any input of length n |
| Space Complexity S_t(n) | Maximum number of tape squares used on any input of length n |
| Undefined when | T loops forever on some input of length n |
Note: In complexity theory, we are always more interested in the growth rate of these functions rather than their absolute values.
3asked 5xavg 7 marks · Chomsky Normal FormAnswerHideConvert 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]_
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...
4asked 3xavg 8 marks · due (skipped 2081) · Method for reduction of NFA to DFAAnswerHideWhat is NFA? How is it different from DFA? How is NFA to DFA conversion done? Convert the following NFA into DFA.[10]
What is NFA? How is it different from DFA? How is NFA to DFA conversion done? Convert the following NFA into DFA.[10]
NFA to DFA: Definition, Differences, Conversion, and Worked Example
STEP 1 - EXTRACT: Given Data
The question asks for definitions and a conversion. The specific NFA to be converted was not provided in the question text (the diagram or table is missing), so the worked example below uses this standard NFA:
| State | a | b |
|---|---|---|
| →q₀ | {q₀, q₁} | {q₀} |
| q₁ | ∅ | {q₂} |
| *q₂ | ∅ | ∅ |
Start state: $q_0$; Final state: $q_2$; Alphabet $\Sigma = {a, b}$; no ε-transitions.
Since the original NFA is missing, the theory below is given in full and the conversion is worked on this assumed NFA. In the exam, apply the same subset-construction steps to the NFA printed on your paper.
STEP 2 - SOLVE
1. What is an NFA?
A Non-deterministic Finite Automaton (NFA) is a finite automaton where, for a given state and input symbol, there may be zero, one, or more next states, and ε-moves (transitions without consuming input) are permitted.
Formally, $M = (Q, \Sigma, \delta, q_0, F)$ where:
| Symbol | Meaning |
|---|---|
| $Q$ | Finite set of states |
| $\Sigma$ | Input alphabet |
| $\delta$ | $Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| $q_0$ | Start state |
| $F$ | Set of final states |
A string is accepted if at least one computation path ends in a final state.
2. Difference Between NFA and DFA
| Feature | DFA | NFA |
|---|---|---|
| Transitions per (state, symbol) | Exactly one | Zero, one, or more |
| ε-moves | Not allowed | Allowed |
| Transition function | $\delta: Q \times \Sigma \to Q$ | $\delta: Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| Acceptance | Unique path | Any accepting path |
| States needed | Usually more | Usually fewer |
| Ease of design | Harder | Easier |
| Language class | Regular | Regular (same power) |
Every DFA is an NFA; every NFA has an equivalent DFA.
3. NFA to DFA Conversion (Subset Construction)
- Step 1: DFA start state = $\varepsilon\text{-closure}(q_0)$.
- Step 2: For each DFA state $T$ and symbol $a$: compute $\varepsilon\text{-closure}(\text{move}(T,a))$ = a new DFA state.
- Step 3: Repeat until no new states appear.
- Step 4: A DFA state is final if it contains any NFA final state.
- Step 5: Missing transitions lead to a dead state $\emptyset$.
4. Worked Example (using the assumed NFA above)
Start state: $\varepsilon\text{-closure}(q_0) = {q_0} = A$
State $A = {q_0}$:
- On $a$: ${q_0, q_1} = B$
- On $b$: ${q_0} = A$
State $B = {q_0, q_1}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup {q_2} = {q_0, q_2} = C$
State $C = {q_0, q_2}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup \emptyset = {q_0} = A$
No new states. Final DFA Transition Table:
| DFA State | NFA States | On $a$ | On $b$ | Final? |
|---|---|---|---|---|
| →A | ${q_0}$ | B | A | No |
| B | ${q_0, q_1}$ | B | C | No |
| C | ${q_0, q_2}$ | B | A | Yes (contains $q_2$) |
Start state = $A$; Final state = $C$ (since it contains the NFA final state $q_2$). This DFA accepts all strings over ${a,b}$ ending in "$ab$".
Note on Missing Data
The actual NFA diagram or table intended by the exam was not included in the question, so the worked conversion above uses the assumed NFA. The theory portions (definition, differences, algorithm) are complete and correct regardless.
Check: the transition computations are consistent ($A\to B/A$, $B\to B/C$, $C\to B/A$), and the final state is $C$, the only subset containing $q_2$.
5asked 3xavg 7 marks · due (skipped 2081) · Pumping LemmaAnswerHideUsing pumping lemma, prove that the language is not regular. $L = {a^i b^j c^k \mid j=i+k}$ [5]
Using pumping lemma, prove that the language is not regular. $L = {a^i b^j c^k \mid j=i+k}$ [5]
- Language: $L = {a^i b^j c^k \mid j = i + k,\ i,k \ge 0}$ - Alphabet: ${a, b, c}$ - Method required: Pumping Lemma for regular languages. --- Suppose $L$ is regular. Then by the Pumping Lemma, there exists a pumping length $p \ge 1$...
Most repeated questions
Topics asked at least twice, most-asked first.
asked 5xavg 7 marks · 2081, 2080, 2079, 2078, 2076AnswerHideConvert 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]_
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...
asked 4xavg 5 marks · 2080.1, 2080, 2078, 2076AnswerHideConstruct regular expression over {1,2,...,9} that represents a. strings of even numbers with length 4 starting with 2 and ending with 8. b. strings starting with odd numbers and ending with even numbers. [5]
Construct regular expression over {1,2,...,9} that represents a. strings of even numbers with length 4 starting with 2 and ending with 8. b. strings starting with odd numbers and ending with even numbers. [5]
- Concatenation (.): places symbols/expressions one after another - Union (+): matches either expression - Kleene Star (): zero or more repetitions - Kleene Plus (+): one or more repetitions --- Constraints: - Length exactly 4 - First sy...
asked 4xavg 5 marks · 2080.1, 2079, 2078, 2076AnswerHideWhat is intractability? Define time and space complexity of turing machine. [5]
What is intractability? Define time and space complexity of turing machine. [5]
Intractability and Time/Space Complexity of Turing Machine
Intractability
Intractability is a concept used to classify problems that cannot be solved in polynomial time but instead require exponential time algorithms.
- Problems that can be solved within reasonable time and space constraints are called tractable problems.
- Problems that cannot be solved in polynomial time but require exponential time algorithms are called intractable (or hard) problems.
An algorithm whose complexity measure increases with input size n no more rapidly than a polynomial in n is said to be polynomially bounded. An algorithm whose complexity grows exponentially is said to be exponentially bounded, and such problems fall under intractability.
Example: Problems like the Travelling Salesman Problem (decision version) are considered intractable as no known polynomial-time algorithm exists for them.
Time and Space Complexity of a Turing Machine
When a Turing Machine (TM) answers a specific instance of a decision problem:
- Time is measured as the number of moves made during computation.
- Space is measured as the number of tape squares used during computation.
The most natural measure of input size is the length of the input string. The worst case is considered, i.e., the maximum time or space required for any input string of that length.
Time Complexity
Let T be a Turing Machine. The time complexity of T is the function T_t defined on the natural numbers as:
For n ∈ N, T_t(n) is the maximum number of moves T can make on any input string of length n.
- If there exists an input string x such that |x| = n and T loops forever on input x, then T_t(n) is undefined.
Space Complexity
The space complexity of T is the function S_t defined as:
S_t(n) is the maximum number of tape squares used by T for any input string of length n.
- If T is a multi-tape TM, the number of tape squares means the maximum of the number of squares used across individual tapes.
- If for some input of length n, T loops forever, then S_t(n) is undefined.
Summary Table
| Measure | Definition |
|---|---|
| Time Complexity T_t(n) | Maximum number of moves on any input of length n |
| Space Complexity S_t(n) | Maximum number of tape squares used on any input of length n |
| Undefined when | T loops forever on some input of length n |
Note: In complexity theory, we are always more interested in the growth rate of these functions rather than their absolute values.
asked 3xavg 8 marks · 2080, 2078, 2076AnswerHideWhat is NFA? How is it different from DFA? How is NFA to DFA conversion done? Convert the following NFA into DFA.[10]
What is NFA? How is it different from DFA? How is NFA to DFA conversion done? Convert the following NFA into DFA.[10]
NFA to DFA: Definition, Differences, Conversion, and Worked Example
STEP 1 - EXTRACT: Given Data
The question asks for definitions and a conversion. The specific NFA to be converted was not provided in the question text (the diagram or table is missing), so the worked example below uses this standard NFA:
| State | a | b |
|---|---|---|
| →q₀ | {q₀, q₁} | {q₀} |
| q₁ | ∅ | {q₂} |
| *q₂ | ∅ | ∅ |
Start state: $q_0$; Final state: $q_2$; Alphabet $\Sigma = {a, b}$; no ε-transitions.
Since the original NFA is missing, the theory below is given in full and the conversion is worked on this assumed NFA. In the exam, apply the same subset-construction steps to the NFA printed on your paper.
STEP 2 - SOLVE
1. What is an NFA?
A Non-deterministic Finite Automaton (NFA) is a finite automaton where, for a given state and input symbol, there may be zero, one, or more next states, and ε-moves (transitions without consuming input) are permitted.
Formally, $M = (Q, \Sigma, \delta, q_0, F)$ where:
| Symbol | Meaning |
|---|---|
| $Q$ | Finite set of states |
| $\Sigma$ | Input alphabet |
| $\delta$ | $Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| $q_0$ | Start state |
| $F$ | Set of final states |
A string is accepted if at least one computation path ends in a final state.
2. Difference Between NFA and DFA
| Feature | DFA | NFA |
|---|---|---|
| Transitions per (state, symbol) | Exactly one | Zero, one, or more |
| ε-moves | Not allowed | Allowed |
| Transition function | $\delta: Q \times \Sigma \to Q$ | $\delta: Q \times (\Sigma \cup {\varepsilon}) \to 2^{Q}$ |
| Acceptance | Unique path | Any accepting path |
| States needed | Usually more | Usually fewer |
| Ease of design | Harder | Easier |
| Language class | Regular | Regular (same power) |
Every DFA is an NFA; every NFA has an equivalent DFA.
3. NFA to DFA Conversion (Subset Construction)
- Step 1: DFA start state = $\varepsilon\text{-closure}(q_0)$.
- Step 2: For each DFA state $T$ and symbol $a$: compute $\varepsilon\text{-closure}(\text{move}(T,a))$ = a new DFA state.
- Step 3: Repeat until no new states appear.
- Step 4: A DFA state is final if it contains any NFA final state.
- Step 5: Missing transitions lead to a dead state $\emptyset$.
4. Worked Example (using the assumed NFA above)
Start state: $\varepsilon\text{-closure}(q_0) = {q_0} = A$
State $A = {q_0}$:
- On $a$: ${q_0, q_1} = B$
- On $b$: ${q_0} = A$
State $B = {q_0, q_1}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup {q_2} = {q_0, q_2} = C$
State $C = {q_0, q_2}$:
- On $a$: ${q_0, q_1} \cup \emptyset = {q_0, q_1} = B$
- On $b$: ${q_0} \cup \emptyset = {q_0} = A$
No new states. Final DFA Transition Table:
| DFA State | NFA States | On $a$ | On $b$ | Final? |
|---|---|---|---|---|
| →A | ${q_0}$ | B | A | No |
| B | ${q_0, q_1}$ | B | C | No |
| C | ${q_0, q_2}$ | B | A | Yes (contains $q_2$) |
Start state = $A$; Final state = $C$ (since it contains the NFA final state $q_2$). This DFA accepts all strings over ${a,b}$ ending in "$ab$".
Note on Missing Data
The actual NFA diagram or table intended by the exam was not included in the question, so the worked conversion above uses the assumed NFA. The theory portions (definition, differences, algorithm) are complete and correct regardless.
Check: the transition computations are consistent ($A\to B/A$, $B\to B/C$, $C\to B/A$), and the final state is $C$, the only subset containing $q_2$.
asked 3xavg 7 marks · 2080, 2079, 2076AnswerHideUsing pumping lemma, prove that the language is not regular. $L = {a^i b^j c^k \mid j=i+k}$ [5]
Using pumping lemma, prove that the language is not regular. $L = {a^i b^j c^k \mid j=i+k}$ [5]
- Language: $L = {a^i b^j c^k \mid j = i + k,\ i,k \ge 0}$ - Alphabet: ${a, b, c}$ - Method required: Pumping Lemma for regular languages. --- Suppose $L$ is regular. Then by the Pumping Lemma, there exists a pumping length $p \ge 1$...
asked 3xavg 7 marks · 2079, 2078, 2076AnswerHideDefine Turing machine and its roles. [5]
Define Turing machine and its roles. [5]
A Turing Machine (TM) is a theoretical computational model that consists of an infinite tape divided into cells, a read/write head, and a finite control unit. It is formally defined as a 7-tuple: $$TM = (Q, \Sigma, \Gamma, \delta, q0, B,...
asked 3xavg 5 marks · 2080.1, 2080, 2078AnswerHideConstruct a PDA that accepts string over Σ={a,b}\Sigma = { a, b }Σ={a,b} that contains equal number of a's followed by equal number of b's. Show acceptance of aabb and aab. [5]
Construct a PDA that accepts string over Σ={a,b}\Sigma = { a, b }Σ={a,b} that contains equal number of a's followed by equal number of b's. Show acceptance of aabb and aab. [5]
PDA for $L = {a^n b^n \mid n \geq 1}$
STEP 1 - Given Data
- Alphabet: $\Sigma = {a, b}$
- Language: strings with equal number of $a$'s followed by equal number of $b$'s
- Strings to test: $aabb$ and $aab$
$$L = {a^n b^n \mid n \geq 1} = {ab, aabb, aaabbb, \ldots}$$
STEP 2 - Construction and Solution
Strategy
- Push each $a$ onto the stack.
- On the first $b$, start popping $a$'s.
- On subsequent $b$'s, keep popping $a$'s.
- Accept when only $Z_0$ remains after all input consumed (empty count).
Formal Definition
$$M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)$$
- $Q = {q_0, q_1, q_2}$
- $\Sigma = {a, b}$
- $\Gamma = {a, Z_0}$
- Start state $q_0$, initial stack symbol $Z_0$
- $F = {q_2}$
Transition Table
| State | Input | Stack Top | Push | Next State |
|---|---|---|---|---|
| $q_0$ | $a$ | $Z_0$ | $aZ_0$ | $q_0$ |
| $q_0$ | $a$ | $a$ | $aa$ | $q_0$ |
| $q_0$ | $b$ | $a$ | $\varepsilon$ | $q_1$ |
| $q_1$ | $b$ | $a$ | $\varepsilon$ | $q_1$ |
| $q_1$ | $\varepsilon$ | $Z_0$ | $Z_0$ | $q_2$ |
Notation: input, top / pushed-string.
Acceptance of $aabb$
| Step | State | Remaining Input | Stack (top→bottom) | Transition |
|---|---|---|---|---|
| 1 | $q_0$ | $aabb$ | $Z_0$ | $a,Z_0/aZ_0$ |
| 2 | $q_0$ | $abb$ | $aZ_0$ | $a,a/aa$ |
| 3 | $q_0$ | $bb$ | $aaZ_0$ | $b,a/\varepsilon$ |
| 4 | $q_1$ | $b$ | $aZ_0$ | $b,a/\varepsilon$ |
| 5 | $q_1$ | $\varepsilon$ | $Z_0$ | $\varepsilon,Z_0/Z_0$ |
| 6 | $q_2$ | $\varepsilon$ | $Z_0$ | halt in final state |
Input consumed, final state $q_2$ reached. $aabb$ is ACCEPTED.
Acceptance of $aab$
| Step | State | Remaining Input | Stack (top→bottom) | Transition |
|---|---|---|---|---|
| 1 | $q_0$ | $aab$ | $Z_0$ | $a,Z_0/aZ_0$ |
| 2 | $q_0$ | $ab$ | $aZ_0$ | $a,a/aa$ |
| 3 | $q_0$ | $b$ | $aaZ_0$ | $b,a/\varepsilon$ |
| 4 | $q_1$ | $\varepsilon$ | $aZ_0$ | stack top is $a$, but no $\varepsilon$-move on $a$ in $q_1$ |
Input exhausted while stack still holds an unmatched $a$ (top $\neq Z_0$), so $q_2$ cannot be reached. $aab$ is REJECTED (2 a's, 1 b: unequal).
Summary
| String | a's | b's | Result |
|---|---|---|---|
| $aabb$ | 2 | 2 | Accepted ($n=2$) |
| $aab$ | 2 | 1 | Rejected |
The PDA correctly accepts $a^n b^n$ and rejects strings with unequal counts.
Keep the transition table precise: write the $q_2$ transitions so that the empty-stack case is distinguished rather than folded into a,ε/a, and avoid an extra initialization state. The verdicts (accept $aabb$, reject $aab$) are unaffected.
asked 3xavg 5 marks · 2081, 2080, 2076AnswerHideDesign the DFA that accepts binary string ending with '00' and show its extended transition function for the string 111000. [5]
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.
asked 2xavg 8 marks · 2080.1, 2080AnswerHideHow Turing Machine is used as a computing function? Construct a TM for simulating a function f(x) = 2x for x = {1}. Iterate the TM for input 11 and generate the output 1111.[10]
How Turing Machine is used as a computing function? Construct a TM for simulating a function f(x) = 2x for x = {1}. Iterate the TM for input 11 and generate the output 1111.[10]
- Function to compute: $f(x) = 2x$ - Input alphabet symbol: $x \in {1}$ (unary representation) - Test input: 11 (i.e., $x = 2$) - Expected output: 1111 (i.e., $f(2) = 4$) - Representation: value $n$ = string of $n$ ones on the tape All...
asked 2xavg 8 marks · 2080.1, 2080AnswerHideDefine CFG. Construct a CFG that generates the language of all palindromes over {a,b} that do not contain the substring aa. Show the leftmost derivation and construct the equivalent parse tree for string babbbab.[10]
Define CFG. Construct a CFG that generates the language of all palindromes over {a,b} that do not contain the substring aa. Show the leftmost derivation and construct the equivalent parse tree for string babbbab.[10]
Context-Free Grammar - Definition and Construction
STEP 1 - EXTRACT: Given Data
- Alphabet: $\Sigma = {a, b}$
- Language: all palindromes over ${a,b}$ that do NOT contain substring $aa$
- Target string for derivation and parse tree: babbbab
- Marks: 10
All required data is present.
STEP 2 - SOLVE
1. Definition of CFG
A Context-Free Grammar is a 4-tuple $G = (V, T, P, S)$ where:
- $V$ = finite set of variables (non-terminals)
- $T$ = finite set of terminals, with $V \cap T = \varnothing$
- $P$ = finite set of productions of the form $A \to \alpha$, where $A \in V$ and $\alpha \in (V \cup T)^*$
- $S \in V$ = the start symbol
Every production has exactly one non-terminal on the left, hence "context-free". CFGs generate the class of Context-Free Languages.
2. Language Analysis
$$L = {, w \in {a,b}^* \mid w = w^R \text{ and } aa \text{ is not a substring of } w ,}$$
Constraints:
- Palindrome: $w = w^R$
- No $aa$: two $a$'s must never be adjacent
Because $w$ is a palindrome, when we place an $a$ at both ends the inner string must not begin or end with $a$ (otherwise $aa$ would form at the junction). So an $a$-wrapped layer must contain an inner block that begins and ends with $b$ (or is a single $b$).
Sample valid strings: $\varepsilon,\ a,\ b,\ aba,\ bab,\ bbb,\ babab,\ babbbab$. Invalid: $aa,\ baab,\ aabaa$.
3. Constructing the CFG
Use two variables:
| Variable | Meaning |
|---|---|
| $S$ | any palindrome without $aa$ |
| $B$ | a palindrome without $aa$ that starts and ends with $b$ |
Productions $P$:
$$ \begin{aligned} S &\to \varepsilon \mid a \mid b \ S &\to bSb \ S &\to aBa \ B &\to b \mid bSb \end{aligned} $$
Grammar: $G = ({S,B},\ {a,b},\ P,\ S)$.
Why $aa$ never occurs:
- $S \to aBa$: the inner $B$ must start and end with $b$, giving $a,b\ldots b,a$, so no adjacent $a$'s at the junction.
- $S \to bSb$ and $B \to bSb$: wrap with $b$'s, always safe.
- No production ever places two $a$'s next to each other.
The palindrome property holds because each recursive rule adds the same terminal symmetrically on both ends.
4. Leftmost Derivation for babbbab
Structural decomposition:
$$ \underbrace{b}{\text{outer}}\ \underbrace{a}{}\ \underbrace{b\ b\ b}{\text{middle}}\ \underbrace{a}{}\ \underbrace{b}_{\text{outer}} $$
- Outer $b\ldots b$ → $S \to bSb$
- Inner $abbba$: $a\ldots a$ → $S \to aBa$
- Inner $bbb$: $b\ldots b$ → $B \to bSb$
- Center $b$ → $S \to b$
Leftmost derivation (always expand leftmost non-terminal):
| Step | Sentential form | Production |
|---|---|---|
| 1 | $S$ | start |
| 2 | $bSb$ | $S \to bSb$ |
| 3 | $baBab$ | $S \to aBa$ |
| 4 | $babSbab$ | $B \to bSb$ |
| 5 | $babbbab$ | $S \to b$ |
$$S \Rightarrow bSb \Rightarrow baBab \Rightarrow babSbab \Rightarrow babbbab$$
Result: $babbbab$ ✓ (matches target)
5. Parse Tree for babbbab
S
/ | \
b S b
/ | \
a B a
/ | \
b S b
|
b
Reading the leaves left to right: $b,a,b,b,b,a,b = babbbab$ ✓
The tree is symmetric about its center, confirming both the palindrome property and the absence of substring $aa$ (each $a$ is bounded by $b$'s).
Final Answer: The CFG $G = ({S,B},{a,b},P,S)$ with productions $S \to \varepsilon \mid a \mid b \mid bSb \mid aBa,\ B \to b \mid bSb$ generates the required language. The leftmost derivation for $babbbab$ uses the sequence $S \Rightarrow bSb \Rightarrow baBab \Rightarrow babSbab \Rightarrow babbbab$, with the parse tree shown above.
asked 2xavg 8 marks · 2079, 2076AnswerHideConvert the following regular expression into equivalent Finite Automata. a.(0+1)∗10(1+0)a. (0+1)10(1+0)a.(0+1)∗10(1+0)b.1∗0(0+1)∗1b. 10(0+1)*1b.1∗0(0+1)∗1_[5]_
Convert the following regular expression into equivalent Finite Automata. a.(0+1)∗10(1+0)a. (0+1)10(1+0)a.(0+1)∗10(1+0)b.1∗0(0+1)∗1b. 10(0+1)*1b.1∗0(0+1)∗1_[5]_
Two regular expressions to convert to Finite Automata: - (a) $(0+1)^,1,0,(1+0)$ - (b) $1^,0,(0+1)^,1$ Alphabet: $\Sigma = {0, 1}$ for both. --- Break into parts: 1. $(0+1)^$ = any string of 0s and 1s (including empty) 2. $10$ = l...
asked 2xavg 5 marks · 2080.1, 2080AnswerHideHow is conversion of PDA to CFG done? Illustrate with example. [5]
How is conversion of PDA to CFG done? Illustrate with example. [5]
Given a Pushdown Automaton (PDA) P = (Q, Σ, Γ, δ, q₀, Z₀, F), we can construct an equivalent Context-Free Grammar (CFG) G = (V, T, R, S). --- For each pair of states (p, q) in the PDA, we create a non-terminal symbol A[p,q], which repres...
asked 2xavg 5 marks · 2078, 2076AnswerHideWhat do you mean by computational Complexity? Explain about the time and space complexity of a Turing machine. [5]
What do you mean by computational Complexity? Explain about the time and space complexity of a Turing machine. [5]
The complexity of computational problems is discussed by choosing a specific abstract machine as a model of computation and considering how much resource a machine of that type requires for the solution of a given problem. - A Complexity...
asked 2xavg 10 marks · 2081, 2078AnswerHideList any two regular operators. Minimize the following finite state machine using Table Filling algorithm.[10]
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}$.
asked 2xavg 10 marks · 2081, 2078AnswerHideDefine 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]
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.
Study every one of these with model answers, flashcards, and MCQs.
Open CSC262 study modes