Presentation is loading. Please wait.

Presentation is loading. Please wait.

Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.

Similar presentations


Presentation on theme: "Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike."— Presentation transcript:

1 Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at www.peerinstruction4cs.org.Dr. Cynthia Lee, UCSDCreative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported Licensewww.peerinstruction4cs.org

2 CONTEXT-FREE LANGUAGES PDA If a language isn’t regular, it just might be one of the…

3 Understanding Pushdown Automata The edge from q0 to q1 does what? a)Lets you go to q1 without reading any input (on epsilon) b)Lets you go to q1 on epsilon or ‘$’ c)Lets you go to q1 on ‘$’

4 Understanding Pushdown Automata In addition to what we said in the last question, the edge from q0 to q1 does what else? a)Pushes one entry onto the stack (epsilon) b)Pushes one entry onto the stack (‘$’) c)Pushes two entries onto the stack (epsilon and ‘$’) d)Pops two entries off the stack (epsilon and ‘$’)

5 Input “aabb” into this PDA. After “aa” has been read, what is on the stack? Tracing in a Pushdown Automaton a) b) c) d) e) top of stack bottom of stack  bb aa aa0 0aa ϵϵϵ

6 Which is the best description of the language of the given PDA? a){ w | number of b’s in w >= number of a’s in w} b){w | w = a n b n+1 for some n>=0} c){ w | w = a n b n+2 for some n>=0} d){ w | w = a n b 2n for some n>=0} e){w | w = 0a n b 2n 0 for some n>=0} Language of a Pushdown Automaton

7 Tracing in a Pushdown Automaton Which string is NOT accepted by this PDA? a) aabb b) abbbc c) abbccc d)aabcc e)None or more than one of the above

8 Tracing in a Pushdown Automaton Which choice depicts a stack state that occurs at some point during the successful* processing of the string “aaabbbc” on the given PDA? a) b) c) d) e)None of the above * Ignore all nondeterministic paths that end in rejecting/getting stuck. top of stack bottom of stack  aaabbbc #a a# #λ

9 Why did we push ‘#’ onto the stack? a)We didn’t have to, because we already “counted” the a’s by pushing them on the stack b)It’s something we do because of convention, but it isn’t necessary to correctness c)We did it to make sure that we didn’t cause a crash/error by trying to pop something off an empty stack d)It is necessary to correctness e)None or more than one of the above

10 THE CLASS OF CONTEXT-FREE LANGUAGES CFLs!

11 Which Venn diagram best represents the classes of languages we have studied? RLs CFLs RLs CFLs = RLs CFLs RLs (a)(b) (c)(d)(e) None of the above Note: CFLs = Context- Free Languages, RLs = Regular Languages

12 What methods can we use to prove/disprove each of these? RLs CFLs RLs CFLs = RLs CFLs RLs (a)(b) (c)(d) Note: CFLs = Context- Free Languages, RLs = Regular Languages

13 Famous People: Noam Chomsky In this class, you know him as the namesake of “Chomsky Normal Form” A linguist who has taught at MIT for 55 years Famous for: Developed theories of conetxt-free grammars for analysis of human language – A mathematical model of language – Discoveries crossed over into Computer Science Perhaps now equally well known for his outspoken criticism of US foreign policy and his radical political views – Anarchist – Vehement war critic, war on drugs critic – Co-wrote Manufacturing Consent, argues that the media in our society is harming democracy and promoting corporations and consumerism

14 CONTEXT-FREE PUMPING LEMMA Proving that languages that are NOT context-free

15 Limits of Context-Free Languages What are the limitations of Context-Free languages What are the limitations of PDA? – Stack size has no limit (infinite stack) – ….BUT, there’s only one of them – Stack can only be accessed at the top What does that mean intuitively? When would you need more than one stack? Regular Context-Free Not Context-Free

16 PDA Language is 0 n 1 2n Can we change this so it is 0 n 1 2n 0 n ?

17 Classic Not-Context-Free Language a n b n c n for some n>=0 INTUITIVELY, the problem is that a PDA recognizing this language would try to: – Push on the stack to count the ‘a’ section, then – Pop off the stack to match the ‘b’ section, then – You’ve “forgotton” n, now you can’t count the ‘c’ section Aside: what could you do with a second stack? THIS IS NOT A PROOF!! – Maybe there is a completely different way to approach this problem using PDA, which we just didn’t think of yet – But, turns out, there is no way to do this, and we can actually prove that

18 Aside: Recognizing a n b n c n for some n>=0 using a second stack

19 CFL Pumping Lemma

20 Proving {a i b j c k | 0<=i<=j<=k} is not Context-Free s = a p b p c p i = ??? – Can’t solve it with just one i! – For the case analysis in this proof, we need to use i=0 for some cases of how the string is sliced up, and i=2 for other cases of how the string is sliced up – Is that legal??? Yes. The Pumping Lemma Game shows us why…

21 The REGULAR LANGUAGES Pumping Lemma Game Your Script “I’m giving you a language L that I’m assuming is regular.” “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| >= p. I think you’ll really like it.” “Hm. I followed your directions for xyz, but when I [copy y N times or delete y], the new string is NOT is L! What happened?” Pumping Lemma’s Script “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p.” “Great string, thanks. I’ve cut s up into parts xyz for you. I won’t tell you what they are exactly, but I will say this: |y| > 0 and |xy| <= p. Also, you can remove y, or copy it as many times as you like, and the new string will still be in L, I promise!” “Well, then L wasn’t a regular language. Thanks for playing.”

22 The CONTEXT-FREE LANGUAGES Pumping Lemma Game Your Script “I’m giving you a language L that I’m assuming is context-free.” “Excellent. I’m giving you this string s that I made using your p. It is in L and |s| >= p. I think you’ll really like it.” “Hm. I followed your directions for uvxyz, but when I [copy vy N times or delete vy], the new string is NOT is L! What happened?” Pumping Lemma’s Script “Thanks. For the language L that you’ve given me, I pick this nice pumping length I call p.” “Great string, thanks. I’ve cut s up into parts uvxyz for you. I won’t tell you what they are exactly, but I will say this: |vy| > 0 and |vxy| <= p. Also, you can remove v and y, or copy them as many times as you like (as in uv i xy i z), and the new string will still be in L, I promise!” “Well, then L wasn’t a context-free language. Thanks for playing.”

23 MIDTERM REVIEW Review review review…

24 From last year’s midterm: 5. To prove a language is not regular, which method can be used? a)Show several DFAs or NFAs that almost, but not quite, recognize the language, and then conclude that no DFA or NFA can recognize the language. b)Use the Pumping Lemma for regular languages. c)Show a CFG that recognizes the language, and then conclude that the language is context-free, not regular. d)(b) and (c) e)None of the above.

25 (a) TRUE or (b) FALSE The following proof is valid: A = {w | w=a n for n>=0} is a regular language, and B = {w | w=b n for n>=0} is a regular language because we can produce DFA’s M A and M B for A and B, respectively (see drawings). Regular languages are closed under concatenation, therefore language AB = {w | w=a n b n for n>=0} is a regular language. (valid in this case means the flow of logic is sound, even though may not do a great job of stating GIVEN/WANT TO SHOW, etc)


Download ppt "Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike."

Similar presentations


Ads by Google