{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw_04_sol - Problem Set 4 Fall 09 Due Thursday Nov 5 at...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Problem Set 4 Fall 09 Due: Thursday Nov 5 at 11:00 AM in class (i.e., Room 103 Talbot Lab) Please follow the homework format guidelines posted on the class web page: http://www.cs.uiuc.edu/class/fa09/cs373/ 1. [ Points : 10] Suppose G is a CFG with p rules and the body of each rule is not longer than n (Note: the rule S → aSbSA has a body length of 5). If we can derive ε from non-terminal S , then prove that we can derive it from S in no more than n p- 1 n- 1 steps. Solution: Consider all parse trees that derive ε from S and let T be one of them that has the minimum number of nodes. On every path from root to some leaf of T , no non-terminal appears twice (if it appears twice, then we can remove all nodes between the two occurrences of that non-terminal and still have a valid parse tree for ε ). Therefore the height of the tree is at most p- 1 . Since each node in the tree has at most n childs, the k-th level of T has at most n k nodes. Therefore the total number of nodes (which is equal to the total number of steps in the derivation) is no more than 1 + n + n 2 + ··· + n p- 1 = ( n p- 1) / ( n- 1) . 2. [ Points : 10] (a) Prove that this language is not context free: L = { a i b j c max( i,j ) | i,j ≥ } Solution: Assume to the contrary that it is context free. Therefore it follows the pumping lemma for CFLs and has a pumping length p . Consider the string s = a p b p c p ∈ L . Since | s | ≥ p , pumping lemma applies to s and we should be able to break s into s = xuyvz such that | uyv | < p , | uv | 6 = 0 and s i = xu i yv i z ∈ L for every i ≥ . We consider two cases (note that one of these cases always happens): • If | u | > and u contains some c 's, or | v | > and v contains some c 's, then s has exactly p a 's (note that | uyv | < p and since uyv has some c 's it cannot reach the area of a 's in the string) but less than p c 's therefore s / ∈ L . • Otherwise consider s 1 . Since u and v do not intersect c 's, s 1 has exactly p c 's. But the number of a 's or b 's in s 1 is more than p (since one of u and v has positive length and it intersects a 's or b 's). Therefore s 1 / ∈ L . So L does not follow the CFL-pumping lemma and therefore is not a CFL. (b) Prove that context free languages are not closed under the operator max , as de ned below: max( A ) = { w ∈ A | if wx ∈ A for some string x , then x = ε } . Hint: part(a) might be useful. 1 Solution: Consider this language A : A = { a i b j c k | k ≤ i or k ≤ j } We have seen a PDA for this language, so we know that A is context free. But note that if w = a i b j c k ∈ A and k < max( i,j ) , then wc ∈ A , therefore w / ∈ max( A ) . So the only possibility for w to be in max( A ) is when k = max( i,j ) . This means that max( A ) = L , where L is the language in part(a) that we know is not context free....
View Full Document

  • Fall '08
  • Viswanathan,M
  • Universal quantification, Formal language, Regular expression, Context-free grammar, context-free language

{[ snackBarMessage ]}

Page1 / 9

hw_04_sol - Problem Set 4 Fall 09 Due Thursday Nov 5 at...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online