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}.
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 --> λ
1.   Define each of the following fundamental concepts Interpreted vs. Compiled Languages Interpretive Overhead Scripting (Procedural) vs....
1.   Define each of the following fundamental concepts Interpreted vs. Compiled Languages Interpretive Overhead Scripting (Procedural) vs. Object Orientation vs. Logic Programing vs. Event Driven Programming Paradigms Programming Libraries/Modules Command Line (Prompt) ASCII Functions Control Flow Hashes/Dictionaries List Comprehension True or False 2.   A dictionary is a random-access data structure. 3.   An array is a sequential access data structure. 4.   Using functions to isolate code is a good programming practice. 5.   Lexicographical ordering starts by comparing the first letters of two strings to determine the...
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....
Explain how each of the following transactions generates a credit and a debit in the American...
Explain how each of the following transactions generates a credit and a debit in the American balance of payments accounts and described (BRIEFLY) how each entry would be classified: An American buys a share of German stock, paying by writing a check on an account with a Swiss bank. The Korean government carries out an official foreign exchange intervention in which it uses dollars held in an American bank to buy Korean currency from its citizens A tourist from Detroit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT