Docsity

6 Problems on Computability and Algorithms with Proof | CS 6505, Assignments of Computer Science

Toggle sidebar
bg1
CS 6505: Algorithms, Computability and
Complexity
Problem Set 1
Solutions
Problem 1
1. Show that decidable languages are closed under union and intersection,
that is, if Aand Bare decidable languages, then so are A∪Band
A∩B.
Proof: Let MAand MBbe the TM that decide Aand Brespectively.
Then we can construct a TM MA∪Bthat decides A∪Bas follows:
on input x,MA∪Bruns each of MA(x) and MB(x). MA∪B(x) then
accepts if and only one (or both) of MA(x) or MB(x) accepts. A
similar technique is used to decide A∩B. We build a machine MA∩B
that on input xruns MA(x) and MB(x), and accepts if and only if
both MAand MBaccept. Since MAand MBare deciders, they will
always halt, and so both MA∪Band MA∩Bare deciders.
2. Are Turing-recognizable languages closed under union and intersec-
tion? Justify your answer.
Proof: Recognizable languages are indeed closed under unions and
intersection. Let NAand NBbe recognizers of Aand Brespectively.
Then a similar trick as in part 1 can be used. In fact NA∩Bcan be
constructed in the same way as MA∩Bwas above. If x∈A∩Bthen
we know that both NA(x) and NB(x) halt, and so NA∩B(x) will halt
and A∩Bis recognizable. However, more care must be taken to show
that A∪Bis recognizable. The issue here is that if we run NA(x)
first, and then run NB(x) after NA(x) finishes, then it is possible that
x6∈ A, but x∈B, and so NA(x) may never halt. Thus we have a
situation where x∈A∪B, but constructing NA∪Bnaively like this,
NA∪B(x)doesn’t halt. The solution is to run NA(x) and NB(x) in
parallel, that is run one step of NAthen one step of NB, and if at any
point one of NA(x) or NB(x) accepts, then NA∩B(x) accepts.
1
pf3
pf4
pf5

Partial preview of the text

Download 6 Problems on Computability and Algorithms with Proof | CS 6505 and more Assignments Computer Science in PDF only on Docsity!

CS 6505: Algorithms, Computability and

Complexity

Problem Set 1

Solutions

Problem 1

  1. Show that decidable languages are closed under union and intersection, that is, if A and B are decidable languages, then so are A ∪ B and A ∩ B. Proof: Let MA and MB be the TM that decide A and B respectively. Then we can construct a TM MA∪B that decides A ∪ B as follows: on input x, MA∪B runs each of MA(x) and MB (x). MA∪B (x) then accepts if and only one (or both) of MA(x) or MB (x) accepts. A similar technique is used to decide A ∩ B. We build a machine MA∩B that on input x runs MA(x) and MB (x), and accepts if and only if both MA and MB accept. Since MA and MB are deciders, they will always halt, and so both MA∪B and MA∩B are deciders.
  2. Are Turing-recognizable languages closed under union and intersec- tion? Justify your answer. Proof: Recognizable languages are indeed closed under unions and intersection. Let NA and NB be recognizers of A and B respectively. Then a similar trick as in part 1 can be used. In fact NA∩B can be constructed in the same way as MA∩B was above. If x ∈ A ∩ B then we know that both NA(x) and NB (x) halt, and so NA∩B (x) will halt and A ∩ B is recognizable. However, more care must be taken to show that A ∪ B is recognizable. The issue here is that if we run NA(x) first, and then run NB (x) after NA(x) finishes, then it is possible that x 6 ∈ A, but x ∈ B, and so NA(x) may never halt. Thus we have a situation where x ∈ A ∪ B, but constructing NA∪B naively like this, NA∪B (x)doesn’t halt. The solution is to run NA(x) and NB (x) in parallel, that is run one step of NA then one step of NB , and if at any point one of NA(x) or NB (x) accepts, then NA∩B (x) accepts.

Let f (x) = a 0 + a 1 x + · · · + anxn, an 6 = 0, be a univariate polynomial with integer coefficients. Let amax = max 0 ≤i≤n {|ai|} be the largest absolute values of all coefficients ai’s. Suppose that f (α) = 0 and |α| ≥ 1. Show that

|α| ≤ n · amax |an|

Based on this fact, give an algorithm that decides whether any given uni- variate polynomial with integer coefficients has an integer root.

Proof: Suppose f (α) = 0. Then we have

