Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transparency No. 1 Formal Language and Automata Theory Homework 5.

Similar presentations


Presentation on theme: "Transparency No. 1 Formal Language and Automata Theory Homework 5."— Presentation transcript:

1 Transparency No. 1 Formal Language and Automata Theory Homework 5

2 Homework Transparency No. 2 1. CFG design 1. Give context-free grammars that generate the following languages. 1.1 A1 = {0,1}* 1.2 A2 = {w  {a,b}* | w ends with ‘aba’.} 1.3 A3 = {w | w matches the regular expression (ab*+ba*)* } 1.4 A4 = {w  {0,1}* | w contains more 0s than 1s,i.e.,#0(w) > #1(w).} 1.5 A5 = {0,1}* - { ww | w  {0,1}* }. Notes. 1. A1, A2 and A3 are regular. 2. Hint for 1.4: Two grammars for the language A4’ = {w | w contains as many 0s as 1s, i.e., #0(w) = #1(w). } can be given as follows: G 1 : S   | 0S1 | 1S0 | SS or G 2 : T   | 0A | 1BA  1 | 0AA | 1T B  0 | 1BB | 0T (For G 2 : we have: for all x  L(T), y  L(A) and z  L(B), #0(x)=#1(x), #1(y) = #0(y) + 1, #0(z) = #1(z) + 1. )

3 Homework Transparency No. 3 2. Regular grammar 2. Let B = { x  {a,b}* | k  0, #b(x) = 4k+1 or 4k+2 } 2.1 Find a strongly right linear grammar G1 such that L(G1) = B. 2.2 Find a strongly left linear grammar G2 such that L(G2) = B. //note: #b(x) is the number of b’s occurring in x. 3. Given the following Grammar G3: S  A | T | AS T   | bA | aB A  a | bAA | aT B  b | aBB | bT 3.1 Find a grammar G4 containing no  -rule such that L(G4) = L(G3) – {  }. 3.2 Find a grammar G5 containing no unit rule such that L(G5) = L(G4) 3.3 Find a Gramamr G6 in Chomsky normal form such that L(G6) = L(G5).

4 Homework Transparency No. 4 3 Pumping lemma for CFL 3.1 Show that the language A = { a k b s c t  {a,b,c}* | 0< k < s < t } is not context free. 3.2 Show that the language B = { xy  {0,1}* | x  {0,1}* and y is the 1's complement of x.} is not context free. Instances of B include 0110, 110001 etc, but do not include 0101, 010 and 0111.

5 Homework Transparency No. 5 4. Context free grammar composition Given two grammar : G7: S  bS | Ab A  a | BA | SB B  bA | bB G8: T  Tb | aTC C  aC | bT 4.1 Find a CFG G9 such that L(G9) = L(G7)  L(G8). 4.2 Find a CFG G10 such that L(G10) = (L(G7)  L(G8) )*. Notes 1.you can reuse production rules and symbols in G7 and G8. 2.You need not study the specific details of G7 and G8, since, as studied in the lecture, there is a systematic method to compose both grammars directly from the general definition of two input CFGs.

6 Homework Transparency No. 6 5. CYK algorithm 5.1. Given the grammar G in Chomsky normal form S  AB A  BB | a B  AB | b | AA 1 Apply the CYK algorithm on the input string aabba to determine if it is in L(G) by completing the following table. 2 Is aabba a member of L(G) ? why ? 3 Is this grammar ambiguous ? why ? 4 a 3 b 2 b 1 a 0 a 123 45

7 Homework Transparency No. 7 5. CYK algorithm 5.2 Given the grammar G in Chomsky normal form S  CB | DA A  a | CS | EA B  b | DS | FB C  aD  b E  DA F  CB 1 Apply the CYK algorithm on the input string aabbab to determine if it is in L(G) by completing the following table. 2 Is aabbab a member of L(G) ? 3 Is this grammar ambiguous ? 5 b 4 a 3 b 2 b 1 a 0 a 123 456

8 Homework Transparency No. 8 6. Parse trees and derivations 6.Given the following grammar : S   | aB | bA A  aS | bAA B  bS | aBB 6.1 Find a left-most derivation for the string aabbba 6.2 Find a right-most derivation for the string babbaa. 6.3 Find a parse tree for aababb.


Download ppt "Transparency No. 1 Formal Language and Automata Theory Homework 5."

Similar presentations


Ads by Google