Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views61 pages

At Lecture # 10 - Turing Machines

The document provides an overview of Turing Machines (TMs), detailing their structure, operation, and the types of languages they can accept, including context-free and regular languages. It explains the components of a TM, such as the tape, control unit, and read-write head, and describes the process of reading, writing, and transitioning between states. Additionally, it covers concepts like halting, accepting states, and provides examples of TMs in action, illustrating how they process input strings and determine acceptance or rejection.

Uploaded by

24pwbcs1126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views61 pages

At Lecture # 10 - Turing Machines

The document provides an overview of Turing Machines (TMs), detailing their structure, operation, and the types of languages they can accept, including context-free and regular languages. It explains the components of a TM, such as the tape, control unit, and read-write head, and describes the process of reading, writing, and transitioning between states. Additionally, it covers concepts like halting, accepting states, and provides examples of TMs in action, illustrating how they process input strings and determine acceptance or rejection.

Uploaded by

24pwbcs1126
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

TURING MACHINE

(TM)

Dr. Imran Khalil


[email protected]
Languages accepted by
Turing Machines
n n n
a b c
Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
1
A Turing Machine
Tape
...... ......

Control Unit Read-Write head

2
The Tape

No boundaries -- infinite length

...... ......

Read-Write head

The head moves Left or Right


3
Read-Write head

...... ......

The head at each transition (time step):

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
4
Example:
Time 0
...... a b a c ......

Time 1
...... a b k c ......

1. Reads a
2. Writes k
3. Moves Left 5
Time 1
...... a b k c ......

Time 2
...... a f k c ......

1. Reads b
2. Writes f
3. Moves Right 6
The Input String

Input string Blank symbol

......   a b a c    ......

head

Head starts at the leftmost position


of the input string
7
States & Transitions
Read Write Move Left

q1 a → b, L q2

Move Right

q1 a → b, R q2
8
Example:
Time 1
......   a b a c    ......

q1
current state

q1 a → b, R q2
9
Time 1
......   a b a c    ......

q1

Time 2
......   a b b c    ......

q2

q1 a → b, R q2
10
Example:
Time 1
......   a b a c    ......

q1

Time 2
......   a b b c    ......

q2

q1 a → b, L q2
11
Example:
Time 1
......   a b a c    ......

q1

Time 2
......   a b b c g   ......

q2

q1  → g, R q2
12
Turing Machines are deterministic

Allowed Not Allowed


a → b, R q2 a → b, R q2

q1 q1
q3 a → d, L q3
b → d, L

13
Partial Transition Function
Example:
......   a b a c    ......

q1

a → b, R q2 Allowed:

No transition
q1
for input symbol c
b → d, L q3
14
Halting

The machine halts in a state if there is


no transition to follow

15
Halting Example 1:

......   a b a c    ......

q1

q1 No transition from q1
HALT!!!
16
Halting Example 2:

......   a b a c    ......

q1

a → b, R q2
No possible transition
q1 from q1 for symbol c
b → d, L q3 HALT!!!
17
Accepting States
q1 q2 Allowed

q1 q2 Not Allowed

•Accepting states have no outgoing transitions


•The machine halts and accepts
18
Acceptance

Accept Input If machine halts


string in an accept state

If machine halts
in a non-accept state
Reject Input or
string
If machine enters
an infinite loop
19
Turing Machine Example
Input alphabet  = {a , b }

Accepts the language: a*


a → a, R

 → , L
q0 q1

20
Time 0:   a a a  

q0

a → a, R

 → , L
q0 q1

21
Time 1:   a a a  

q0

a → a, R

 → , L
q0 q1

22
Time 2:   a a a  

q0

a → a, R

 → , L
q0 q1

23
Time 3:   a a a  

q0

a → a, R

 → , L
q0 q1

24
Time 4:   a a a  

q1

a → a, R Halt & Accept

 → , L
q0 q1

25
Rejection Example

Time 0   a b a  

q0

a → a, R

 → , L
q0 q1
26
Time 1   a b a  

q0
No possible Transition
a → a, R Halt & Reject

 → , L
q0 q1
27
Infinite Loop Example
A Turing machine
a * +b( a + b) *
for language

b → b, L
a → a, R

 → , L
q0 q1

28
Time 0:   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

29
Time 1:   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

30
Time 2:   a b a  

q0

b → b, L
a → a, R

 → , L
q0 q1

31
Time 2   a b a  
q0
  a b a  

Infinite loop
Time 3
q0
Time 4   a b a  
q0

Time 5   a b a  
q0 32
Because of the infinite loop:

•The accepting state cannot be reached

•The machine never halts

•The input string is rejected

33
Another Turing Machine
Example
Turing machine for the language n n
{a b }
n 1

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 34
Basic Idea:

Match a’s with b’s:


Repeat:
replace leftmost a with x
find leftmost b and replace it with y
Until there are no more a’s or b’s

If there is a remaining a or b reject

35
Time 0:  a a b b  

q0

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 36
Time 1:  x a b b  

q1

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 37
Time 2:  x a b b  

q1

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 38
Time 3:  x a y b  

q2

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 39
Time 4:  x a y b  

q2

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 40
Time 5:  x a y b  

q0

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 41
Time 6:  x x y b  

q1

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 42
Time 7:  x x y b  

q1

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 43
Time 8:  x x y y  

q2

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 44
Time 9:  x x y y  

q2

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 45
Time 10:  x x y y  

q0

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 46
Time 11:  x x y y  

q3

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 47
Time 12:  x x y y  

q3

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 48
Time 13:  x x y y  

q4
Halt & Accept

q4 y → y, R y → y, L
y → y, R a → a, R a → a, L
 → , L

y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R 49
Observation:

If we modify the
n n
machine for the language {a b }

we can easily construct


n n n
a machine for the language {a b c }

50
Turing machine for the language n n n
{a b c }
n 1

51
Turing machine for the language n n n
{a b c }
n 1

52
TURING MACHINES::FORMAL
DEFINITIONS

53
Transition Function

q1 a → b, R q2

 (q1, a ) = (q2 , b, R )

54
Transition Function

q1 c → d, L q2

 (q1, c) = (q2 , d , L)

55
Turing Machine:

Input Tape
alphabet alphabet
States

M = (Q, , ,  , q0 , , F )

Transition Accept
function states
Initial blank
state 56
If a language L is accepted
by a Turing machine M
then we say that L is:
•Turing Recognizable

Other names used:


•Turing Acceptable

57
Example
Example
Acknowledgment

• [Michael_Sipser] Introduction to the Theory of Computation.


• [Margaret Fleck and Sariel Har Peled] Introduction to the
Theory of Computation.
• [John_E._Hopcroft] Intro to Automata Theory, Language and
Computation.
• .

60

You might also like