2. … ε ε a0 a1 … an ε ε …
RD Input Tape
Head
Finite
Control
qi
3. 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)
4. 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.
7. X/X,L
Find
1
Y/Y,L
[/Y,R
ε/ε,R
Find
Accept End ε/ε,L Start (/(,L {/{,L Z/Z,L ε/ε,L Reject
2
]/Y,L
Y/Y,L
Find
3
X/Y,D
X : Scanned Symbol
Y : Written Symbol [/[,L
D : Move Direction