f (α) = 0 = a 0 + a 1 α + a 2 α^2 +... + anαn

=

a 0 an

a 1 an

α +

a 2 an

α^2 +... +

an− 1 an

αn−^1 + αn

αn^ = −

[(

a 0 an

a 1 an

α +

a 2 an

α^2 +... +

an− 1 an

αn−^1

]

a = −

[(

a 0 an

α−(n−1)^ +

a 1 an

α−(n−2)^ +

a 2 an

α−(n−3)^ +... +

an− 1 an

)]

|a| =

a 0 an

α−(n−1)^ +

a 1 an

α−(n−2)^ +

a 2 an

α−(n−3)^ +... +

an− 1 an

|a 0 | |an|

∣∣α−(n−1)

∣∣ + |a 1 | |an|

∣∣α−(n−2)

∣∣ + |a 2 | |an|

∣∣α−(n−3)

∣∣ +... + |an− 1 | |an|

≤

|a 0 | |an|

|a 1 | |an|

|a 2 | |an|

|an− 1 | |an| ≤ amax |an|

amax |an|

amax |an|

amax |an| = n · amax |an| The above fact leads to a simple algorithm for deciding whether or not the univariate polynomial f (x) = a 0 +a 1 x+· · · +anxn^ has any integer roots. First find amax by examining the absolute value of each coefficient. Then for each α in the range −n · a |maxan| ≤ α ≤ n · a |maxan| , test if f (α) = 0. Since we know all zeros of f lie in this range, if there is one, we will find it, and furthermore, we can guarantee that if we do not find a zero, then there are no integer roots.

Note: Although this algorithm is guaranteed to terminate, it does not necessarily run in polyomial-time. Do you see why?

A state of a Turing machine is said to be useless if it is never entered on any input string. Prove that the language

{〈M 〉 : M is a TM that has a useless state}

is undecidable.

Proof: Let L = {〈M 〉 : M is a TM that has a useless state}. We show that AT M reduces to L. Suppose that T is a Turing-Machine that decides L. We will construct a Turing-Machine D that decides AT M.

D(< M, w >):

  1. Construct a Turing-Machine NM,w which has some non-trivial set of states Q which are different from the states of M , and that does the following: NM,w(x):

(a) run M on w. (b) if M accepts w, then cycle through all states of Q

  1. Run T (< NM,w >).
  2. If T (< NM,w >) accepts, then reject.
  3. Otherwise, accept.

To see that D decides AT M observe if M accepts w then by construction NM,w will not have any useless states. Furthermore, if M does not accept w, then since we assume that the number of states of NM,w is some non- trivial superset of those of M , then NM,w must have some useless state. We conclude that NM,w does not have a useless state if and only if M accepts w. Thus D decides AT M , a contradiction. It follows that L is undecidable.

For a language L, an enumerator for L is an algorithm that outputs a se- quence w 1 , w 2 ,... , wi,... of strings in Σ∗, such that wi ∈ L for each i ∈ N, and each w ∈ L eventually appears in the sequence (that is, for each w ∈ L, there is some i ∈ N such that w = wi). It is well known that a language is Turing-recognizable if and only if it has an enumerator. (For this reason a Turing-recognizable language is said to be recursively enumerable.)

  1. Read Section 3.2 of Sipser’s textbook for the equivalence between rec- ognizability and enumerability. There is nothing to hand in for this part.
  2. Prove that a language L is decidable if and only if there is an enu- merator that enumerates L in a lexicographic order (for instance, if Σ = { 0 , 1 }, then a lexicographic order of Σ∗^ is ε, 0, 1, 00, 01, 10, 11, 000, 001, ...).

Proof: (⇒) Let L be a decidable language and M a decider of L. Then the following Turing machine E enumerates L in the lexicographic order:

For each w ∈ Σ∗^ in the lexicographic order:

  1. Run M (w).
  2. If M (w) = 1, output w.

Clearly E is an enumerator of L that outputs each member of L in the lexicographic order.

(⇐) Conversely, let E be an enumerator of L that outputs elements of L in the lexicographic order L = {w 1 , w 2 , w 3 ,.. .}. Then the following Turing machine M decides L:

On input x ∈ Σ∗: For i = 1, 2 , 3 ,.. .:

  1. Run the enumerator E to output wi.
  2. If x = wi, then halt and output 1 (i.e. accept x).
  3. If x < wi, then halt and output 0 (i.e. reject x).