CMPS 260 Spring 2019
Homework #7: CFL's and Turing Machines
Due: 5pm, May 10

1. Give an example of a context-free language whose complement is not context-free. Justify your claim.


2. Argue persuasively that there is an algorithm by which to determine, given a context-free grammar G and a positive integer n, whether L(G) contains any strings of length less than n.

Hint: One way to solve the problem makes use of Linz's Theorem 8.5.


3. Present a Turing machine that computes the function f(x) = x mod 5, where the input and output are to be encoded using unary notation.

For example, if, initially, the tape has 27 1's on it (representing the integer 27), the machine should halt with there being two 1's on the tape (because 27 mod 5 = 2).

Provide a short narrative to explain, at a high level of abstraction, how your machine works.


4. Present a Turing machine that computes the function f(w) = ambn, where na(w) = m and nb(w) = n. In other words, given a string of a's and b's, it sorts them into alphabetical order.

Provide a short narrative to explain, at a high level of abstraction, how your machine works.


5. Each move of a Turing machine results in the current tape symbol being overwritten and the read-write head sliding one tape cell to the left or to the right.

Suppose that we define a Restricted Turing machine to be one in which each move results in only one of those two actions taking place (i.e., either the current tape symbol is overwritten or the read-write head slides over one place, but not both). The transition function δ of such a machine would have signature δ: Q × Γ → Q × (Γ ∪ {L,R}) (with the assumption that Γ ∩ {L,R} = ∅) with these interpretations:

Show that the computation of any "standard" Turing machine can be simulated by a Restricted Turing machine. To do that, describe, for each transition δ(p,a) = (q,b,R) (respectively, (q,b,L)) in the standard TM, what transition(s) would be included in the RTM for the purpose of simulating it.


6. (Bonus Problem) Prove the following generalized version of the Pumping Lemma for Regular Languages:

If L is a regular language, there exists m>0 such that, if uvw ∈ L and |v| ≥ m, there exist strings x, y, and z satisfying these conditions:
  1. v = xyz
  2. |xy| ≤ m
  3. |y| > 0
  4. for all i≥0, uviw ∈ L, where vi = xyiz