Theory Final—Sample Questions—Version of November 6, 2009 Annotated version with some (sometimes rather sketchy) answers and notes. This is a collection of sample theory final questions. This is just to get some idea of the format of the final and the level of difficulty. These example questions do not guarantee anything about the topics of the questions on your final and they do not guarantee the exact level of difficulty of the questions on your final. The actual final will consist of five or six questions of equal weight. Your lowest question score won’t count. Procedures of the Theory Final 1. The only things that you are allowed to have out during the exam are your cheat-sheet, pen(s), pencil(s), an eraser, a ruler, and a simple watch. Please note that you are not allowed to use cellphones, PDAs, etc. as a clock. 2. Please silence your cellphones etc. 3. Do not share your supplies with others and do not talk with others. 4. Use only scrap paper provided by me. 5. Please also hand in your scrap paper when you are done. 6. Understanding the questions is part of the exam; you are not allowed to ask questions during the exam. 7. As usual, you only have to explain your answer if this is stated in the question. 8. If you use a theorem/construction from your book, please state what you are using where. 9. You may only leave the room after you finish your exam, 10. Your answers should be to the point. 1 1. Suppose that P 6= NP and that the alphabet is {a, b, c}. Draw a Venn diagram that shows the relationships between the following classes of languages: (a) NP (b) P (c) the DCFLs (d) the languages that can be accepted by an NFA-Λ (e) the languages that can be accepted by a nondeterministic Turing machine with 25 tapes (f) the languages that can be accepted by a Turing machine that halts on all inputs (g) the languages that can be generated by an unrestricted grammar (h) the languages that have an algorithmic solution (i) the languages whose complement is recursively enumerable (j) the recursive languages (k) the recursively enumerable languages (l) the regular languages Your Venn diagram should show the following relationships (d) = (l) ( (c) ( (b) ( (a) ( (f ) = (h) = (j) ( (e) = (g) = (k) In addition, (j) ( (i) and (i) ∩ (k) = (j). 2 2. (a) Suppose that the alphabet is {0, 1}. For every class of languages in the table, you have to state whether the class is closed under complementation, concatenation, and intersection. Write “yes” in a box if the class is closed under the operation, write “no” if the class is not closed under the operation, and write “nobody knows” if nobody knows whether or not the class is closed under the operation. closed under Complementation Concatenation Intersection NP nobody knows yes yes P The context-free languages The recursively enumerable languages yes yes yes no yes no no yes yes The recursive languages yes yes yes (b) For one of the boxes where you answered “no,” give an explicit example that shows why that particular class is not closed under that particular operation. (Clearly state which box you chose.) To show that a class is not closed under a particular operation, it suffices to give a counterexample. For example, To show that CFLs are not closed under intersection, argue as follows. let A = {ai bi cj | i, j ≥ 0} and let B = {ai bj cj | i, j ≥ 0}. Then A and B are CFLs, but A ∩ B = {ai bi ci | i ≥ 0}, which is not a CFL. (c) For one of the boxes where you answered “yes,” informally argue why that particular class is closed under that particular operation. (Clearly state which box you chose.) All “yes” boxes are totally doable. For example, to show that recursive languages are closed under complementation, argue as follows. Suppose A is recursive. Then there is an algorithm for A. If you switch the accepts and rejects in this algorithm, you get an algorithm for the complement of A. So, the complement of A is recursive. 3 3. Consider the following grammar G: S → Λ | 01S | 10S | 0S1 | 1S0 | S01 | S10 | 1S | S1 (a) Show that this grammar is ambiguous. You need to give a string and two leftmost derivations or two parse trees for this string. For example, these are two leftmost derivations for the string 1: S ⇒ 1S ⇒ 1 and S ⇒ S1 ⇒ 1 At first glance, it may seem that the language generated by G is L = {x ∈ {0, 1}∗ | n0 (x) ≤ n1 (x)}. However, this is not true. (b) For both of the following statements, circle “true” is the statement is true, and circle “false” if the statement is false. i. L ⊆ L(G) true / false ii. L(G) ⊆ L true / false (c) Show that L(G) 6= L. Argue that you can’t derive 00111100. (d) Give a context-free grammar that generates L. (It suffices to give the rules.) S → SS | 0S1 | 1S0 | S1. 4 4. Let L = {ai bk ci dk | i, k ≥ 0}. (a) Explain informally why L doesn’t seem to be a context-free language. A PDA that accepts L should push the a’s and the b’s. Then it needs to compare the c’s against the a’s. But the a’s are at the bottom of the stack. To get to the a’s, the b’s have to be popped. But then it is impossible to compare the b’s against the d’s. (b) Prove that L is not context-free. Suppose for a contradiction that L is context-free. Let n be the integer from the pumping lemma for context-free languages. Let u = an bn cn dn . Then u ∈ L and |u| ≥ n. So, by the pumping lemma for context-free languages, there exist strings v, w, x, y, z such that u = vwxyz, |wy| > 0, |wxy| ≤ n, and for any m ≥ 0, vwm xy m z ∈ L. Since |wxy| ≤ n and |wy| ≥ 1, it holds that wy ∈ a+ b∗ or wy ∈ b+ c∗ or wy ∈ c+ d∗ or wy ∈ d+ . We will show that all these cases, vxz 6∈ L. i. ii. iii. iv. If If If If wy wy wy wy ∈ a+ b∗ , then vxz contains less than n a’s and n c’s, so vxz 6∈ L. ∈ b+ c∗ , then vxz contains less than n b’s and n d’s, so vxz 6∈ L. ∈ c+ d∗ , then vxz contains less than n c’s and n a’s, so vxz 6∈ L. ∈ d+ , then vxz contains less than n d’s and n b’s, so vxz 6∈ L. We have shown that vxz 6∈ L. This is a contradiction. It follows that the assumption that L is context-free is wrong. So, we have shown that L is not context-free. 5 5. Give the simplified transition diagram of a (deterministic) Turing machine that halts on all inputs and that accepts the language {x ∈ {a, b}∗ | na (x) 6= nb (x)} Give a short explanation to convince me that your Turing machine is correct. Idea: we go through the string, looking for an ’a’ and changing it into ’X’, then we go to the end of the string and going backwards we look for a ’b’ and change it into ’X’. Thus, we mark off exactly one ’a’ and one ’b’. We continue doing this process. If we cannot find an ’a’, we have to check that we still have a ’b’ to conclude that the number of ’a’s and ’b’s is not the same. If there is a ’b’, we accept, if not, we reject. If we have found an ’a’ and we cannot find a ’b’, we know that the numbers are not the same and we accept. 6 6. Recall that a counter automaton is a PDA with just two stack symbols, A and Z0 , for which the string on the stack is always of the form An Z0 for some n ≥ 0 (such a restricted stack is called a counter). A two-counter automaton is like a counter automaton, except that it has two counters. (a) Give a language that can be accepted by a deterministic two-counter automaton, but not by a PDA. L = {ak bk ck | k ≥ 1} (b) Draw the transition diagram of a deterministic two-counter automaton that accepts your language from part (a). Explanation of notation: σ, γ1 /u1 , γ2 /u2 means that we are reading input symbol σ, top of the first stack γ1 , top of the second stack γ2 and we are replacing the stack symbols with u1 on the first stack and u2 on the second stack. Notice that γ1 , γ2 are either A or Z0 , and u1 , u2 are strings over {A}, or possibly Z0 is the corresponding γ is Z0 . (c) Give a short, high-level explanation to convince me that your two-counter automaton is correct. Idea: While we read ’a’s, we push ’A’ onto both stacks. Then for every ’b’ we pop ’A’ from the first stack and for every ’c’ we pop ’A’ from the second stack. 7 7. Consider the following decision problem EMPTYTM : Given a Turing machine M , is L(M ) = ∅? (a) Show that EMPTYTM is undecidable. This follows immediately from Rice’s Theorem. (b) Is EMPTYTM in RE (recursively enumerable), in coRE, in both, or in neither? Explain your answer. EMPTYTM is in coRE, but not in RE. Note that it can not be in both RE and coRE, since then it would be decidable, and we know that it isn’t (from part (a). It is in coRE by the following nondeterministic semi-algorithm for EMPTY0TM : On input M , a TM, guess a string x and run M on input x. If M accepts x, accept. (c) Show that the following problem is undecidable: Given two TMs M1 and M2 , is L(M1 ) ∩ L(M2 ) = ∅? We will call the new problem EQTM . Suppose for a contradiction that EQTM is decidable. Then we can decide EMPTYTM as well, since L(M ) = ∅ if and only if L(M ) ∩ L(M ) = ∅. This is a contradiction. It follows that EQTM is undecidable. Note: It is not possible to construct a TM M such that L(M ) = L(M1 ) ∩ L(M2 ). 8
© Copyright 2024