1 / 12

COSC 3340: Introduction to Theory of Computation

COSC 3340: Introduction to Theory of Computation. University of Houston Dr. Verma Lecture 10. Chomsky Normal Form (CNF). Rules of CFG G are in one of two forms: (i) A  a (ii) A  BC, B  S and C  S + Only one rule of the form S   is allowed if  in L(G).

talon
Download Presentation

COSC 3340: Introduction to Theory of Computation

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. COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10 UofH - COSC 3340 - Dr. Verma

  2. Chomsky Normal Form (CNF) • Rules of CFG G are in one of two forms: (i) A  a (ii) A  BC, B  S and C  S + Only one rule of the form S  is allowed if  in L(G). • Easier to reason with in proofs • Leads to more efficient algorithms • Credited to Prof. Noam Chomsky at MIT Reading Assignment: Converting a CFG to CNF. UofH - COSC 3340 - Dr. Verma

  3. Exercises • Are the following CFG's in CNF? (i) SaSb |  (ii) SaS | Sb |  (iii) SAS | SB |  Aa Bb (iv) SAS | SB Aa |  Bb UofH - COSC 3340 - Dr. Verma

  4. Closure properties of CFL's • CFL's are closed under: (i) Union (ii) Concatenation (iii) Kleene Star • What about intersection and complement? UofH - COSC 3340 - Dr. Verma

  5. The setting • L1= L(G1) where G1 = (V1, T, P1, S1) • L2 = L(G2) where G2 = (V2, T, P2, S2) • Assume wlog that V1V2 =  UofH - COSC 3340 - Dr. Verma

  6. Closure under Union -- Example • L1 = { anbn | n  0 } • L2 = { bnan | n  0 } • G1 ? • Ans: S1aS1b |  • G2? • Ans: S2bS2a |  • How to make grammar for L1L2? • Ans: Idea: Add new start symbol S and rules SS1| S2 UofH - COSC 3340 - Dr. Verma

  7. Closure under Union General construction • Let G = (V, T, P, S) where • V = V1V2 { S }, • SV1V2 • P = P1P2 { SS1 | S2 } UofH - COSC 3340 - Dr. Verma

  8. Closure under concatenation Example • L1 = { anbn | n  0 } • L2 = { bnan | n  0 } • Is L1L2 = { anb{2n}an | n >= 0 } ? • Ans: No! It is { anb{n+m}am | n, m  0 } • How to make grammar for L1L2 ? • Idea: Add new start symbol and rule SS1S2 UofH - COSC 3340 - Dr. Verma

  9. Closure under concatenation General construction • Let G = (V, T, P, S) where • V = V1V2 { S }, • SV1V2 • P = P1P2 { SS1S2 } UofH - COSC 3340 - Dr. Verma

  10. Closure under kleene star Examples • L1 = {anbn | n 0} • What is (L1)*? • Ans: { a{n1}b{n1} ... a{nk}b{nk} | k 0 and ni 0 for all i } • L2 = { a{n2} | n 1 } • What is (L2)*? • Ans: a*.Why? • How to make grammar for (L1)*? • Idea: Add new start symbol S and rules SSS1 | . UofH - COSC 3340 - Dr. Verma

  11. Closure under kleene star General construction • Let G = (V, T, P, S) where • V = V1 { S }, • SV1 • P = P1 { SSS1| } UofH - COSC 3340 - Dr. Verma

  12. Tips for Designing CFG's • Use closure properties -- divide and conquer • Analyze strings – Is order important? Number? Do we need recursion? • Flat versus hierarchical? • Are any possibilities (strings) missing? • Is the grammar generating too many strings? UofH - COSC 3340 - Dr. Verma

More Related