Exercise Sheet 6: Theoretical Computer Science (Bridging Course)
Exercise Sheet 6: Theoretical Computer Science (Bridging Course)
Exercise Sheet 6
Due: 11th December 2014
(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
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 - - - - -
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
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.