Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Algorithms and Theory of Computing About Turing Machine, Exercises of Algorithms and Programming

Turing Machine Excercises With Solutions From Nanyang Technological University.

Typology: Exercises

2021/2022

Uploaded on 02/11/2022

gwen
gwen 🇺🇸

5

(8)

285 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Xiaohui Bei
Algorithms and Theory of Computing
MAS714 2021
Exercises on Turing Machines
Exercise 1:
Simulate the Lecture 17 Example 1 TM that accepts language L={anbncn|n1}on input
“aaabbbccc”. List the state and the tape content of every step of the run.
Solution: Skipped.
Exercise 2:
Describe what are the languages accepted by the following Turing machines.
Note: in figures below, means the blank symbol.
(a).
q0q1q2q3
start / , R
0/0, R
1/1, R 0/0, R
(b).
q0q1q2q3
start / , R
b/b, R
a/a, R a/a, R
b/b, R
Solution:
(a). L(M)=010(1 + 0)
(b). L(M)=(a+b)aa(a+b)
pf3
pf4
pf5

Partial preview of the text

Download Algorithms and Theory of Computing About Turing Machine and more Exercises Algorithms and Programming in PDF only on Docsity!

Xiaohui Bei

Algorithms and Theory of Computing

MAS714 2021

Exercises on Turing Machines

Exercise 1: Simulate the Lecture 17 Example 1 TM that accepts language L = {anbncn^ | n ≥ 1 } on input “aaabbbccc”. List the state and the tape content of every step of the run.

Solution: Skipped.

Exercise 2: Describe what are the languages accepted by the following Turing machines. Note: in figures below, “ ” means the blank symbol.

(a).

start q 0 q 1 q 2 q 3

/ , R

0 / 0 , R

1 / 1 , R 0 / 0 , R

(b).

start q 0 q 1 q 2 q 3

/ , R

b/b, R

a/a, R a/a, R

b/b, R

Solution:

(a). L(M ) = 0∗10(1 + 0)∗

(b). L(M ) = (a + b)∗aa(a + b)∗

As discussed in class, a common operation in Turing-machine programs involves “shifting over”. We need to move the contents of each of the cells to the right of the current head position one cell right, and then find our way back to the current head position. Give the high level description of how to perform this operation.

Solution: On input string w:

(a). We maintain a set of states corresponding to the symbol we just read.

(b). Mark the first symbol with a $ (assume $ ∈/ Σ) and go on to the state corresponding to that symbol read.

(c). Move the head toward right till the end of the string (till you hit ) while replacing the current symbol with the previous symbol (this information is contained in the state the you are currently in), shifting to the state corresponding to the symbol just read.

(d). After hitting the at the end of the input, replace the with the last symbol and start going left back to the start position.

(e). Clear the symbol and move right one position to place the head right on top of the first symbol of the shifted string.

(f). Move one position backwards without doing anything to the tape to place the head right on top of the original start position, accept.

(g). For any situation not described above, reject.

Say that a write-once Turing machine is a single-tape TM that can alter each tape cell at most once (including the input portion of the tape). Show that this variant Turing machine model is equivalent to the ordinary Turing machine model. (Hint: As a first step, consider the case whereby the Turing machine may alter each tape cell at most twice. Use lots of tape.)

Solution: We first simulate an ordinary Turing machine by a write-twice Turing machine. The write-twice machine simulates a single step of the original machine by copying the entire tape over to a fresh portion of the tape to the right-hand side of the currently used portion. The copying procedure operates character by character, marking a character as it is copied. This procedure alters each tape cell twice, once to write the character for the first time and again to mark that it has been copied. The position of the original Turing machine’s tape head is marked on the tape. When copying the cells at, or adjacent to, the marked position, the tape contents is updated according to the rules of the original Turing machine. To carry out the simulation with a write-once machine, operate as before, except that each cell of the previous tape is now represented by two cells. The first of these contains the original machine’s tape symbol and the second is for the mark used in the copying procedure. The input is not presented to the machine in the format with two cells per symbol, so the very first time the tape is copied, the copying marks are put directly over the input symbols.

(a). Show that the set of decidable languages is closed under the union operation.

(b). Show that the set of recursively enumerable languages is closed under the union oper- ation.

Solution:

(a). For any two decidable languages L 1 and L 2 , let M 1 and M 2 be the TMs that decide them. We construct a TM M ′^ that decides the union of L 1 and L 2 : On input w:

(a) Run M 1 on w. If it accepts, accept. (b) Run M 2 on w. If it accepts, accept. Otherwise, reject.

It is easy to check that M ′^ accepts w if either M 1 or M 2 accepts it. If both reject, M ′ rejects.

(b). For any two r.e. languages L 1 and L 2 , let M 1 and M 2 be the TMs that recognize them. We construct a TM M ′^ that recognizes the union of L 1 and L 2 : On input w:

(a) Run M 1 and M 2 alternatively on w step by step. If either accept, accept. If both halt and reject, reject.

If either M 1 or M 2 accepts w, M ′^ accepts w because the accepting TM arrives to its accepting state after a finite number of steps. Note that if both M 1 and M 2 reject and either of them does so by looping, then M ′^ will loop. By definition this means M ′ rejects w.