EECS 2001: Introduction to the
Theory of Computation
Muhammad Umair Khan
Turing Machine (02
n
) n => 0
EECS 2001 Introduction to Theory of Computation 2
 String of zeros with length power of 2
 0, 00, 0000, 00000000, ….
 Major Steps
 Read left to right and cross off every second 0
 If there was only one zero on the tape, accept
 If there were more than one zero, and if the number of zeros was odd, reject
 Return to the left end of the tape
 Start over
 Technique: removing half of the zeros in every pass
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 3
 Formal Description
 Q = {p1, p2, p3, p4, p5, paccept, preject},
 • Σ = {0}, and
 • Γ = {0,x,␣}.
 • We describe δ with a state diagram (see Figure 3.8).
 • The start, accept, and reject states are p1, paccept, and preject,
respectively.
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 4
␣  R
x  R
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 5
0  ␣, R
␣  R
x  R
␣  R
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 6
0  ␣, R
x  R
0  x, R
␣  R
x  R
␣  R
␣  L
␣  R
x  L
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 7
0  ␣, R
x  R
␣  R
x  R
0  x, R
␣  R
x  R
0  R
␣  R
␣  L
␣  R
x  L
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 8
0  ␣, R
x  R
0  x, R
␣  R
x  R
0  x, R x  R
␣  R
x  R
0  R
␣  R
␣  L
␣  R
0  L
x  L
Turing Machine (02
n
)
EECS 2001 Introduction to Theory of Computation 9
 Walk through with string 0000
1: 0000␣ 2: ␣000␣ 3: ␣x00␣ 4: ␣x00␣
3: ␣x0x␣ 5: ␣x0x␣ 5: ␣x0x␣ 5: ␣x0x␣
5: ␣x0x␣ 2: ␣x0x␣ 2: ␣x0x␣ 3: ␣xxx␣
3: ␣xxx␣ 5: ␣xxx␣ 3: ␣xxx␣ 3: ␣xxx␣
3: ␣xxx␣ 2: ␣xxx␣ 2: ␣xxx␣ 2: ␣xxx␣
2: ␣xxx␣ accept:
Turing Machine (C = {aibjck| i × j = k and i, j, k ≥ 1}.)
EECS 2001 Introduction to Theory of Computation 10
M3 = “On input string w:
 1. Scan the input from left to right to determine whether it is a member of
a+b+c+ and reject if it isn’t.
 2. Return the head to the left-hand end of the tape.
 3. Cross off an a and scan to the right until a b occurs. Shuttle between the
b’s and the c’s, crossing off one of each until all b’s are gone. If all c’s have
been crossed off and some b’s remain, reject .
 4. Restore the crossed off b’s and repeat step 3 if there is another a to cross
off. If all a’s have been crossed off, determine whether all c’s also have been
crossed off. If yes, accept; otherwise, reject .”
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 11
 Construct a TM to accept palindromes using one tape
 Start reading, if an a/b is encountered, cross it, move
to the end and read the last symbol: (1) if the first and
last match, cross the last, move to the beginning: (2) if
the last symbol is end of input, accept.
 Repeat step 1 until there are no symbols left. Accept.
 If at any point the first and last do not match, reject.
 Question: is the empty string accepted?
 Will the above machine work for a single character
string?
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 12
 Construct a TM to accept palindromes using one tape
 States
 q0 : start state; tape head is on the leftmost symbol
 qa : leftmost symbol was a; crossed it, tape head is moving to the right
 qb : leftmost symbol was b; crossed it, tape head is moving to the right
 q′a : reached rightmost symbol; test whether it is equal to a, and delete it
 q′b : reached rightmost symbol; test whether it is equal to b, and delete it
 qL : test was positive; tape head is moving to the left
 qaccept : accept state
 qreject : reject state
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 13
 Construct a TM to accept palindromes using one tape
 Transitions
 q0 , a → qa , ␣, R qa, a → qa, a, R
 qb, a → qb, a, R q0, b → qb, ␣, R
 qa, b → qa, b, R qb, b → qb, b, R
 q0 , ␣ → qaccept qa, ␣ → q′a, ␣, L
 qb , ␣ → q′b, ␣, L q′a, a → qL, ␣, L
 q′b, a → qreject qL, a → qL, a, L
 q′a , b → qreject q′b, b → qL, ␣, L
 qL, b → qL, b, L q′a, ␣ → qaccept
 q′b , ␣ → qaccept qL, ␣ → q0, ␣, R
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 14
 Construct a TM to accept the language {albman | m = l
+ n; l, m, n are natural numbers)
 If the first letter is a, cross it, move right to find a b, cross it, come back
