Question

In: Computer Science

Give a grammar that generates each of the following languages: (1) L = {a2n cm bm...

Give a grammar that generates each of the following languages:
(1) L = {a2n cm bm | m ≥ 0, n ≥ 0}
(2) L = {an b2m cn | m ≥ 0, n ≥ 0}
(3) L = {an bm | n+m is even}
(4) L = {an bm | n ≤ m+3}
(5) The complement of the language L = {anbn | n ≥ 0}

Solutions

Expert Solution

The generated grammars for the given L is as follows,

(1) L = {a2n cm bm | m ≥ 0, n ≥ 0}

   

     L = {ε} U {Even length of infinite a’s} U {All odd and even length string cb } U {combination of a’s and cb’s with even length a’s}

     L = {ε,aa,aaaa,aaaaaa,aaaaaaaa,....,cb,cbcb,cbcbcb,.....,aacb,aacbcb,aacbcbcb,.. aaaacb,aaaacbcb,.....}

(2) L = {an b2m cn | m ≥ 0, n ≥ 0}

     L = {ε} U U {Even length of infinite b’s} U {All odd and even length string ac } U {combination of a’s,b’s and c’s with equal number of a’s and c’s and even length b’s}

      L = {ε,bb,bbbb,bbbbbb,bbbbbbbb,....,ac,acac,acacac,.....,abbc,abbbbc,abbbbbbc,.....}

(3) L = {an bm | n+m is even}

No constraint in giving so we can consider n>=0 and m>=0. Considering zero as even number.

     L = {ε} U { even length strings formed consists of ab}

     L={ε,aa,bb,ab,aaaa,aaab,aabb,abbb,bbbb,...}

(4) L = {an bm | n ≤ m+3}

Considering the considering the condition n<= m+3

So,

when m=0,n<=3 can be applied

When m=1,n<=4

When m=2,n<=5.

L = {ε, a,aa,aaa,b,ab,aab,aaab,aaaab,bb,abb,aabb,aaabb,aaaabb,aaaaabb,...}

(5) The complement of the language L = {anbn | n ≥ 0}

Consider L* as the complete closure of all combinations of a’s and b’s

    L = L* - {equal number of a’s and b’s}

       = {unequal number of a’s and b’s}

       = {ε,a,aa,aaa,... b,bb,bbb,...,aab,aaab,...,abb,abbb,....}



Related Solutions

1-Give a BNF grammar (do not use EBNF) for the language that generates the set of...
1-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by zero or more statements with a semicolon after each one, followed by the keyword end. Use the non-terminal for statements, and do not give productions for it. 2-Give a BNF grammar (do not use EBNF) for the language that generates the set of all strings consisting of the keyword begin, followed by one or more...
Formal Languages Give a regular expression for each of the following languages: L2a = {w ?...
Formal Languages Give a regular expression for each of the following languages: L2a = {w ? {0,1}* | w corresponds to the binary encoding of non-negative integers that are evenly divisible by 4 L2b = {w ? {a,b}* | w contains at least one 'a' and exactly two b's} L2c = {w ? {0, 1, 2}* | w starts with a 2, ends with a 1 and contains an even number of 0's}.
each one of the following languages defined over {0,1}, give the transition diagram of a deterministic,...
each one of the following languages defined over {0,1}, give the transition diagram of a deterministic, single tape Turing Machine. {03i 1 02i 1 0i | i > 0}
The first five questions give languages over {0, 1}. In each case decide whether the language...
The first five questions give languages over {0, 1}. In each case decide whether the language is regular or not, and prove your answer is correct. 5. The set of strings in which the number of 0's is a perfect square.
Determine whether or not the following languages are regular. If the language is regular then give...
Determine whether or not the following languages are regular. If the language is regular then give an NFA or regular expression for the language. Otherwise, use the pumping lemma for regular languages or closure properties to prove the language is not regular. 1) L = { 0 n1 k : k ≤ n ≤ 2k} 2) L = { 0 n1 k : n > 0, k > 0 } È { 1 k0 n : k > 0, n...
Prove Turing-Decidability of the following languages. L = { < M > | TM M accepts...
Prove Turing-Decidability of the following languages. L = { < M > | TM M accepts at least one string in no more than 9 step} Hint: What is the maximum number of tape squares can a TM scan in no more than 9 steps?
Give the grammar following: E --> E + T | T T --> T* F |...
Give the grammar following: E --> E + T | T T --> T* F | F F --> (E) | id Eliminating the left recursion rules and getting a non-left recursive equivalent grammar.
The first five questions give languages over {0,1}. In each case decide whether the language is...
The first five questions give languages over {0,1}. In each case decide whether the language is regular or not, and prove your answer is correct The set of all strings x beginning with a non-null string of the form ww.
Give the finite-state automaton and the regular grammar for the following: (a) (ab v ba)* v...
Give the finite-state automaton and the regular grammar for the following: (a) (ab v ba)* v (ab)* (b) (11*)*(110 v 01) (c) All strings over {0,1} containing the string 010 (d) All strings over {0,1} which do not contain the string 010
1b. Explain each of the following with an example in two languages of your choice for...
1b. Explain each of the following with an example in two languages of your choice for each item. (25 points) Orthogonality Generality Uniformity
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT