0% found this document useful (0 votes)
16 views21 pages

Lec 17

A Turing machine (TM) is a mathematical model developed by Alan Turing that can accept both context-free languages (CFLs) and some non-context-free languages (non-CFLs). It consists of an input tape, a tape head for reading and writing, an output alphabet, a finite set of states including a start and halt state, and a program of rules dictating state transitions. TMs can demonstrate acceptance of various languages through examples, such as the EVEN-EVEN language and the non-CFL {anbnan}.

Uploaded by

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

Lec 17

A Turing machine (TM) is a mathematical model developed by Alan Turing that can accept both context-free languages (CFLs) and some non-context-free languages (non-CFLs). It consists of an input tape, a tape head for reading and writing, an output alphabet, a finite set of states including a start and halt state, and a program of rules dictating state transitions. TMs can demonstrate acceptance of various languages through examples, such as the EVEN-EVEN language and the non-CFL {anbnan}.

Uploaded by

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

Turing Machine

Turing machine
The mathematical models (FAs, TGs, PDAs)
that have been discussed so far can decide
whether a string is accepted or not by them
i.e. these models are language identifiers.
However, there are still some languages which
can’t be accepted by them e.g. there does not
exist any FA or TG or PDA accepting any non-
CFLs.
Alan Mathison Turing developed the
machines called Turing machines, which
accept some non-CFLs as well, in addition to
CFLs.

2
Turing machine
Definition: A Turing machine (TM) consists of the
following
1. An alphabet Σ of input letters.
2. An input TAPE partitioned into cells, having infinite
many locations in one direction. The input string is
placed on the TAPE starting its first letter on the cell
i, the rest of the TAPE is initially filled with blanks
Input TAPE
(∆’s).
i ii iii iv
a b a ∆ ...

TAPE Head 3
Turing machine continued …
3. A tape Head can read the contents of cell on the
TAPE in one step. It can replace the character at any
cell and can reposition itself to the next cell to the
right or to the left of that it has just read.
Initially the TAPE Head is at the cell i. The TAPE Head
can’t move to the left of cell i. the location of the
TAPE Head is denoted by .
Input TAPE
i ii iii iv
a b a ∆ ...

TAPE Head 4
Turing machine continued …
4. An alphabet Г (Output) of characters that can be
printed on the TAPE by the TAPE Head. Г may include
the letters of Σ. Even the TAPE Head can print blank ∆,
which means to erase some character from the TAPE.
5. Finite set of states containing exactly one START state
and some (may be none) HALT states that cause
execution to terminate when the HALT states are
entered.

5
Turing machine continued …
6. A program which is the set of rules, which show
that which state is to be entered when a letter is read
form the TAPE and what character is to be printed.
This program is shown by the states connected by
directed edges labeled by triplet
(letter, letter, direction)

6
Turing machine continued …
It may be noted that 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 the cell before it leaves. The direction tells the
TAPE Head whether to move one cell to the right, R, or
one cell to the left, L. Following is a note

7
Note
It may be noted that there may not be any outgoing
edge at certain state for certain letter to be read from
the TAPE, which creates nondeterminism in Turing
machines. It may also be noted that at certain state,
there can’t be more than one out going edges for
certain letter to be read from the TAPE. The machine
crashes if there is not path for a letter to be read from
the TAPE and the corresponding string is supposed to
be rejected.

8
Note continued …
To terminate execution of certain input string
successfully, a HALT state must be entered and the
corresponding string is supposed to be accepted by
the TM. The machine also crashes when the TAPE
Head is instructed to move one cell to the left of cell i.
Following is an example of TM

9
Example
Consider the following Turing machine (TM) for
(a+b)b(a+b)*.
(a,a,R)
(b,b,R)
(a,a,R)
(b,b,R) (∆, ∆,R)

1 START 2 3 4 HALT

(b,b,R)

Let the input string aba be run over this TM


10
Example continued …
Input TAPE
i ii iii iv
a b a  ...

TAPE Head
Starting from the START state, reading a form
the TAPE and according to the TM
program, a will be printed i.e. a will be
replaced by a and the TAPE Head will be
moved one cell to the right. 11
Which can be seen as

Input TAPE
i ii iii iv
a b a ∆ ...

TAPE Head
This process can be expressed as

1 2

aba aba 12
At state 2 reading b, state 3 is entered and the letter b
is replaced by b, i.e.

1 2 3
aba → aba → aba
At state 3 reading a, will keep the state of the TM
unchanged. Lastly, the blank ∆ is read and ∆ is
replaced by ∆ and the HALT state is entered. Which
can be expressed as

13
1 2 3 3
→ → → → HALT
aba aba aba aba∆

Which shows that the string aba is accepted by this


machine. It can be observed, from the program of the
TM, that the machine accepts the language expressed
by (a+b)b(a+b)*.

14
EVEN-EVEN language (TM)
Theorem: Every regular language is accepted by
some TM.
Example: Consider the EVEN-EVEN language.
Following is a TM accepting the EVEN-EVEN language.

15
(b,b,R)

(∆,∆,R)
5 HALT 1 START 2
(b,b,R)

(a,a,R) (a,a,R) (a,a,R)


(a,a,R)

(b,b,R)

3 4
(b,b,R)

It may be noted that the above diagram is


similar to that of FA corresponding to
EVEN-EVEN language. Following is another 16
Example: anbn (TM)
(a, a, R) (B, B, L) (B, B, R)
(B, B, R)

(a, A, R) (b,B,L) (A, A,R)


1 START 2 3 5

(A, A, R) (a, a, L)
4 (∆, ∆, R)

6 HALT
(a, a, L)
Example: non-CFL {anbnan} (TM)

Consider the following TM


(a,a,R) (b,b,R)

(b,b,R) (a,a,L)
2 3 4

(b,a,R)
(a,*,R)
(∆, ∆,R) (a,a,R)
9 HALT 1 START 5

(*,*,R) (∆, ∆,L)


(a,a,L)
(b,b,L) (a, ∆,L) (a, ∆,L)
7 6
8
18
Example continued …
The string aaabbbaaa can be observed to be accepted
by the above TM. It can also be observed that the
above TM accepts the non-CFL {anbnan}.

19
PALINDOME (TM)
PALINDOME (TM)

You might also like