turing machine
DESCRIPTION
This presentation provide an example to explain the idea of Turing Machine with two ways infinite tape (BALANCED PARENTHESES EXAMPLE).TRANSCRIPT
Finite Control
qi
R\D Head
Input Tape
ε a0 a1 … an ε ε ε … …
Create a Turing Machine that takes as input a string consists of different parentheses ( ), [ ] or { } and ensure
if that string is balanced – open parentheses are balanced with closed parentheses – and correct – the smaller one does not include the bigger –.
Examples:
{[[(()())]()]} Accepted (balanced and correct)
[(())(){()()}] Rejected (balanced but wrong)
{[()}}{[(())]} Rejected (correct but unbalanced)
{()([])}[(()]] Rejected (unbalanced and wrong)
Q = { Start , Find1 , Find2 , Find3 , End , Rejected , Accepted }
States Description :
Start : initial state, that begin to find first symbol ), ] or } then check it with X, Y or Z respectively.
Find1 : moving left to find matched symbol (, then check it with X and return to Start state.
Find2 : moving left to find matched symbol [, then check it with Y and return to Start state.
Find3 : moving left to find matched symbol {, then check it with Z and return to Start state.
End : the string is finished, thus moving left to ensure that all symbols are checked.
Rejected : there are unchecked (unbalanced) symbols or the string is wrong, therefore string is rejected.
Accepted : all symbols are checked (balanced) and the string is correct, therefore string is accepted.
Γ = { ( , ) , [ , ] , { , } , X , Y , Z , ε } (Tape Alphabet)
Σ = { ( , ) , [ , ] , { , } } (Input Alphabet)
F = { Accepted } (Finite States)
Initial State: Start
Blank Symbol: ε
ε Z Y X } { ] [ ) ( δ(q , γ)
End
ε , L
Start Z , R
Start Y , R
Start X , R
Find3 Z , L
Start { , R
Find2 Y , L
Start [ , R
Find1 X , L
Start ( , R
Start → ) , ] , }
Rejected
ε , R (unbalanced)
Rejected Z , L
(wrong)
Rejected Y , L
(wrong)
Find1 X , L
- Rejected
{ , L (wrong)
- Rejected
[ , L (wrong)
- Start X , R
Find1 (
Rejected
ε , R (unbalanced)
Rejected Z , L
(wrong)
Find2 Y , L
Find2 X , L
- Rejected
{ , L (wrong)
- Start Y , R
- Rejected
( , L (unbalanced)
Find2 [
Rejected
ε , R (unbalanced)
Find3 Z , L
Find3 Y , L
Find3 X , L
- Start Z , R
- Rejected
[ , L (unbalanced)
- Rejected
( , L (unbalanced)
Find3 {
Accepted
ε , R (correct)
(balanced)
End Z , L
End Y , L
End X , L
- Rejected
{ , L (unbalanced)
- Rejected
[ , L (unbalanced)
- Rejected
( , L (unbalanced)
End
ε
- - - - - - - - - - Rejected
Stop
- - - - - - - - - - Accepted
Stop
X / Y , D X : Scanned Symbol Y : Written Symbol D : Move Direction
Find2
Find1
Accept Reject
Find3
End Start
X/X,L
]/Y,L
[/Y,R
ε/ε,R ε/ε,L (/(,L {/{,L
[/[,L
Z/Z,L ε/ε,L
Y/Y,L
Y/Y,L
{ [ ε ε … … ( ) ] }
A. The string: {[()]}
Start
{ [ ε ε … … ( ) ] }
A. The string: {[()]}
Start
{ [ ε ε … … ( ) ] }
A. The string: {[()]}
Start
{ [ ε ε … … ( ) ] }
A. The string: {[()]}
Start
{ [ ε ε … … ( X ] }
A. The string: {[()]}
Find1
{ [ ε ε … … X X ] }
A. The string: {[()]}
Start
{ [ ε ε … … X X ] }
A. The string: {[()]}
Start
{ [ ε ε … … X X Y }
A. The string: {[()]}
Find2
{ [ ε ε … … X X Y }
A. The string: {[()]}
Find2
{ [ ε ε … … X X Y }
A. The string: {[()]}
Find2
{ Y ε ε … … X X Y }
A. The string: {[()]}
Start
{ Y ε ε … … X X Y }
A. The string: {[()]}
Start
{ Y ε ε … … X X Y }
A. The string: {[()]}
Start
{ Y ε ε … … X X Y }
A. The string: {[()]}
Start
{ Y ε ε … … X X Y Z
A. The string: {[()]}
Find3
{ Y ε ε … … X X Y Z
A. The string: {[()]}
Find3
{ Y ε ε … … X X Y Z
A. The string: {[()]}
Find3
{ Y ε ε … … X X Y Z
A. The string: {[()]}
Find3
{ Y ε ε … … X X Y Z
A. The string: {[()]}
Find3
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Start
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
End
Z Y ε ε … … X X Y Z
A. The string: {[()]}
Accepted
[ { ε ε … … ( ) } ]
B. The string: [{()}]
Start
[ { ε ε … … ( ) } ]
B. The string: [{()}]
Start
[ { ε ε … … ( ) } ]
B. The string: [{()}]
Start
[ { ε ε … … ( ) } ]
B. The string: [{()}]
Start
[ { ε ε … … ( X } ]
B. The string: [{()}]
Find1
[ { ε ε … … X X } ]
B. The string: [{()}]
Start
[ { ε ε … … X X } ]
B. The string: [{()}]
Start
[ { ε ε … … X X Z ]
B. The string: [{()}]
Find3
[ { ε ε … … X X Z ]
B. The string: [{()}]
Find3
[ { ε ε … … X X Z ]
B. The string: [{()}]
Find3
[ Z ε ε … … X X Z ]
B. The string: [{()}]
Start
[ Z ε ε … … X X Z ]
B. The string: [{()}]
Start
[ Z ε ε … … X X Z ]
B. The string: [{()}]
Start
[ Z ε ε … … X X Z ]
B. The string: [{()}]
Start
[ Z ε ε … … X X Z Y
B. The string: [{()}]
Find2
[ Z ε ε … … X X Z Y
B. The string: [{()}]
Rejected (wrong)
{ [ ε ε … … [ ( ) ]
C. The string: {[[()]
Start
{ [ ε ε … … [ ( ) ]
C. The string: {[[()]
Start
{ [ ε ε … … [ ( ) ]
C. The string: {[[()]
Start
{ [ ε ε … … [ ( ) ]
C. The string: {[[()]
Start
{ [ ε ε … … [ ( ) ]
C. The string: {[[()]
Start
{ [ ε ε … … [ ( X ]
C. The string: {[[()]
Find1
{ [ ε ε … … [ X X ]
C. The string: {[[()]
Start
{ [ ε ε … … [ X X ]
C. The string: {[[()]
Start
{ [ ε ε … … [ X X Y
C. The string: {[[()]
Find2
{ [ ε ε … … [ X X Y
C. The string: {[[()]
Find2
{ [ ε ε … … [ X X Y
C. The string: {[[()]
Find2
{ [ ε ε … … Y X X Y
C. The string: {[[()]
Start
{ [ ε ε … … Y X X Y
C. The string: {[[()]
Start
{ [ ε ε … … Y X X Y
C. The string: {[[()]
Start
{ [ ε ε … … Y X X Y
C. The string: {[[()]
Start
{ [ ε ε … … Y X X Y
C. The string: {[[()]
End
{ [ ε ε … … Y X X Y
C. The string: {[[()]
End
{ [ ε ε … … Y X X Y
C. The string: {[[()]
End
{ [ ε ε … … Y X X Y
C. The string: {[[()]
End
{ [ ε ε … … Y X X Y
C. The string: {[[()]
End
{ [ ε ε … … Y X X Y
C. The string: {[[()]
Rejected (unbalanced)