Homework 2

15-212 Java, Spring 1998

January 28, 1998
Instructors: Mosur and Tygar


This assignment is due at start of your section on February 4. Please read the class policies for collaboration, cheating, and late assignments. Be extremely neat and concise in writing up your answers; answers that are not clear to the grader, are difficult to read or understand, or are too long, will receive no credit. In your write-up, please use the actual Greek letters and math symbols rather than spelling them out in English as done below. We did that only because HTML currently doesn't support math symbols.

IMPORTANT: Note that this assignment is in three parts: I, II, and III. You must hand in each part separately, so do each part on separate pieces of paper. Put your name, your section, and the part number at the top of the first page of each part. Be sure that the pages for each part are held together (stapling preferred). Basically, think of this as three short, separate problem sets. Points will be deducted if you do not follow these directions.

Part I

1. Pumping Theorem. Do L&P problem 2.4.5 .

2. Arithmetic with finite automata. Let SIGMA = { 0,1,2,3,4,5,6,7,8,9 }. Let L be a language over SIGMA, L = { x : the number with decimal notation x is divisible by 3, and x contains no two consecutive identical digits }. For example, 12 is in L, because 12 is divisible by 3. But 99 is not in L, because even though 99 is divisible by 3, it contains two consecutive identical digits. Show that L is regular. (Hint: a number is divisible by three if and only if the sum of its digits is divisible by three.)

Part II

1. CFG warm-up. Write a CFG for:

a) { ambn : m does not equal n }
b) { ambn : m < n < 2m }
c) { w is a string in {a,b}* : each prefix of w has at least as many a's as b's }

2. Ambiguity and parsing. Do L&P problem 3.2.2 . Also, choose a string in the language that has multiple derivations and draw at least two of the possible parse trees for it.

Part III

1. Flipping for a PDA. Construct a pushdown automaton that accepts the language { w is a string in {a,b}* : w = wR }, where wR is the reverse of the string w (i.e., w spelled backwards).

2. Flipping for a Turing machine. Diagram a Turing machine that computes f(w) = wR over SIGMA = {a,b}. (Hint: use R and L as defined in 4.1; it'll vastly reduce the amount of writing you'll have to do.)