WOLKITE UNIVERSITY
College of Computing & Informatics
Department of Computer Science
Regular Program
Complexity Theory (CoSc4131)
Chapter two
Turing Machine (TM)
Outline
Revision on alphabet, strings and languages
Turing machine (TM)
Configuration of TM
Construction of TMs
05/10/2022 Turing Machine 2
Revision of Alphabet, String and Language
An alphabet is a finite, non-empty set of symbols
• We use the symbol ∑ (sigma) to denote an alphabet
• Examples:
• Binary: ∑ = {0,1}
• All lower case letters: ∑ = {a,b,c,..z}
• Alphanumeric: ∑ = {a-z, A-Z, 0-9}
A string or word is a finite sequence of symbols chosen from ∑
• Empty string is (or “epsilon”)
• Length of a string w, denoted by “|w|”, is equal to the number of (non- ) characters in
the string
• E.g., x = 010100 |x| = 6
• x = 01 0 1 00 |x| = ?
• xy = concatenation of two strings x and y
05/10/2022 Turing Machine 3
Languages
L is a said to be a language over alphabet ∑, only if L ∑* this is
because ∑* is the set of all strings (of all possible length including
) over the given alphabet ∑
Examples:
1. Let L be the language of all strings consisting of n 0’s
followed by n 1’s:
L = {, 01, 0011, 000111,…}
2. Let L be the language of all strings of with equal number of
0’s and 1’s:
L = {, 01, 10, 0011, 1100, 0101, 1010, 1001,…}
05/10/2022 Turing Machine 4
Languages…
• Example: L={x:xЄ{0,1}* and x is a prime number written in binary}
11 Є L , 101 Є L, 10001 Є L, 1000 L
How to describe languages?
o Enumeration: {a, ac, da}, i,e As defined set of elements
o Regular expressions : c(ab)*(d/c)
o Context free grammars: SdTd, TTT|aTb|
o Set notation: L={x|xЄ{0,1}*}
05/10/2022 Turing Machine 5
The Membership Problem
Given a string w ∑*and a language L over ∑, decide whether or
not w L.
Example:
Let w = 100011
Q) Is w the language of strings with equal number of 0s and 1s?
05/10/2022 Turing Machine 6
Turing machine
• The abstract models of computing devices:
Deterministic Finite Automata, Nondeterministic Finite Automata,
Nondeterministic Finite Automata with -Transitions, Pushdown Automata,
and Deterministic Pushdown Automata.
• However, none of the above “seem to be” as powerful as a real
computer
• We now turn our attention to a much more powerful abstract
model of a computing device: a Turing machine.
• This model is believed to do everything that a real general purpose
computer can do.
05/10/2022 Turing Machine 7
Turing machine…
• A Turing machine is somewhat similar to a finite automaton, Just like the
finite state automaton the Turing Machine solves decision problems
- Both of them attempts to decide if a string is in a given language.
• Furthermore, both have a finite set of states.
• There are important differences:
1. A TM can both write on the tape and read from it.
2. The read-write head can move both to the left and to the right.
3. The tape is infinite.
4. The special states for rejecting and accepting take immediate effect
05/10/2022 Turing Machine 8
Turing machine…
• A Turing machine is a hypothetical machine thought of by the
mathematician Alan Turing in 1936.
• Despite its simplicity, the machine can simulate any computer
algorithm, no matter how complicated .
• It consists of:
A head which reads the input tape.
A state register stores the state of the Turing machine.
After reading an input symbol, it is replaced with another symbol, its
internal state is changed, and it moves from one cell to the right or left.
If the TM reaches the final state, the input string is accepted, otherwise
rejected.
05/10/2022 Turing Machine 9
Turing machine …
• A TM can be formally described as a 7-tuple (Q, Γ, ∑, δ, q0, qa, qr)
where −
1. A finite set of states (Q, typically).
2. An input alphabet (Σ, typically).
3. A tape alphabet (Γ, typically; contains Σ), which includes a
blank symbol, B, not in Σ.
• Entire tape except for the input is initially blank.
4. A transition function (δ, typically). δ :Qx Γ Qx Γx{L,R}
5. A start state (q0, in Q, typically).
6. An accept state (F or qaccept, typically).
7. A reject state (r or qreject, typically).
05/10/2022 Turing Machine 10
Turing machine…
05/10/2022 Turing Machine 11
Turing machine…
05/10/2022 Turing Machine 12
Turing machine…
•
Final states have no outgoing transitions and then the machine halts
05/10/2022 Turing Machine 13
Turing machine…
05/10/2022 Turing Machine 14
Turing machine…
05/10/2022 Turing Machine 15
Turing machine…
05/10/2022 Turing Machine 16
Configuration of TM
05/10/2022 Turing Machine 17
Configuration
Configuration of TM
of Turing machine
05/10/2022 Turing Machine 18
Configuration of TM…
05/10/2022 Turing Machine 19
Configuration of TM…
05/10/2022 Turing Machine 20
Configuration of TM…
05/10/2022 Turing Machine 21
Configuration of TM…
05/10/2022 Turing Machine 22
Configuration of TM…
05/10/2022 Turing Machine 23
Configuration of TM…
05/10/2022 Turing Machine 24
Configuration of TM…
05/10/2022 Turing Machine 25
State diagram of TM
05/10/2022 Turing Machine 26
State diagram of TM
05/10/2022 Turing Machine 27
State diagram of TM…
05/10/2022 Turing Machine 28
State diagram of TM…
05/10/2022 Turing Machine 29
05/10/2022 Turing Machine 30
05/10/2022 Turing Machine 31
05/10/2022 Turing Machine 32
05/10/2022 Turing Machine 33
05/10/2022 Turing Machine 34
05/10/2022 Turing Machine 35
05/10/2022 Turing Machine 36
05/10/2022 Turing Machine 37
05/10/2022 Turing Machine 38
05/10/2022 Turing Machine 39
05/10/2022 Turing Machine 40
05/10/2022 Turing Machine 41
05/10/2022 Turing Machine 42
05/10/2022 Turing Machine 43
Because of the infinite loop:
• The final state cannot be reached
• The machine never halts
• The input is not accepted
05/10/2022 Turing Machine 44
05/10/2022 Turing Machine 45
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
05/10/2022 Formal Language and Automata theory 46
05/10/2022 Turing Machine 47
05/10/2022 Turing Machine 48
05/10/2022 Turing Machine 49
05/10/2022 Turing Machine 50
05/10/2022 Turing Machine 51
05/10/2022 Turing Machine 52
05/10/2022 Turing Machine 53
05/10/2022 Turing Machine 54
05/10/2022 Turing Machine 55
05/10/2022 Turing Machine 56
05/10/2022 Turing Machine 57
05/10/2022 Turing Machine 58
05/10/2022 Turing Machine 59
05/10/2022 Turing Machine 60
Exercise-1
•Design a Turing machine for the
language containing a stings of 0’s
and 1’s ending with 011
05/10/2022 Turing Machine 61
05/10/2022 Turing Machine 62
Exercise 2
• Obtain a Turing machine to accept the language
L={w\w is even and ∑={a,b}}
05/10/2022 Turing Machine 63
05/10/2022 Turing Machine 64
Exercise-3
• Construct a Turing machine which accepts the
language of aba over ∑={a,b}
05/10/2022 Turing Machine 65
Solution -3
05/10/2022 Turing Machine 66
THE END
05/10/2022 Turing Machine 67