Download presentation
Presentation is loading. Please wait.
Published byKimberly Tucker Modified over 9 years ago
1
Lecture 10UofH - COSC 3340 - Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10
2
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.
3
Lecture 10UofH - 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
4
Lecture 10UofH - 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?
5
Lecture 10UofH - COSC 3340 - Dr. Verma 5 The setting L 1 = L(G 1 ) where G 1 = (V 1, T, P 1, S 1 ) L 2 = L(G 2 ) where G 2 = (V 2, T, P 2, S 2 ) Assume wlog that V 1 V 2 =
6
Lecture 10UofH - COSC 3340 - Dr. Verma 6 Closure under Union -- Example L 1 = { a n b n | n 0 } L 2 = { b n a n | n 0 } G 1 ? – Ans: S 1 aS 1 b | G 2 ? – Ans: S 2 bS 2 a | How to make grammar for L 1 L 2 ? – Ans: Idea: Add new start symbol S and rules S S 1 | S 2
7
Lecture 10UofH - COSC 3340 - Dr. Verma 7 Closure under Union General construction Let G = (V, T, P, S) where – V = V 1 V 2 { S }, – S V 1 V 2 – P = P 1 P 2 { S S 1 | S 2 }
8
Lecture 10UofH - COSC 3340 - Dr. Verma 8 Closure under concatenation Example L 1 = { a n b n | n 0 } L 2 = { b n a n | n 0 } Is L 1 L 2 = { a n b {2n} a n | n >= 0 } ? – Ans: No! It is { a n b {n+m} a m | n, m 0 } How to make grammar for L 1 L 2 ? – Idea: Add new start symbol and rule S S 1 S 2
9
Lecture 10UofH - COSC 3340 - Dr. Verma 9 Closure under concatenation General construction Let G = (V, T, P, S) where – V = V 1 V 2 { S }, – S V 1 V 2 – P = P 1 P 2 { S S 1 S 2 }
10
Lecture 10UofH - COSC 3340 - Dr. Verma 10 Closure under kleene star Examples L 1 = {a n b n | n 0} What is (L 1 )*? – Ans: { a {n1} b {n1}... a {nk} b {nk} | k 0 and ni 0 for all i } L 2 = { a {n 2 } | n 1 } What is (L 2 )*? – Ans: a*. Why? How to make grammar for (L 1 )*? – Idea: Add new start symbol S and rules S SS 1 | .
11
Lecture 10UofH - COSC 3340 - Dr. Verma 11 Closure under kleene star General construction Let G = (V, T, P, S) where – V = V 1 { S }, – S V 1 – P = P 1 { S SS 1 | }
12
Lecture 10UofH - 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?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.