1 / 18

CSC3130 Mid-term Review

CSC3130 Mid-term Review. bridger.zhao@gmail.com. Department of Computer Science & Engineering. Scope: regular languages. DFA, NFA and conversion from NFA to DFA. Regular expression. Equivalence of DFA, NFA and regular expression. Closure properties of regular languages.

lalaine
Download Presentation

CSC3130 Mid-term Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC3130 Mid-term Review bridger.zhao@gmail.com Department of Computer Science & Engineering

  2. Scope: regular languages • DFA, NFA and conversion from NFA to DFA. • Regular expression. • Equivalence of DFA, NFA and regular expression. • Closure properties of regular languages. • Pumping lemma for regular languages. • DFA minimization algorithm, DFA equivalence. CSC3130 Tutorial One

  3. Scope: context free languages • Context free grammars. • Derivations, parse trees, and ambiguity. • Removal of ε and unit productions, Chomsky Normal Form. • The CYK parsing algorithm. • Pushdown automata. • Pumping lemma for context-free languages CSC3130 Tutorial One

  4. NFA to DFA & State minimization CSC3130 Tutorial One

  5. DFA Hacking • Let L be a regular language, L’={u|uv is in L and |u|=|v|}. That is, L’ is the first halves of strings in L. Prove that L’ is also regular. • Hints: Let M be the DFA for L, How do we characterize a middle state? CSC3130 Tutorial One

  6. Closure Properties • For regular languages: union, intersection, concatenation, Kleen closure, reverse, complement, etc. • For context free languages, exclude intersection and complement. • Usage: is L L regular? Is non palindromes regular? CSC3130 Tutorial One

  7. Context Free Language • S → |aaSbbb • CFG to PDA see 08L10,17/23 CSC3130 Tutorial One

  8. CNF • Consider the following simple grammar: • A  cA | a • B  ABC | b • C  c • How to convert this grammar to CNF? CSC3130 Tutorial One

  9. Conversion into CNF Step 1: Convert every production into either: A B1B2…Bn or A a e.g. A  bCDeF becomes: A  BCDEF B  b E  e CSC3130 Tutorial One

  10. Conversion into CNF Step 2: Convert production of the form A B1B2…Bn into A  C1C2 : e.g. A  BCDEF becomes: A  BX X  CY Y  DZ Z  EF CSC3130 Tutorial One

  11. Example • Convert the following CFG into Chomsky Normal Form: S  • S  ABBA • B  bCb • A  a • C  c CSC3130 Tutorial One

  12. Solution Step 1: B bCb becomes B DCD D b Step 2: S  ABBA becomes S AE E BF F BA B DCD becomes B DG G CD Result: S  S AE E BF F BA B DG G CD A  a C  c D b S  S  ABBA B  bCb A  a C  c CSC3130 Tutorial One

  13. Pumping Lemma for CFL • L = { ww | w is in {0,1}* } • Assume L is a CFL • Let n be the Pumping Lemma constant • Considerz = 0n1n0n1n, |z| = 4n > n • We want write z = uvwxy with |vwx|  n and |vx| 1 • There are several cases for uvwxy CSC3130 Tutorial One

  14. Pumping Lemma for CFL 0n1n0n1n • Case 1: vwx is within the first block0’s • v and x must contain 0’s • Let vx consist of k 0’s, where k > 0 • Choose i=0, uviwxiy=0n-k1n 0n1n • If 0n-k1n 0n1n in form of ww, the end of first w must lie in the second block of 0’s • Then, the two w’s are in the different pattern:0+1+0+ and 0+1+.So, 0n-k1n 0n1n L CSC3130 Tutorial One

  15. Pumping Lemma for CFL • Case 2: vwx spread over the first block of 0’s and first block of 1’s • vx has at least one 0’s or one 1’s • Let vx consist of k 0’s and p 1’s, where k0 ,p>0 or k>0,p 0 • Choose i=0, uviwxiy=0n-k1n-p 0n1n • If 0n-k1n-p 0n1n in form of ww, the end of first w must lie after the first block of 1’s • Then, the number of 1’s is different in two w. So, 0n-k1n-p 0n1n L 0n1n0n1n CSC3130 Tutorial One

  16. Pumping Lemma for CFL • Case 3: vwx is within the first block of 1’s • v and x must contain 1’s • Let vx consist of k 1’s, where k > 0 • Choose i=0, uviwxiy =0n1n-k 0n1n • If 0n1n-k 0n1n in form of ww, the end of first w must lie in the second block of 0’s • Then, the number of 1’s is different in two w. So, 0n1n-k 0n1n L. 0n1n0n1n CSC3130 Tutorial One

  17. Pumping Lemma – Example • Case 4: vwx spread over the first block of 1’s and second block of 0’s • vx has at least one 1’s or one 0’s. • Let vx consist of k 1’s and p 0’s, where k 0,p>0 or k>0,p 0 • Choose i=0, uviwxiy =0n1n-k 0n-p1n • For 0n1n-k 0n-p1n in form of ww, if the end of first w lie in the first block of 1’s, then the number of 0’s is different in two w. • if the end of first w lie in the second block of 0’s, then the number of 1’s is different in two w. So, 0n1n-k 0n-p1n L 0n1n0n1n CSC3130 Tutorial One

  18. Pumping Lemma for CFL • Other cases: vwx is within the second half of z • the argument is symmetric to the cases where vwx is within the first half of z • We can conclude that L = { ww | w is in {0,1}* } is not context free. 0n1n0n1n 0n1n0n1n 0n1n0n1n CSC3130 Tutorial One

More Related