(left) to the start of the tape
 Repeat the first step till all a’s before the b’s are crossed out
 Move to the first of the remaining b’s, read the first one, cross it, move right
till you find an a, cross it, move back left to the first of the remaining b’s
 Repeat the third step until all the b’s and a’s have been crossed out.
if any b’s or a’s are left, reject. Otherwise accept
if a b occurs after the second set of a’s, reject
Turing Machine
EECS 2001 Introduction to Theory of Computation 15
 TM M4 is solving what is called the element distinctness problem. It is given a list of
strings over {0,1} separated by #s and its job is to accept if all the strings are different.
The language is
E = {#x1#x2# · · · #xl| each xi ∈ {0,1}∗ and xi ≠ xj for each i ≠ j}.
 Machine M4 works by comparing x1 with x2 through xl, then by comparing x2 with x3
through xl, and so on. An informal description of the TM M4 deciding this language
follows.
 M4 = “On input w:
 1. Place a mark on top of the leftmost tape symbol. If that symbol was a blank, accept. If
that symbol was a #, continue with the next step. Otherwise, reject.
 2. Scan right to the next # and place a second mark on top of it. If no # is encountered
before a blank symbol, only x1 was present, so accept.
 3. By zig-zagging, compare the two strings to the right of the marked #s. If they are
equal, reject.
 4. Move the rightmost of the two marks to the next # symbol to the right. If no # symbol
is encountered before a blank symbol, move the leftmost mark to the next # to its right
and the rightmost mark to the # after that. This time, if no # is available for the rightmost
mark, all the strings have been compared, so accept .
 5. Go to step 3.”
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 16
 Construct a TM to accept the language of all words w
such that each w has at least one more b than a
 ababb
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 17
 Construct a TM to accept the language of all words w
such that each w has at least one more b than a
 Start reading, if an a/b is encountered, cross it, move forward till you find
the opposite a/b, cross that too (if you cannot find a b and reach the end of
tape, reject), move to the beginning of the tape
 Repeat Step 1 until you cannot find any a. If you still find a b (uncrossed),
accept. If you cannot find a b after crossing out all a’s, reject.
 Note: sequence of a’s and b’s do not matter in this particular problem
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 18
 Construct a TM to accept palindromes using two tapes
 Tape 1 has original input
 Tape 2 has original input
 Read first symbol of Tape 1 and last symbol of Tape 2, compare, if both are
equal, move Tape 1 head right and Tape 2 head left.
 Repeat till Tape 1 head reaches end and Tape 2 head reaches start
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 19
 Construct a TM to accept palindromes using two tapes
 Tape 1 has original input
 Tape 2 has original input
 Read first symbol of Tape 1 and last symbol of Tape 2, compare, if both are
equal, move Tape 1 head right and Tape 2 head left.
 Repeat till Tape 1 head reaches end and Tape 2 head reaches start
 NOTE: we are not crossing out the already read input symbols as we did in
the single tape TM
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 20
 Construct a TM to accept anbncn using one tape (n≥0)
 Tape alphabet = a, b, c, x, ␣
 Step 1: check the sequence, read all the tape without altering,
check whether all a’s come before all b’s and all b’s come
before all c’s. If not reject.
 Step 2: Read the left most a, cross it, read the leftmost b, cross
it, read the left most c, cross it. Move to the leftmost a. Repeat.
 Step 3: If any one symbol is not found but others are, reject.
 aaabbbbccc
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 21
 Construct a TM to accept anbncn using one tape (n>=0)
without crossing it (remember crossing uses an extra
symbol x)
 Tape alphabet = a, b, c, ␣
 Step 1: check the sequence, read all the tape without altering, check
whether all a’s come before all b’s and all b’s come before all c’s. If
not reject.
 Step 2: Read the left most a, read the leftmost b, overwrite the
rightmost a with the leftmost b, read the left most c, overwrite 2
rightmost b’s with c’s, move to the end, overwrite three right most
c’s with the end of input symbol. (in one step we have essentially
deleted one a, one b, one c, in total 3 symbols).
 Step 3: If any one symbol is not found but others are, reject.
 aaabbbcc – aabbbbcc- aabbcccc-aabbc___- abbbc_- abccc_ - ab___-
bb- cc
Turing Machine Examples
EECS 2001 Introduction to Theory of Computation 22
 For practice
 Construct a TM to accept all strings over {a, b, c} such
that the number of a = to number of b = number of c
(sequence does not matter)
Turing Machine (02
n
) 0 00 0000
EECS 2001 Introduction to Theory of Computation 23
0  ␣, R
x  R
0  x, R
␣  R
x  R
0  x, R x  R
␣  R
x  R
0  R
␣  R
␣  L
␣  R
0  L
x  L
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 24
Q what would be the sequence of configurations of the preceding TM when
00 is given as the input string?
Configuration : Current state, current location of the head, and current contents
of the tape
p1 00, ␣ p2 0,
␣ x p3 ␣, ␣ p5 x ␣,
p5 ␣ x ␣, ␣ p2 x ␣,
␣ x p2 ␣, ␣ x ␣ paccept
(The head has moved right – beyond the input but it does not matter as we are
in the accept state)
Turing Machine (w#w)
EECS 2001 Introduction to Theory of Computation 25
1  x, R
x  L
0  x, R
0  x, L
0,1  R
x  R
#  R
0,1  R
#  R
x  R
#  R
1  x, L
#  L
0,1  L
␣  R
x  R
x  R
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 26
Q what would be the sequence of configurations of the preceding TM when 11
is given as the input string?
Configuration : Current state, current location of the head, and current contents
of the tape
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 27
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
a. Can a Turing machine ever write the blank symbol ␣ on its tape?
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 28
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
a. Can a Turing machine ever write the blank symbol ␣ on its tape?
Yes, it is part of the tape alphabet. This can be written to signal the start
of the tape as well as the end of input (not the ned of tape).
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 29
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
b. Can the tape alphabet Γ be the same as the input alphabet Σ?
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 30
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
b. Can the tape alphabet Γ be the same as the input alphabet Σ?
No, we could force it to be equal however the resulting TM will not work
as we will be using the blank symbol in the input as well as the end of
input.
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 31
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
c. Can a Turing Machine’s head ever be in the same location in two successive
steps?
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 32
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
c. Can a Turing Machine’s head ever be in the same location in successive
steps?
Yes, according to the definition of the TM, if we are at the left most place
on the tape, and we attempt to move left, the TM stays on the same place.
(there is no left to the left most)
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 33
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
d. Can a Turing Machine contain just a single state?
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 34
Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to
answer the following questions, and explain your reasoning.
d. Can a Turing Machine contain just a single state?
Note we are not talking about the places in the tape, but the actual TM
(which looks like a state machine). No, according to the definition, accept
state must be different from the reject state.
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 35
 Q Give implementation-level descriptions of Turing machine that decide the
following language over the alphabet {0,1}.
 {w| w contains an equal number of 0s and 1s}
Turing Machine Questions
EECS 2001 Introduction to Theory of Computation 36
 Q Give implementation-level descriptions of Turing machine that decide the
following language over the alphabet {0,1}.
 {w| w contains an equal number of 0s and 1s}
 1. Scan the tape and mark the first 0 that has not been marked. If no unmarked 0 is
found, go to Step 4. Otherwise, move the head back to the front of the tape and
move to step 2.
 2. Scan the tape and mark the first 1 that has not been marked. Go to Step 3. If no
unmarked 1 is found, reject .
 3. Move the head back to the front of the tape and go to Step 1.
 4. Move the head back to the front of the tape. Scan the tape to see if any unmarked
1s remain. If none are found, accept; otherwise, reject .
References
EECS 2001 Introduction to Theory of Computation 37
Ideas, problems and their solutions in this lecture/tutorial have been taken from
• Prof. Jeffery Edmonds’ Lecture notes for EECS 2001 at York University
• Prof. Suprakash Datta’ Lecture notes for EECS 2001 at York University
• Introduction to the Theory of Computation (3rd edition) by Michael Sipser
• Introduction to Theory of Computation by Anil Maheshwari and Michiel Smid
• Wikipedia and other webpages of different professors/universities

Winter 8 Tutorial TM.pptx

  • 1.
    EECS 2001: Introductionto the Theory of Computation Muhammad Umair Khan
  • 2.
    Turing Machine (02 n )n => 0 EECS 2001 Introduction to Theory of Computation 2  String of zeros with length power of 2  0, 00, 0000, 00000000, ….  Major Steps  Read left to right and cross off every second 0  If there was only one zero on the tape, accept  If there were more than one zero, and if the number of zeros was odd, reject  Return to the left end of the tape  Start over  Technique: removing half of the zeros in every pass
  • 3.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 3  Formal Description  Q = {p1, p2, p3, p4, p5, paccept, preject},  • Σ = {0}, and  • Γ = {0,x,␣}.  • We describe δ with a state diagram (see Figure 3.8).  • The start, accept, and reject states are p1, paccept, and preject, respectively.
  • 4.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 4 ␣  R x  R
  • 5.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 5 0  ␣, R ␣  R x  R ␣  R
  • 6.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 6 0  ␣, R x  R 0  x, R ␣  R x  R ␣  R ␣  L ␣  R x  L
  • 7.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 7 0  ␣, R x  R ␣  R x  R 0  x, R ␣  R x  R 0  R ␣  R ␣  L ␣  R x  L
  • 8.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 8 0  ␣, R x  R 0  x, R ␣  R x  R 0  x, R x  R ␣  R x  R 0  R ␣  R ␣  L ␣  R 0  L x  L
  • 9.
    Turing Machine (02 n ) EECS2001 Introduction to Theory of Computation 9  Walk through with string 0000 1: 0000␣ 2: ␣000␣ 3: ␣x00␣ 4: ␣x00␣ 3: ␣x0x␣ 5: ␣x0x␣ 5: ␣x0x␣ 5: ␣x0x␣ 5: ␣x0x␣ 2: ␣x0x␣ 2: ␣x0x␣ 3: ␣xxx␣ 3: ␣xxx␣ 5: ␣xxx␣ 3: ␣xxx␣ 3: ␣xxx␣ 3: ␣xxx␣ 2: ␣xxx␣ 2: ␣xxx␣ 2: ␣xxx␣ 2: ␣xxx␣ accept:
  • 10.
    Turing Machine (C= {aibjck| i × j = k and i, j, k ≥ 1}.) EECS 2001 Introduction to Theory of Computation 10 M3 = “On input string w:  1. Scan the input from left to right to determine whether it is a member of a+b+c+ and reject if it isn’t.  2. Return the head to the left-hand end of the tape.  3. Cross off an a and scan to the right until a b occurs. Shuttle between the b’s and the c’s, crossing off one of each until all b’s are gone. If all c’s have been crossed off and some b’s remain, reject .  4. Restore the crossed off b’s and repeat step 3 if there is another a to cross off. If all a’s have been crossed off, determine whether all c’s also have been crossed off. If yes, accept; otherwise, reject .”
  • 11.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 11  Construct a TM to accept palindromes using one tape  Start reading, if an a/b is encountered, cross it, move to the end and read the last symbol: (1) if the first and last match, cross the last, move to the beginning: (2) if the last symbol is end of input, accept.  Repeat step 1 until there are no symbols left. Accept.  If at any point the first and last do not match, reject.  Question: is the empty string accepted?  Will the above machine work for a single character string?
  • 12.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 12  Construct a TM to accept palindromes using one tape  States  q0 : start state; tape head is on the leftmost symbol  qa : leftmost symbol was a; crossed it, tape head is moving to the right  qb : leftmost symbol was b; crossed it, tape head is moving to the right  q′a : reached rightmost symbol; test whether it is equal to a, and delete it  q′b : reached rightmost symbol; test whether it is equal to b, and delete it  qL : test was positive; tape head is moving to the left  qaccept : accept state  qreject : reject state
  • 13.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 13  Construct a TM to accept palindromes using one tape  Transitions  q0 , a → qa , ␣, R qa, a → qa, a, R  qb, a → qb, a, R q0, b → qb, ␣, R  qa, b → qa, b, R qb, b → qb, b, R  q0 , ␣ → qaccept qa, ␣ → q′a, ␣, L  qb , ␣ → q′b, ␣, L q′a, a → qL, ␣, L  q′b, a → qreject qL, a → qL, a, L  q′a , b → qreject q′b, b → qL, ␣, L  qL, b → qL, b, L q′a, ␣ → qaccept  q′b , ␣ → qaccept qL, ␣ → q0, ␣, R
  • 14.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 14  Construct a TM to accept the language {albman | m = l + n; l, m, n are natural numbers)  If the first letter is a, cross it, move right to find a b, cross it, come back (left) to the start of the tape  Repeat the first step till all a’s before the b’s are crossed out  Move to the first of the remaining b’s, read the first one, cross it, move right till you find an a, cross it, move back left to the first of the remaining b’s  Repeat the third step until all the b’s and a’s have been crossed out. if any b’s or a’s are left, reject. Otherwise accept if a b occurs after the second set of a’s, reject
  • 15.
    Turing Machine EECS 2001Introduction to Theory of Computation 15  TM M4 is solving what is called the element distinctness problem. It is given a list of strings over {0,1} separated by #s and its job is to accept if all the strings are different. The language is E = {#x1#x2# · · · #xl| each xi ∈ {0,1}∗ and xi ≠ xj for each i ≠ j}.  Machine M4 works by comparing x1 with x2 through xl, then by comparing x2 with x3 through xl, and so on. An informal description of the TM M4 deciding this language follows.  M4 = “On input w:  1. Place a mark on top of the leftmost tape symbol. If that symbol was a blank, accept. If that symbol was a #, continue with the next step. Otherwise, reject.  2. Scan right to the next # and place a second mark on top of it. If no # is encountered before a blank symbol, only x1 was present, so accept.  3. By zig-zagging, compare the two strings to the right of the marked #s. If they are equal, reject.  4. Move the rightmost of the two marks to the next # symbol to the right. If no # symbol is encountered before a blank symbol, move the leftmost mark to the next # to its right and the rightmost mark to the # after that. This time, if no # is available for the rightmost mark, all the strings have been compared, so accept .  5. Go to step 3.”
  • 16.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 16  Construct a TM to accept the language of all words w such that each w has at least one more b than a  ababb
  • 17.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 17  Construct a TM to accept the language of all words w such that each w has at least one more b than a  Start reading, if an a/b is encountered, cross it, move forward till you find the opposite a/b, cross that too (if you cannot find a b and reach the end of tape, reject), move to the beginning of the tape  Repeat Step 1 until you cannot find any a. If you still find a b (uncrossed), accept. If you cannot find a b after crossing out all a’s, reject.  Note: sequence of a’s and b’s do not matter in this particular problem
  • 18.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 18  Construct a TM to accept palindromes using two tapes  Tape 1 has original input  Tape 2 has original input  Read first symbol of Tape 1 and last symbol of Tape 2, compare, if both are equal, move Tape 1 head right and Tape 2 head left.  Repeat till Tape 1 head reaches end and Tape 2 head reaches start
  • 19.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 19  Construct a TM to accept palindromes using two tapes  Tape 1 has original input  Tape 2 has original input  Read first symbol of Tape 1 and last symbol of Tape 2, compare, if both are equal, move Tape 1 head right and Tape 2 head left.  Repeat till Tape 1 head reaches end and Tape 2 head reaches start  NOTE: we are not crossing out the already read input symbols as we did in the single tape TM
  • 20.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 20  Construct a TM to accept anbncn using one tape (n≥0)  Tape alphabet = a, b, c, x, ␣  Step 1: check the sequence, read all the tape without altering, check whether all a’s come before all b’s and all b’s come before all c’s. If not reject.  Step 2: Read the left most a, cross it, read the leftmost b, cross it, read the left most c, cross it. Move to the leftmost a. Repeat.  Step 3: If any one symbol is not found but others are, reject.  aaabbbbccc
  • 21.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 21  Construct a TM to accept anbncn using one tape (n>=0) without crossing it (remember crossing uses an extra symbol x)  Tape alphabet = a, b, c, ␣  Step 1: check the sequence, read all the tape without altering, check whether all a’s come before all b’s and all b’s come before all c’s. If not reject.  Step 2: Read the left most a, read the leftmost b, overwrite the rightmost a with the leftmost b, read the left most c, overwrite 2 rightmost b’s with c’s, move to the end, overwrite three right most c’s with the end of input symbol. (in one step we have essentially deleted one a, one b, one c, in total 3 symbols).  Step 3: If any one symbol is not found but others are, reject.  aaabbbcc – aabbbbcc- aabbcccc-aabbc___- abbbc_- abccc_ - ab___- bb- cc
  • 22.
    Turing Machine Examples EECS2001 Introduction to Theory of Computation 22  For practice  Construct a TM to accept all strings over {a, b, c} such that the number of a = to number of b = number of c (sequence does not matter)
  • 23.
    Turing Machine (02 n )0 00 0000 EECS 2001 Introduction to Theory of Computation 23 0  ␣, R x  R 0  x, R ␣  R x  R 0  x, R x  R ␣  R x  R 0  R ␣  R ␣  L ␣  R 0  L x  L
  • 24.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 24 Q what would be the sequence of configurations of the preceding TM when 00 is given as the input string? Configuration : Current state, current location of the head, and current contents of the tape p1 00, ␣ p2 0, ␣ x p3 ␣, ␣ p5 x ␣, p5 ␣ x ␣, ␣ p2 x ␣, ␣ x p2 ␣, ␣ x ␣ paccept (The head has moved right – beyond the input but it does not matter as we are in the accept state)
  • 25.
    Turing Machine (w#w) EECS2001 Introduction to Theory of Computation 25 1  x, R x  L 0  x, R 0  x, L 0,1  R x  R #  R 0,1  R #  R x  R #  R 1  x, L #  L 0,1  L ␣  R x  R x  R
  • 26.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 26 Q what would be the sequence of configurations of the preceding TM when 11 is given as the input string? Configuration : Current state, current location of the head, and current contents of the tape
  • 27.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 27 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. a. Can a Turing machine ever write the blank symbol ␣ on its tape?
  • 28.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 28 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. a. Can a Turing machine ever write the blank symbol ␣ on its tape? Yes, it is part of the tape alphabet. This can be written to signal the start of the tape as well as the end of input (not the ned of tape).
  • 29.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 29 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. b. Can the tape alphabet Γ be the same as the input alphabet Σ?
  • 30.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 30 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. b. Can the tape alphabet Γ be the same as the input alphabet Σ? No, we could force it to be equal however the resulting TM will not work as we will be using the blank symbol in the input as well as the end of input.
  • 31.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 31 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. c. Can a Turing Machine’s head ever be in the same location in two successive steps?
  • 32.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 32 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. c. Can a Turing Machine’s head ever be in the same location in successive steps? Yes, according to the definition of the TM, if we are at the left most place on the tape, and we attempt to move left, the TM stays on the same place. (there is no left to the left most)
  • 33.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 33 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. d. Can a Turing Machine contain just a single state?
  • 34.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 34 Q 3.5 of Sipser Book: Examine the formal definition of a Turing machine to answer the following questions, and explain your reasoning. d. Can a Turing Machine contain just a single state? Note we are not talking about the places in the tape, but the actual TM (which looks like a state machine). No, according to the definition, accept state must be different from the reject state.
  • 35.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 35  Q Give implementation-level descriptions of Turing machine that decide the following language over the alphabet {0,1}.  {w| w contains an equal number of 0s and 1s}
  • 36.
    Turing Machine Questions EECS2001 Introduction to Theory of Computation 36  Q Give implementation-level descriptions of Turing machine that decide the following language over the alphabet {0,1}.  {w| w contains an equal number of 0s and 1s}  1. Scan the tape and mark the first 0 that has not been marked. If no unmarked 0 is found, go to Step 4. Otherwise, move the head back to the front of the tape and move to step 2.  2. Scan the tape and mark the first 1 that has not been marked. Go to Step 3. If no unmarked 1 is found, reject .  3. Move the head back to the front of the tape and go to Step 1.  4. Move the head back to the front of the tape. Scan the tape to see if any unmarked 1s remain. If none are found, accept; otherwise, reject .
  • 37.
    References EECS 2001 Introductionto Theory of Computation 37 Ideas, problems and their solutions in this lecture/tutorial have been taken from • Prof. Jeffery Edmonds’ Lecture notes for EECS 2001 at York University • Prof. Suprakash Datta’ Lecture notes for EECS 2001 at York University • Introduction to the Theory of Computation (3rd edition) by Michael Sipser • Introduction to Theory of Computation by Anil Maheshwari and Michiel Smid • Wikipedia and other webpages of different professors/universities