CS311 / MATH352 - AUTOMATA AND COMPLEXITY THEORY Homework # 8 Max. Points: 100 Due Date: Thursday, February 15, 2007, 11:45 AM Student s Name: Student ID: Important Instructions You are required to get print-out of this homework, and solve it using the space provided against each question. You are not allowed to solve on other papers. Clearly state your assumptions, if you are assuming some thing in addition to the given information in each question. Please write legibly. Write your roll number on every page that you submit. Avoid copying work of another person. If found, then such case would be forwarded for disciplinary action without any warning / justification. If you are acquiring help from any resource, then include references completely. There are total 5 questions in this homework Qs 1a)Suppose that you have a class of PDAs, let us say PDA new where you are allowed to have more than one symbol on the left side of a transition. E.g, ABC D is allowed under the rules of PDA new. Show that this class of PDAs has equivalent power to the PDAs that you have studied in class (let us call this latter class PDA normal.) in which you were allowed to pop only one symbol at a time. To do so, use the following method. Take a PDA new that accepts an arbitrary language L, and construct a PDA normal that accepts the same language. Similarly, take a PDA normal that accepts an arbitrary language L, and construct a PDA new that accepts the same language. Note: Over here, both PDA new and PDA normal accept by final state. (15 marks) Ans 1) Showing that a PDA new simulates a PDA normal is trivial. Since you may have one or more symbols on the left side of a transition of PDA new, you can take a PDA normal and simulate all its transitions. The reverse direction is a little more tricky(simulating a PDA new by a PDA normal ) is a bit more tricky, but it can be done like this. Suppose you have a transition as below: x, ABC-> DE Q1
Now, what you need to do is introduce new states for popping each symbol in turn. It goes like this: Q1 x, A-> λ λ, B-> λ λ, C-> DE P1 P2 In general, for any transition with z number of symbols on L.H.S (where z>1), add z-1 new states, where you pop out each symbol in turn. If you find all the symbols in the transition, then from the last state push the entire R.H.S of original transition. This will yield an equivalent NPDA.
Qs 1b) Now, let us consider another class of PDAs, which has no start symbol and does not necessarily halt upon empty stack. So, for example, it will halt if the only transition available between two states q i and q j while stack is empty is of form ( 0,A anything ) but it will not halt if there is a transition of form ( 0, λ B) or (0, λ λ) while the stack is empty. Show that this class of PDAs (let us call these PDA no_start ) are equivalent in power to PDA normal, by the same method as used in part a) Note: Over here, both PDA no_start and PDA normal accept by final state. (10 marks) Ans) Showing that PDA normal simulates PDA no_start is fairly trivial. Take PDA no_start, and add a new start state and start variable. If PDA no_start hangs any where, so does the PDA normal we have constructed. Simlarly, if PDA no_start accepts, so does PDA normal. The original PDA no_start, with no start symbol. Qf We simulate the same thing in PDA normal, but over here when we start in P0, the stack contains a start symbol $. This PDA will accept same language as above. P0 λ, λ-> λ Qf Now, we need to show that PDA no_start simulates PDA normal.. Its fairly simple.
1) Take a given PDA normal P1 with its states and transitions. It starts out with a start symbol $. 2) Take all the states and transitions to a new machine P2 which is a PDA no_start. Introduce a new start state, and push the start symbol $ onto PDA no_start. This new PDA now simulates all the transitions of PDA normal. 3) Now, what we need to do is find a way to have this PDA halt if the start symbol is popped. So what we do is replace all transitions of form (a, λ -> x) according to every letter of the alphabet. So, if stack alphabet is {A,B,C, $} then (a, λ -> x) is replaced by (a, A -> x) and (a, B -> x), (a, C -> x) and (a, $ -> x). This modification now prevents us operating on an empty stack, just as we had in original P1. 4) We also need to ensure that the state machine halts after doing something f the form $->$. So, wherever a $->$ transition occurs, we remove it and replace it with the same transition going to a state having no outgoing transitions (we take it to an accepting state if the $->$ transition occurred on a accepting state in the original P1; a non-accepting state if it initially occurred on a non-accepting state in P1). 5) This P2 now accepts an equivalent language to P1. The original PDAnormal, with a start symbol $ present by default. Qf Below, we have to place the start symbol in PDAno_start ourselves. We also take precautions by modifying lambada transitions in between and Qf to halt the PDA when stack is empty. P0 λ, λ-> $ Qf
Qs 2 a). Use the CYK algorithm on the strings 010010 and 000000 for the grammar below to determine whether they belong to the language or not. You must exhibit the table correctly to receive credit. (Note: You may, or may not, have to simplify the grammar first before proceeding) 20 marks S --> AB BC A --> BA 0 B --> CC 1 C --> AB 0 {B} {S,C} {S,C,A} {A,S} - {A,S,C} {B} - {B} {B} {S,C} {S,A} {B} {S,C} {S,A} {A,C} {B} {A,C} {A,C} {B} {A,C} 0 1 0 0 1 0 Since the last entry does not contain S, we say the string w cannot be produced by the grammar. {B} {S,A,C} {S,A,C} {B} {B} {B} {S,A,C} {S,A,C} {S,A,C} {S,A,C} {B} {B} {B} {B} {B} {A,C} {A,C} {A,C} {A,C} {A,C} {A,C} 0 0 0 0 0 0
Since the last entry does not contain S, we say the string w cannot be produced by the grammar. b) You have studied the time-complexity of CYK algorithm in class (or at least in the slides). Give the big-oh, and explain why the algorithm has this complexity.. (5 marks) Since we have O(n square) entries, and each takes O(n) time, it takes O(n cube) time to implement this algorithm. Qs 3) Consider the language L of the form a n b n c i (0 <= n <= i <= 2n). Show that this language is non-context free using pumping lemma for CFL. This topic will be covered in Saturday s lecture. (20 marks) First of all, we assume the language L to be an infinite CFL for contradiction. We select the string w= a m b m c 2m, where m is pumping lemma constant. Now, we subdivide w = uvwxy, where w >m., vwx <=m and vx >=1. Case 1: vwx lies entirely in a s. Simply pump i = 2 to get a string where no of a s exceeds no of b s and hence does not belong to L. Case 2: vwx lies entirely in b s. Similar treatment to case 1. Case 3: vwx lies entirely in c s. Pump i =2 to get a string where no of c s exceeds double numbers of b s (and hence does not belong to L)
Case 4: v contains a s and b s, while x contains b s.simply pump i=2, the string you get will no longer be of form a s followed by b s followed by c s, and hence will not belong to L Case 5: v contains a s, while x contains a s and b s. Similar to case 4. Case 6: v contains b s and c s while x contains c s. Similar to case 4. Case 7: v contains b s while x contains b s and c s. Similar to case 4. Case 8: v contains a s, while x contains b s. Pump down (i = 0) to get a string where no of c s exceeds double numbers of b s, or double numbers of a s(and hence does not belong to L) Case 9: V contains b s and x contains c s. Pump up (i=2), to get a string where either no of c s exceeds double number of b s, or number of b s and a s are not equal (or both conditions) and hence does not belong to language L. Since we have a contradiction for each case when we pump the repeated portion of string, hence we have that our original assumption that L is CFL is mistaken. Hence by pumping lemma it is shown to be non-cfl. Qs 4 )Use the construction given in your book (pg 272-273, Exercise 7.1.11) to convert the following grammar to Greibach normal form. (10 marks) S AA 0 A SS 1 To be emailed later this evening Qs 5) This is essentially a reading/research check. Find out what the operations of homomorphism and inverse homomorphisms on a language are, and what are the closure properties of CFLs under these operations. Don t worry, these are just complicated names for a very simple concept that is explained in the book. You will need to know this(as well as the other closure properties studied in class) to solve the following questions.
a)assume that L1 ={ a n b n, n >= 0} is a CFL.. Now, use closure properties of CFL (you may use the ones studied in class, as well as homomorphisms and inverse homomorphisms) to prove that L2 = { a m b n c n, m>=0, n>=0} is also a CFL. (7 marks) Ans) First do a homomorphism on L1, replacing a with b and b with c to get L3 ={ b n c n, n >= 0} is a CFL. Now, take the language L4 =a* (which we know to be a CFL), and using closure of CFL under concatenation, take L4. L3 = { a m b n c n, m>=0, n>=0} as the required language which we needed to show to be CFL. b)you may assume that L1 ={ a n b n c n, n >= 0} is NOT a CFL. Using this fact, and closure properties of CFL(you may use the ones studied in class, as well as homomorphisms and inverse homomorphisms), show that L2 ={ a n b n c 2n, n >= 0} is also not a CFL. (13 marks) Ans) Assume for contradiction that L1 ={ a n b n c 2n, n >= 0} is indeed a CFL. Then we may perform a inverse homomorphism on L2, replacing cc with c (as CFL closed under inverse homomorphism). This gives us a new language, that is L1 ={ a n b n c n, n >= 0} which must also be CFL. But we are already given that L2 is non-cfl, so this conclusion is impossible. Hence our initial assumption that L1 is a CFL must have been wrong. Hence proved by contradiction, that L1 is noncfl (since assuming it to be CFL leads to impossible conclusion).
Note: To get credit in part a) and b), you may ONLY use closure properties and the assumptions given to you