2081 11

CSC262 ยท 2081 ยท 5 marks

Turing Machine Analysis

Turing Machine Analysis

Theory of ComputationChapter 6: Turing MachinesAcceptance of a string by a Turing MachinesNumerical: Turing machine string trace

Turing Machine: Testing String "())))"

Given

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.


Solution

Initial tape (head at position 1, state $q_0$):

( ) ) ) )
^

Trace

StepStatePosReadActionResulting Tape
1$q_0$1(X, R, $q_1$X ) ) ) )
2$q_1$2)X, L, $q_2$X X ) ) )
3$q_2$1XX, R, $q_0$X X ) ) )
4$q_0$2X(skip right, stay $q_0$)X X ) ) )
5$q_0$3)No transition definedHALT

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 ).

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.