0% found this document useful (0 votes)
74 views

Exercise Sheet 6: Theoretical Computer Science (Bridging Course)

This document contains an exercise sheet for a theoretical computer science course. It includes 4 exercises on topics like Turing machines, pushdown automata, and non-deterministic Turing machines. The exercises ask students to design Turing machines for certain languages, describe how to simulate a pushdown automaton with a Turing machine, and explain how to recognize composite numbers encoded in unary with a non-deterministic Turing machine. Sample solutions are provided for each exercise.

Uploaded by

madhav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Exercise Sheet 6: Theoretical Computer Science (Bridging Course)

This document contains an exercise sheet for a theoretical computer science course. It includes 4 exercises on topics like Turing machines, pushdown automata, and non-deterministic Turing machines. The exercises ask students to design Turing machines for certain languages, describe how to simulate a pushdown automaton with a Turing machine, and explain how to recognize composite numbers encoded in unary with a non-deterministic Turing machine. Sample solutions are provided for each exercise.

Uploaded by

madhav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Theoretical Computer Science (Bridging Course)

Dr. G. D. Tipaldi University of Freiburg


F. Boniardi Department of Computer Science
Winter semester 2014/2015

Exercise Sheet 6
Due: 11th December 2014

Exercise 6.1 (Turing Machines)


(a) Design a Turing Machine that decides the language L := {0n 1n | n ≥ 1}. Explain your
choice.
Solution: Alternately, the TM will change a 0 to an X and then a 1 to a Y until all 00 s and
10 s have been matched.
In more detail, starting at the left end of the input, the TM enters a loop in which it changes
a 0 to a X and moves to the right over whatever 00 s and Y 0 s it sees, until it comes to a 1. It
changes the 1 to a Y and moves left, over Y 0 s and 00 s, until it finds an X. At that point, it
looks for a 0 immediately to the right, and if it finds one, changes it to X and repeats this
process, changing a matching 1 to a Y .
The formal specification is M = (Q, Σ, Γ, q0 , qreject , qaccept ), where:
• Q := {q0 , q1 , q2 , q3 , qr , qa }.
• Σ = {0, 1}.
• Γ = {0, 1, X, Y, t}
• The transition function δ is given by
Q×Γ 0 1 X Y t
q0 (q1 , X, R) (qr , 1, R) (qr , X, R) (q3 , Y, R) (qr , t, R)
q1 (q1 , 0, R) (q2 , Y, L) (qr , X, R) (q1 , Y, R) (qr , t, R)
q2 (q2 , 0, L) (qr , 1, R) (q0 , X, R) (q2 , Y, L) (qr , t, R)
q3 (qr , 0, R) (qr , 1, R) (qr , X, R) (q3 , Y, R) (qa , t, R)
qr - - - - -
qa - - - - -
• qreject := qr .
• qaccept := qa .
(b) Give the sequence of configurations for the input string 0011.
Solution:
q0 0011 Xq1 011 X0q1 11
Xq2 0Y 1 q2 X0Y 1 Xq0 0Y 1
XXq1 Y 1 XXY q1 1 XXq2 Y Y
Xq2 XY Y XXq0 Y Y XXY q3 Y
XXY Y q3 t XXY Y t qa t

(c) Give the sequence of configurations for the input string 0010.
Solution:
q0 0010 Xq1 010 X0q1 10
Xq2 0Y 0 q2 X0Y 0 Xq0 0Y 0
XXq1 Y 0 XXY q1 0 XXY 0q1 t
XXY 0 t qr t
Exercise 6.2 (Turing Machines)
Describe a TM that decides the language

L = {w ∈ {0, 1}∗ | |w|0 = |w|1 } .

where |w|0 and |w|1 are respectively the number of 0’s and 1’s in w.

Solution: We call M such Turing Machine. M = (Q, Σ, Γ, δ, q0 , qaccept , qreject ) can be the fol-
lowing:

• Q := {q0 , q1 , q2 , q3 , qa , qr }.
• Σ := {0, 1}.
• Γ := {0, 1, X, t}.

