0% found this document useful (0 votes)
141 views66 pages

Turing Machines: Costas Busch - LSU 1

1. A Turing machine is a computational model of algorithm execution that consists of a tape, a read/write head, finite state control, and a table of transitions between states. 2. The tape is infinite in both directions and divided into cells that can hold symbols. The head reads, writes, and moves left or right along the tape. 3. The machine operates by reading the symbol under the head, writing a new symbol, moving the head, and transitioning to a new state according to the transition table. 4. A Turing machine accepts or rejects an input string based on whether it halts in an accepting state or non-accepting state. It may also loop infinitely

Uploaded by

Elite Squad
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)
141 views66 pages

Turing Machines: Costas Busch - LSU 1

1. A Turing machine is a computational model of algorithm execution that consists of a tape, a read/write head, finite state control, and a table of transitions between states. 2. The tape is infinite in both directions and divided into cells that can hold symbols. The head reads, writes, and moves left or right along the tape. 3. The machine operates by reading the symbol under the head, writing a new symbol, moving the head, and transitioning to a new state according to the transition table. 4. A Turing machine accepts or rejects an input string based on whether it halts in an accepting state or non-accepting state. It may also loop infinitely

Uploaded by

Elite Squad
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/ 66

Turing Machines

Costas Busch - LSU 1


The Language Hierarchy

n n n ?
a b c ww ?

Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
Costas Busch - LSU 2
Languages accepted by
Turing Machines
n n n
a b c ww

Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
Costas Busch - LSU 3
A Turing Machine
Tape
...... ......

Read-Write head
Control Unit

Costas Busch - LSU 4


The Tape

No boundaries -- infinite length


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

Read-Write head

The head moves Left or Right

Costas Busch - LSU 5


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

Read-Write head

The head at each transition (time step):

1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Costas Busch - LSU 6
Example:
Time 0
...... a b a c ......

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

1. Reads a
2. Writes k
3. Moves Left
Costas Busch - LSU 7
Time 1
...... a b k c ......

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

1. Reads b
2. Writes f
3. Moves Right
Costas Busch - LSU 8
The Input String

Input string Blank symbol

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

head

Head starts at the leftmost position


of the input string
Costas Busch - LSU 9
States & Transitions

Read Write
Move Left

q1 a  b, L q2

Move Right

q1 a  b, R q2
Costas Busch - LSU 10
Example:
Time 1
......   a b a c    ......

q1
current state

q1 a  b, R q2
Costas Busch - LSU 11
Time 1
......   a b a c    ......

q1

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

q2

q1 a  b, R q2
Costas Busch - LSU 12
Example:
Time 1
......   a b a c    ......

q1

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

q2

q1 a  b, L q2
Costas Busch - LSU 13
Example:
Time 1
......   a b a c    ......

q1

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

q2

q1   g, R q2
Costas Busch - LSU 14
Determinism
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

No lambda transitions allowed


Costas Busch - LSU 15
Partial Transition Function
Example:

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

q1
Allowed:
a  b, R q2
No transition
q1 for input symbol c
b  d, L q3
Costas Busch - LSU 16
Observation:
In order to accept an input string,
it is not necessary to scan all the
symbols in the string

Costas Busch - LSU 17


Halting

The machine halts in a state if there is


no transition to follow

Costas Busch - LSU 18


Halting Example 1:

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

q1

q1 No transition from q1
HALT!!!

Costas Busch - LSU 19


Halting Example 2:

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

q1

a  b, R q2
No possible transition
q1 from q1 and symbol c
b  d, L q3 HALT!!!
Costas Busch - LSU 20
Accepting States

q1 q2 Allowed

q1 q2 Not Allowed

•Accepting states have no outgoing transitions


•The machine halts and accepts

Costas Busch - LSU 21


Acceptance

If machine halts
Accept Input
string in an accept state

