Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test # 2 Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score.

Similar presentations


Presentation on theme: "Test # 2 Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score."— Presentation transcript:

1 Test # 2 Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score

2 Solution Exercise 2.23 (credits to Jeff Kleeblatt for finding this elegant solution) S  AB | BA A  XAX | 1 B  XBX | 0 X  0 | 1

3 Idea of Pumping Lemma for Context- Free Languages S  * uAz where A is a variable, u and z are in  * uAz  * uvAyz  * uvxyz where v, x and y are in  * S  * uv 2 xy 2 z uv 10 xy 10 z uv n xy n z for n = 1, 2, 3, …

4 Pumping Lemma for Context-Free Grammars Pumping Lemma for Context-Free Grammars. Given a context-free grammar G = ( ,V,R,S), there exists n > 0 such that: For any string w  L with |w|  n, there are u, v, x, y, z in  * for which the following holds: 1.w = uvxyz 2.|vxy|  n 3.v  e or y  e 4.uv i xy i z  L, for each i = 0, 1, 2, …

5 Preliminaries of the Proof Definition. Given a grammar G, the fanout of G, denoted f(G), is the greatest number of symbols on the right side of a rule in G Example: G ={ S  aSbS, S  ab, S  e } 4 2 1 F(G) = 4

6 Preliminaries the Proof (2) S  aSbS  aSbaSb  aSbab  a 2 b 2 ab Parse Tree: What is the maximum number of children for any node in this parse tree? F(G) S aSbS a ab S b e

7 Preliminaries (3) Lemma. Given a grammar G and a parse tree T for G, let w be the word contained in T, then: if length(w) > F(G) h, then height(T) > h Proof. The maximum number of leaves in a parse tree of height h is F(G) h = maximum number of characters of any word for that tree

8 Proof of Pumping Lemma Proof. Let n = F(G) |V|+1 Consider any w  L(G) with |w|  n Let T be a parse tree for w with the smallest height Let P be a path of length h, such that h is the height of T. Since |w|  F(G) |V|+1, then length(P)  |V| + 1 Thus, the number of nodes in P is at least |V| + 2 Thus, there must be at least one repeated variable A.

9 Proof (2) R akak T … A A … … amam a1a1 aiai ajaj alal apap uv xyz w = a 1 …. a p P has at least |V| + 2 nodes

10 Example {a n b n c n | n = 0, 1, 2, …} is not context-free {ww | w  {a,b}*}

11 Context-Free is not Closed under Intersection, Complement Theorem. Let L and M two context-free languages. Then L  M is not necessarily context-free L c is not necessarily context-free Proof (intersection). Homework (Friday): find a counter-example

12 Context-Free is not Closed under Intersection, Complement (2) Proof (complement). By contradiction: suppose that the complement of a context- free language is always context-free. We show that this implies that the intersection must always be context free: L  M = (L c  M c ) c

13 Homework 2.30 (a) 2.31 2.32 Show that the set of all context-free languages is not closed under intersection


Download ppt "Test # 2 Friday, November 2 nd Covers all of Chapter 2 Test # 2 will be 20% of final score (same as Test #1) Final Exam will be 40% of the final score."

Similar presentations


Ads by Google