Practice Final Exam
## Practice Final Exam

### Prof. Carolina Ruiz

CS4123 Theory of Computation. B97

#### Department of Computer Science

Worcester Polytechnic Institute

### 1. (20 Points) Turing Machines

Construct the state diagram with transitions of a deterministic
Turing machine that given an input number n in binary
representation halts with just the binary representation of n+1
on its tape.

### 2. (20 Points) Recursive Functions

Show that the following integer approximation of the log function
is PRIMITIVE recursive.

log(m,n) := "logarithm in base m of n"
= "the least k for which m^k >= n"

m^k denotes m to the k-th power.
You can assume that m >= 2 and n > 0.

**Hint:s** Use bounded minimization.

### 3. (20 Points) Decidability

Let Sigma = {0,1}.
Show that the problem of testing whether a CFG generates some string in 1*
is decidable. In other words,

show that
ONESTARcfg = {< G > | G is a CFG and (1* INTERSECTION L(G)) <> empty}
is decidable.

**Hint:s** Do not make the mistake of assuming that the intersection of CFLs
is context free.

### 4. (20 Points) Undecidability

Solve either one of the following problems:

- Show that CONTEXTFREEtm = {< M > | M is a TM and L(A) is context free}
is undecidable.

- Show that DECIDERtm = {< M > | M is a TM and M stops on all inputs}
is undecidable.

### 5. (20 Points) P, NP, and NP-completeness

Let G = (V,E) be an undirected graph.
A vertex cover for G is a is a subset V' of V such that for each
edge (a,b) in E either a belongs to V', or b belongs to V' (or both).

VERTEX-COVER = {< G,c > | G is undirected graph and G has a vertex cover of size c}.

Show that VERTEX-COVER is an NP-complete problem

** Hint:** Show that:

- VERTEX-COVER is in NP.
- Show that CLIQUE <=_P VERTEX-COVER using the following transformation:
< G,k> belongs to CLIQUE iff f(< G,k >) = < GC,c > belongs to VERTEX-COVER

where

- G = (V,E).
- GC = (V,EC),

EC = {(a,b) | a and b belong to V but edge (a,b) does NOT belong to E}.
- c = |V| - k.

(Don't forget to show that the function f can be computed by a
deterministic TM in polynomial time.)