If machine halts
in a non-accept state
Reject Input or
string
If machine enters
an infinite loop
Costas Busch - LSU 22
Turing Machine Example

Input alphabet   {a , b }

Accepts the language: a*


a  a, R

  , L
q0 q1

Costas Busch - LSU 23


Time 0   a a a  

q0

a  a, R

  , L
q0 q1

Costas Busch - LSU 24


Time 1   a a a  

q0

a  a, R

  , L
q0 q1

Costas Busch - LSU 25


Time 2   a a a  

q0

a  a, R

  , L
q0 q1

Costas Busch - LSU 26


Time 3   a a a  

q0

a  a, R

  , L
q0 q1

Costas Busch - LSU 27


Time 4   a a a  

q1

a  a, R Halt & Accept

  , L
q0 q1

Costas Busch - LSU 28


Rejection Example

Time 0   a b a  

q0

a  a, R

  , L
q0 q1
Costas Busch - LSU 29
Time 1   a b a  

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

  , L
q0 q1
Costas Busch - LSU 30
A simpler machine for same language
but for input alphabet   {a }

Accepts the language: a*

q0

Costas Busch - LSU 31


Time 0   a a a  

q0

Halt & Accept

q0

Not necessary to scan input

Costas Busch - LSU 32


Infinite Loop Example
A Turing machine
for language a * b(a  b) *

b  b, L
a  a, R

  , L
q0 q1

Costas Busch - LSU 33


Time 0   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

Costas Busch - LSU 34


Time 1   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

Costas Busch - LSU 35


Time 2   a b a  

q0

b  b, L
a  a, R

  , L
q0 q1

Costas Busch - LSU 36


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
Costas Busch - LSU 37
Because of the infinite loop:

•The accepting state cannot be reached

•The machine never halts

•The input string is rejected

Costas Busch - LSU 38


Another Turing Machine Example
n n
Turing machine for the language {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
Costas Busch - LSU 39
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

Costas Busch - LSU 40


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
Costas Busch - LSU 41
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
Costas Busch - LSU 42
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
Costas Busch - LSU 43
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
Costas Busch - LSU 44
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
Costas Busch - LSU 45
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
Costas Busch - LSU 46
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
Costas Busch - LSU 47
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
Costas Busch - LSU 48
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
Costas Busch - LSU 49
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
Costas Busch - LSU 50
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
Costas Busch - LSU 51
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
Costas Busch - LSU 52
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
Costas Busch - LSU 53
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
Costas Busch - LSU 54
Observation:

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

we can easily construct


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

Costas Busch - LSU 55


Formal Definitions
for
Turing Machines

Costas Busch - LSU 56


Transition Function

q1 a  b, R q2

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

Costas Busch - LSU 57


Transition Function

q1 c  d, L q2

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

Costas Busch - LSU 58


Turing Machine:

Input Tape
alphabet alphabet
States

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

Transition Accept
function states
Initial blank
stateCostas Busch - LSU 59
Configuration

  c a b a  

q1

Instantaneous description: ca q1 ba

Costas Busch - LSU 60


Time 4 Time 5
 x a y b    x a y b  

q2 q0

A Move: q2 xayb  x q0 ayb

Costas Busch - LSU 61


Time 4 Time 5
 x a y b    x a y b  

q2 q0

Time 6 Time 7
 x x y b    x x y b  

q1 q1
A computation
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b
Costas Busch - LSU 62
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b


Equivalent notation: q2 xayb  xxy q1 b

Costas Busch - LSU 63


Initial configuration: q0 w

Input string

 a a b b  

q0

Costas Busch - LSU 64


The Accepted Language

For any Turing Machine M


L( M )  {w : q0 w  x1 q f x2 }

Initial state Accept state

Costas Busch - LSU 65


If a language L is accepted
by a Turing machine M
then we say that L is:

•Turing Recognizable

Other names used:


•Turing Acceptable
•Recursively Enumerable

Costas Busch - LSU 66

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy