Question

In: Computer Science

Consider the two languages below: L1 = {w | w є {0,1,2}* and is of the...

Consider the two languages below:
L1 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0 and i = j or j = k}
L2 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0}
One of the languages in the above problem is regular. Which one? Prove it.
Prove that the OTHER one is not regular.
Is the non-regular one context free? Prove it

Solutions

Expert Solution

In the given question, we have 2 languages L1 and L2. We need to find,the language is regular or not .And if the language is not regular we need to check it is CFL or not.

Solution: We can't construct DFA or NFA for a non regular language. Since,finite automata do not have auxiliary memory ,it can not be constructed for languages where memory is required Here,in L1 we need i = j or j=k (number of 0 is equal to number of 1 or number of 1 is equal to number of 0).Since we can't store number of times 0s,1s or 2s have appeared in any string present in language L1, it is impossible to compare the number of 0s with 1s or 1s with 2s.Thus ,the language L1 is not regular.Moreover , construction of DFA or NFA for language L1 is not possible .Hence it can be said that the language L1 is not regualr.

The langue L1 can be constructed using a single stack. Since in L1 we need i=j or j=k,we can use a single stack for developing the language. Let us take an example of string in language L1. String S1=00112(i = j) or S2= 01122 ( j = k).

Now, if we scan string S1 from left to write and push all 0s into the stack .

After the 0s are pushed into the stack , we perform pop aperation for each 1 we encounter.

If the stack is empty as we encounter the last 1 in the scanning of string it means that the number of 0s in the given string is equal to number of 1s.

Now ,we can simply scan 2s and reach to the end of string as there are no condition attach to the number of 2s in the given string . The image below shows ,how push and pop operation can be performed using string S1.

Similar operation can be performed to contruct string S2 .

Thus , we can construct strings in L1 with single stack. And if a language can be constructed using a single stack than it is CFL.

So, Language L1 is not regular but it is CFL.

Language L2 is regualr. Language L2 includes all strings where 1,2 and 3 are in order 123 and has nothing to do with the numbers of 1s ,2s and 3s. Here , we can easily construct DFA and NFA for language L2. Since DFA and NFA can be constructed only for regular language,it can be said that language L2 is regualr. The image below shows NFA and DFA for language L2.

So in the given question ,L1 is CFL and L2 is regular


Related Solutions

Consider the two languages below: L1 = {w | w є {0,1,2}* and is of the...
Consider the two languages below: L1 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0 and i = j or j = k} L2 = {w | w є {0,1,2}* and is of the form 0i1j2k where i, j and k ≥ 0} One of the languages in the above problem is regular. Which one? Prove it. Prove that the OTHER one is not regular. Is the non-regular one context...
Give examples of languages L1 and L2 over {a, b} that satisfy the descriptions below: (a)...
Give examples of languages L1 and L2 over {a, b} that satisfy the descriptions below: (a) L1 is regular, L2 is nonregular, and L1 U L2 is regular; (b) L1 is regular, L2 is nonregular, and L1 U L2 is nonregular; (c) L1 is regular, L2 is nonregular, and L1 n L2 is regular; (d) L1 is nonregular, L2 is nonregular, and L1 U L2 is regular. (e) L1 is nonregular, L2 is nonregular, and L1 n L2 is regular.
Consider the following languages: A = {w: |w| > k, where k is a constant integer}...
Consider the following languages: A = {w: |w| > k, where k is a constant integer} B = {ε,0,1, 10, 001} (The complement of A) (The complement of B) (True/False)                    A is regular (True/False)                    B is regular (True/False)                     is regular (True/False)                      is regular   2.  If A is regular, and  A  = A, then B must be not regular. True or False 3. Given three languages A, B, C where . If both A and B are regular, then C must be regular. True or False Automata and...
Given two languages A and B, let A/B denote the language {w | w x ∈...
Given two languages A and B, let A/B denote the language {w | w x ∈ A for some x ∈ B}. Show that if A is a context-free language and B is a regular language, then A/B is a context-free language. hint (construct PDAs)
Draw the NFA for language L2 = { w | w ends in 12}. Alphabet {0,1,2}
Draw the NFA for language L2 = { w | w ends in 12}. Alphabet {0,1,2}
Consider the following languages over {0, 1}: L3 = {w : does not begin and end...
Consider the following languages over {0, 1}: L3 = {w : does not begin and end with same symbol and |w| £ 3} L4 = {w : w = wR, |w| £ 3} Enumerate the first 8 strings in the L-ordering of the following: L3 L4 L3 – L4 L4 – L3 L3L4 L4L3 L33 L4*
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}.
Consider two languages A and B where A is a context free language and B is...
Consider two languages A and B where A is a context free language and B is a regular language. Show that the set difference, A-B, must also be context free. Also show that B-A may not be context free
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list...
The intersection of two lists L1 and L2, L1 ∩ L2, is defined as the list containing elements in both L1 and L2 only. Given two sorted lists L1 and L2, write a function, called intersection, to compute L1 ∩ L2 using only the basic list operations. The intersection function is defined as follows template list intersection( const list & L1, const list & L2); C++
Consider two countries, A and B, that have the same technology given by Y=L1/2N1/2. The two...
Consider two countries, A and B, that have the same technology given by Y=L1/2N1/2. The two countries have the same land area. The population growth function in countries A and B are given by g(c)=5c and g(c)=4c, respectively. For the periods from 0 to T-1 the economies were separated and at their steady states. However, at the beginning of time T, the wall between the two countries collapsed and the two countires were merged. Making certain assumptions, plot the time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT