Question

In: Computer Science

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}.

Solutions

Expert Solution

See when you are trying to make a regular expression you want to see things with your result. First, it should be able to accept all the strings that you want to accept, and second, it should not accept any unwanted strings. Understood, now let's try to make some regular expressions.

a) {w ' {0,1}* | w corresponds to the binary encoding of non-negative integers that are evenly divisible by 4}

This is easy we just need to understand what it means. See when we are writing binary no.'s each bit is assigned a value. The assigned values are as follows (from LSB to MSB):-

1, 2, 4, 8 , 16, 32, 64, .....

See just the least two values, i.e., 1 & 2 are the values that are not divisible by 4 rest all the values are divisible by 4. So if we want our no.'s to be divisible by 4 we need to make those two bits 0. So we can say that we need to accept all the strings that end with two 0's. Before that, we can accept anything.

So the regular expression will be:-

(1+0)*00

b) {w ? {a,b}* | w contains at least one 'a' and exactly two b's}

w is supposed to contain exactly 2 b's so we need to fix that, but the no. of a's only have the lower limit that is it should have at least one a.

When stuck try making the smallest strings with some other strings that you want to accept through your regular expression, or you can also try making the DFA for the language.\

The regular expression will look like this:-

a(a*ba*ba*) + b (ba + aa*b)a*

c) {w ? {0, 1, 2}* | w starts with a 2, ends with a 1 and contains an even number of 0's}

This one is easy again.

2(00)*1

Hope this helps. If you like the answer please upvote. If you have any queries or suggestions regarding the answers please leave them in the comments section so I can update and improve the answer. Thank you


Related Solutions

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...
Are the following languages over {a, b} regular? If they are then prove it. If they...
Are the following languages over {a, b} regular? If they are then prove it. If they are not prove it with the Pumping Lemma a) {ap | p is a prime number} b) {xax | x Î{a,b}*} (start by listing some strings in, not in, the language
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output please. A blank line (may contain spaces) Postal abbreviation (2 letters) for State followed by a space and then the 5-digit zip code A KU student username (Ex. lpork247) A “valid” email address (also explain how you defined “valid”) A SSN pattern (ddd-dd-dddd)
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the...
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the intended match. ^[^A-Z] 17. Regular Expression: Given the following regular expression, provide a description of the intended match. [^^!] 18. Regular Expression: Given the following regular expression, provide a description of the intended match. ^.\{72\}$ 19. Regular Expression: Given the following regular expression, provide a description of the intended match. [A-Za-z0-9] 20. Regular Expression: Given the following regular expression, provide a description of the...
submit a regular expression that will identify each of the following patterns. 1 - a US...
submit a regular expression that will identify each of the following patterns. 1 - a US telephone number that conforms to the following pattern 111.222.3456 2 - a US social security number that fits the following pattern 111-22-3456 3 - an American Express credit card number that fits the following format:       4 digits followed by a space followed by 6 digits followed by a space followed by 5 digits False positives are allowed in each case, so all you need...
Consider the following regular expression meta operators: ( ) [ ] { } . * +...
Consider the following regular expression meta operators: ( ) [ ] { } . * + ? ^ $ | \ For each of the following, give one example of strings which the regular expression would match. Describe (colloquially, in a manner that a non-technical person would understand) the set of strings that the pattern is designed to match. Each regular expression is enclosed in the pair of '/' characters below. [2 marks each] (a) /^[a-z][0-9]*\.$/ (b) /([0-9]+)\s\w+\s\1/
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”....
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”. 2. What is degree centrality? Create a graph of 4 vertices and compute the degree centrality of the vertices. 3. Compute internal and external community densities for a graph containing 6 nodes. You can create any graph of 6 nodes with at least 4 edges.
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}
Use the pumping lemma to show that the following languages are not regular. A a. A1={0^n...
Use the pumping lemma to show that the following languages are not regular. A a. A1={0^n 1^n 2^n | n≥0} b. A2 = {www | w ∈ {a,b}∗} A c. A3 ={a^2^n | n≥0} (Here, a^2^n means a string of 2^n a’s.) A ={a3n |n > 0 }
Use the pumping lemma to show that the following languages are not regular (c) (5 pts)...
Use the pumping lemma to show that the following languages are not regular (c) (5 pts) Let Σ = {0, 1, −, =} and SUB = {x = y − z | x, y, z are binary integers, and x is the result of the subtraction of z from y}. For example: 1 = 1 − 0, 10 = 11 − 01 are strings in SUB but not 1 = 1 − 1 or 11 = 11 − 10.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT