CS 44 Exam #2 February 14, 2001 Name Time Started: Time Finished: Each question is equally weighted. You may omit two questions, but you must answer #8, and you can only omit one of #6 or #7. Circle the questions you are omitting. (Do not just leave them blank.) Show your work and state your assumptions for partial credit consideration. Unless explicitly stated, there are NO intended errors and NO trick questions. If in doubt, ask! You have two hours to work. 1. Answer each of the following questions with a brief paragraph. [5 points each] (a) Why is the concept of a Turing Machine important? Mention the Church- Turing Hypothesis in your answer. (b) Prove that the following grammar is ambiguous: S 0 S0 1SS SS1 S1S (c) We proved that regular languages are closed under intersection by defining a procedure for constructing a machine to recognize the strings in both languages. Briefly explain what goes wrong when we try to combine two DPDAs in the same way to get a machine for the intersection of two DCFLs. (d) Suppose Turing Machine T moves its tape head right on every move. What can you say about L(T)? Explain your answer.
2. Give CFGs to generate the following languages, and show a derivation of the string x in each case. [10 points each] (a) L = {a i b j c k i = k or j = k}, x = aabcc (b) (00 + 11)*, x = 001111 3. (a) Construct a deterministic PDA for the following language. You must also give a brief, informal English description of how the machine works. [15 points] L = {a m ba m m 0} {a k ca 2k k 0}
(b) Give a convincing argument (not necessarily a formal proof) of the fact that the deterministic CFLs are a proper subset of the CFLs. [5 points] 4. Give precise algorithms for the following decision problems. If appropriate, explain how we know when we can stop the algorithm. (a) Given a regular expression r, is the language described by r empty? [5 points] (b) Given a CFL L and string x, is x L? (Do not give an answer involving PDAs.) [5 points] (c) Given regular languages L 1 and L 2, is L 1 a proper subset of L 2? [10 points]
5. Consider the following context-free grammar G: S S 1 $ S 1 S 1 A A a ab (a) Find an equivalent LL(1) grammar by factoring and eliminating left recursion. [8 points] (b) Construct a top-down parser for L(G). Show the transition table and any other necessary information. [8 points] (c) Trace the steps of the parser on the input string aba$, showing at each step the state, unread input and stack contents. Explain the important steps. You may stop once it is clear how the parsing process works. [4 points]
6. Consider the following CFG: S asa bsb a b (a) Describe the language that is generated by the CFG. [5 points] (b) Prove your answer. [15 points] 7. Recall from our class discussion that the language L = {a n b n c n n 0} is not context free. Draw a transition diagram for a Turing Machine accepting L. Do not use any TM subroutines.
8. (a) Draw a transition diagram for a TM which computes the delete function, converting configuration (q, xcy) to (h, xy), where c {0,1, } and x,y {0,1}*. Do not use any TM subroutines in your answer. [8 points] (b) Draw a transition diagram for a TM which sums a list of positive integers. The initial configuration for the machine is (q 0, n a 1... a n ),where n is an integer specifying how many numbers are to be added, and a 1 -a n are the numbers themselves. The final configuration of the machine should be (h, a 1 +...+a n ). All values are represented as sequences of 1 s. For example, started with (q 0, 111 1111 111 1 ) your machine should produce (q 0, 11111111 ). That is, 4 + 3 + 1 = 8. You may use the delete machine from part a, but no other subroutine. [12 points] Enjoy your day off on Friday!