Professional Documents
Culture Documents
Chapter19 PDF
Chapter19 PDF
1
● The tape:
HALT
● The start state can have any number of outgoing and incoming
edges.
2
Program Rules
● The first letter is the character the tape head reads from the cell
to which it is pointing.
● The second letter is what the tape head prints in the cell before
it leaves the cell.
● The direction is R (right) or L (left) and indicates if the tape
head should move one cell to the right or one cell to the left.
3
● Turing machines are deterministic. There is at most one
transition out of each state labeled with the same first letter.
● The machine crashes
§ if there is no arrow labeled with the letter in the cell pointed
to by the tape head .
§ if it tries to move left from the first cell.
● A word is accepted when a final state is entered.
4
Execution of a Turing Machine: 3 possibilities
The tape head moves to the right one cell at a time forever.
5
(a,a,R)
(b,b,R)
(a,a,R)
START 1 2 3 HALT 4
(b,b,R) (D,D,R)
(b,b,R)
S = {a,b}
a b a D D D … G = {a,b}
(a+b)b(a+b)*
1 à 2 à 3
a b a D … aba aba aba
a b a D … à 3 à HALT
abaD abaDD
6
Example: {anbn| n ³ 1}
S={a,b} G={a,A,B}
(a,a,R)
(B,B,R) (B,B,L) (B,B,R)
START 1 2 3 5
(a,A,R) (b,B,L) (A,A,R)
(D,D,R)
(A,A,R) (a,a,L)
4 HALT
(a,a,L)
7
8
Example: PALINDROME
(b,b,R) (b,b,L)
(a,a,R) (a,a,L)
2 3 4
(a,D,R) (D,D,L) (a,D,L) (D,D,R)
(D,D,R)
START 1
(D,D,R)
HALT 8
(D,D,R)
(b,D,R) (D,D,L) (b,D,L) (D,D,R)
5 6 7
(a,a,R) (b,b,L)
(b,b,R) (a,a,L)
9
10
11
Example:
read an a,PALINDROME
then
search for a at
the end (b,b,R) (b,b,L)
(a,a,R) (a,a,L)
2 3 4
(a,D,R) (D,D,L) (a,D,L) (D,D,R)
(D,D,R)
START 1
(D,D,R)
HALT 8 Odd
PALINDROME
(D,D,R)
(b,D,R) (D,D,L) (b,D,L) (D,D,R)
5 6 7
Even
PALINDROME
read a b, then
search for b at
(a,a,R) (b,b,L)
the end (b,b,R) (a,a,L)
12
● Theorem. For every regular language, there is a Turing
machine that accepts it.
Proof: We transform a finite automaton to a Turing machine.
§ The start state of the finite automaton is the start state of
the Turing machine.
§ Add a halt state to the Turing machine, and one transition
from every final state of the finite automaton to the new
halt state. (Erase all the + symbols.) Label the new
transitions (D,D,R).
§ Change each label “a” of the finite automaton to (a,a,R),
and similarly for all other letters of S.
13
Example: EVEN-EVEN
(b,b,R)
START 1 2
(b,b,R)
(D,D,R)
(a,a,R) (a,a,R) (a,a,R) (a,a,R)
HALT
(b,b,R)
3 4
(b,b,R)
14
(a+b)*aa(a+b)*
(D,D,R)
(b,b,R)
(a,a,R)
START 1 2 HALT 3
(a,a,R)
(b,b,R)
● If we reach the HALT state, execution terminates and the
word is accepted. (double a)
● If the machine crashes, the word is rejected. (words with no
aa ending in a)
● It is also possible to get into an infinite loop. (words with no
aa ending in b, or the empty word)
15
{anbnan| n ³ 0}
(a,a,R) (b,b,R)
2 3 4
(b,b,R) (a,a,L)
(b,a,R)
(a,*,R)
(a,a,R)
HALT START 1 5
(D,D,R)
(*,*,R) (D,D,L)
(a,D,L) (a,D,L)
8 7 6
(a,a,L)
(b,b,L)
16
17
The Subprogram “INSERT”
… b X a b b X D D …
INSERT b
… b X b a b b X D D …
18
S={a,b,X} (a,a,R) 2
G={Q,a,b,X}
INSERT # 6 7 8 9
(a,X,L) (#,#,R) (b,X,L)
(D,D,L) (#,#,R)
b b b a a a b a D …
# X b b X a a b a D
21
The Subprogram “DELETE”
… F R I E N D D D …
DELETE
… F I E N D D D …
22
S={a,b,c} (c,c,L) 6
(D,c,R)
G={a,b,c}
(c,D,L) (c,b,L) (b,c,L) (a,c,L)
(b,D,L) (b,b,L)
3 5
(D,b,R) 7
(D,D,L) (a,D,L) (c,a,L)
(c,c,R) (b,a,L) (a,b,L)
(b,b,R)
(a,a,R) 2
(c, D,R) (a,a,L) 4 (D,a,R)
(b, D,R)
(a, D,R)
1
23