CSC262 · 2080 · 10 marks
How does Turing machine accept a string? Design a Turing Machine over the alphabet {0,1,a} that processes the string defined by L = {a01a,a10a,a0101a}. Show both transition diagram and table. Show acceptance of a0101a.
How does Turing machine accept a string? Design a Turing Machine over the alphabet {0,1,a} that processes the string defined by L = {a01a,a10a,a0101a}. Show both transition diagram and table. Show acceptance of a0101a.[10]
Turing Machine for L = {a01a, a10a, a0101a}
Given
- Alphabet (Σ): ${0, 1, a}$
- Language: $L = {a01a,\ a10a,\ a0101a}$ (a finite language of exactly 3 strings)
- Tape symbols (Γ): ${0, 1, a, B}$ where $B$ = blank
- Required: definition of acceptance, TM design, transition diagram, transition table, trace of
a0101a
Solution
1. How a Turing Machine Accepts a String
A Turing Machine is a 7-tuple: $$M = (Q, \Sigma, \Gamma, \delta, q_0, B, F)$$
- $Q$: finite set of states
- $\Sigma$: input alphabet
- $\Gamma$: tape alphabet ($\Sigma \subseteq \Gamma$, includes $B$)
- $\delta: Q \times \Gamma \rightarrow Q \times \Gamma \times {L, R}$: transition function
- $q_0$: initial state
- $B$: blank symbol
- $F \subseteq Q$: set of final (accepting) states
Acceptance process:
- The input string $x$ is written on the tape, surrounded by blanks $B$.
- The head starts at the leftmost symbol of $x$; machine begins in $q_0$.
- At each step the machine reads the current cell, uses $\delta$ to write a symbol, move (L/R), and change state.
- A string is accepted if the machine halts in a final state ($q \in F$).
- It is rejected if it halts in a non-final state or never halts.
$$L(M) = { x \in \Sigma^* \mid q_0 x \vdash^* \alpha, q_f, \beta,\ q_f \in F}$$
2. Design Strategy
Since $L$ is finite (3 exact strings), the TM scans left-to-right, tracking progress through the shared prefix a, then branching. Since we only recognize, we write back the same symbol and move R.
States:
| State | Meaning |
|---|---|
| $q_0$ | expect leading a |
| $q_1$ | after a; expect 0 or 1 |
| $q_2$ | after a0; expect 1 |
| $q_3$ | after a01; expect final a or continue 0 |
| $q_4$ | after a1; expect 0 |
| $q_5$ | after a10; expect final a |
| $q_6$ | after a010; expect 1 |
| $q_7$ | after a0101; expect final a |
| $q_8,q_9,q_{10}$ | after trailing a; verify blank end |
| $q_a$ | accept (final) |
| $q_r$ | reject |
3. Transition Table
$\delta(\text{state},\text{read}) = (\text{write},\text{move},\text{next})$
| State | Read | Write | Move | Next |
|---|---|---|---|---|
| $q_0$ | a | a | R | $q_1$ |
| $q_0$ | 0,1,B | - | - | $q_r$ |
| $q_1$ | 0 | 0 | R | $q_2$ |
| $q_1$ | 1 | 1 | R | $q_4$ |
| $q_1$ | a,B | - | - | $q_r$ |
| $q_2$ | 1 | 1 | R | $q_3$ |
| $q_2$ | 0,a,B | - | - | $q_r$ |
| $q_3$ | a | a | R | $q_8$ |
| $q_3$ | 0 | 0 | R | $q_6$ |
| $q_3$ | 1,B | - | - | $q_r$ |
| $q_4$ | 0 | 0 | R | $q_5$ |
| $q_4$ | 1,a,B | - | - | $q_r$ |
| $q_5$ | a | a | R | $q_9$ |
| $q_5$ | 0,1,B | - | - | $q_r$ |
| $q_6$ | 1 | 1 | R | $q_7$ |
| $q_6$ | 0,a,B | - | - | $q_r$ |
| $q_7$ | a | a | R | $q_{10}$ |
| $q_7$ | 0,1,B | - | - | $q_r$ |
| $q_8$ | B | B | - | $q_a$ |
| $q_8$ | 0,1,a | - | - | $q_r$ |
| $q_9$ | B | B | - | $q_a$ |
| $q_9$ | 0,1,a | - | - | $q_r$ |
| $q_{10}$ | B | B | - | $q_a$ |
| $q_{10}$ | 0,1,a | - | - | $q_r$ |
4. Transition Diagram
a 0 1 a B
->(q0) --------> (q1) ----> (q2) ----> (q3) ----> (q8) ----> ((qa))
| 1 a01a path |
v | 0
(q4) v
| 0 (q6)
v | 1
(q5) v
| a (q7)
v | a
(q9) v
| B (q10)
v | B
((qa)) v
((qa))
(All undefined/unexpected inputs go to $q_r$, reject.)
5. Acceptance of a0101a
Tape: $B\ a\ 0\ 1\ 0\ 1\ a\ B$
| Step | State | Head reads | Action | Next |
|---|---|---|---|---|
| 1 | $q_0$ | a | write a, R | $q_1$ |
| 2 | $q_1$ | 0 | write 0, R | $q_2$ |
| 3 | $q_2$ | 1 | write 1, R | $q_3$ |
| 4 | $q_3$ | 0 | write 0, R | $q_6$ |
| 5 | $q_6$ | 1 | write 1, R | $q_7$ |
| 6 | $q_7$ | a | write a, R | $q_{10}$ |
| 7 | $q_{10}$ | B | write B | $q_a$ |
The machine halts in $q_a$ (final state), so the string a0101a is ACCEPTED. ✓
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.