• qaccept := qa .
• qreject := qr .
• The transition function δ is given by

State 0 1 t X Y
q0 (q2 , X, R) (q1 , X, R) (qa , t, R) (qr , X, R) (q0 , Y, R)
q1 (q3 , Y, L) (q1 , 1, R) (qr , t, R) (qr , X, R) (q1 , Y, R)
q2 (q2 , 0, R) (q3 , Y, L) (qr , t, R) (qr , X, R) (q2 , Y, R)
q3 (q3 , 0, L) (q3 , 1, L) (qr , t, R) (q0 , X, R) (q3 , Y, L)
qr - - - - -
qa - - - - -

The state diagram of M is reported below.

qr
X →R

t→R t→R
X →R X →R
Y →R
0 → X, R

1 → X, R 0→R
q0 q1 t→R q2 Y →R

1→R
t→R Y →R 1 → Y, R
0 → Y, L

X →L 0→L
qa q3 1→L
Y →L

Exercise 6.3 (Pushdown Automata, Turing Machines)


How would one simulate a PDA on a Turing machine? Please do not write the Turing machine
itself, but rather write the key idea in plain English.
Solution: We show how a PDA can be simulated by a non-deterministic two-tape TM. This
would in a second step be transformed into a normal (deterministic, one-tape) TM using the
transformations shown in the lecture.
We use the second tape of the TM to represent the stack of the PDA, whereas the first tape is
only used to read the input of the PDA. The states of the TM basically represent the states of the
PDA. In addition, we need some auxiliary states (see below). The TM works as follows: Whenever
the PDA would read a symbol, the TM must read the symbol under the head on the first tape
and moves the head one step to the right. Whenever the PDA uses the empty symbol as input
symbol, the head on the first tape keeps its position. At the same time, the TM performs the
appropriate action on the second tape in such a way the the head is always positioned on the
“top-most” symbol:
• If the PDA consumes a symbol from the stack but does not write a new one, the TM deletes
the symbol under the head and moves the head one position to the left.
• If the PDA consumes a symbol from the stack and writes a new one, the TM overwrites the
symbol below the head with the new one.
• If the PDA does not consume a symbol from the stack but writes a new one, the TM moves
one step to the right and writes the new symbol. For this we actually need to perform two
steps which can be done using some auxiliary states (we need to remember the symbol to
write and the current state of the TM).
• If the PDA does not change the stack, the TM does not change the second tape.
This TM accepts the input of the PDA iff it stops in an accept state (if there are several accepting
states in the PDA, we use an additional transition that brings the TM from these states to its
single accept state).

Exercise 6.4 (Non Deterministic Turing Machines)


We call a natural number composite if it is not prime1 , formally, the set of natural composite
numbers is
{hk | h, k ∈ N, h, k ≥ 2}
Give a nondeterministic Turing machine of the alphabet of vertical bars Σ = {|} that recognizes
the language of composite numbers encoded as unary numbers (i.e. a natural number n is encoded
in the form |n ). You should not give a formal construction, but describe the idea behind it as
precise as possible.

Solution: Using a nondeterministic Turing machine “recognizing” composite numbers is not that
hard. We can use the non-determinism to guess. The following is the idea behind the construction
of a non-deterministic Turing Machine τ that recognizes composite numbers in unary form, i.e.,
|n for some n ∈ N.

1. Nondeterministically choose two numbers p and q, such that p ≥ 1, q ≥ 1 and transform the
input in the form t|n t |q t |q t
2. Multiply p by q to obtain t|n t |pq t
3. Check the numbers of | before the middle t and then accept if this number is equal, and
reject otherwise.

Since the Turing Machine is non-deterministic, we are sure on the step 2 of the algorithm, the given
number n will be tested against all its potential factors and hence we will know with probability
1 whether the number is composite or not.

1 Remember that 1 and −1 are not prime numbers! By definition, prime numbers must not be invertible in Z.

You might also like