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

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...
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
Ex#3: Give a string of lengths, 4, 6, 8 generated by the following grammar G =...
Ex#3: Give a string of lengths, 4, 6, 8 generated by the following grammar G = (V, T, S. P). S → 0S S --> 0S1S S --> λ
2. (CFGs) Give CFGs that generate the following languages. Use as few variables as you can...
2. (CFGs) Give CFGs that generate the following languages. Use as few variables as you can (and no more than requested). Unless specified otherwise, the alphabet is Σ = {0, 1}. (c) L3 = {w | w represents a binary number that starts with 1 and is divisible by 3}. Use at most 4 variables. (d) L4 = {x1#x2# · · · #xk | k ≥ 1, each xi ∈ {0, 1}* , and xi = xjR for some i...
Assignment: Grammar Agreement Read the following passages. For each sentence, determine if the subject and verbs...
Assignment: Grammar Agreement Read the following passages. For each sentence, determine if the subject and verbs agree with each other. If the subject and verb already agree, do not make any changes. If the subject and verb do not agree, re-write the verb to correct the problem Every one suspecting himself of at least one of the cardinal virtues, and this are mine: I is one of the few honest people that I have ever known. -The Great Gatsby, F....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT