The regular expression have all strings of 0 s and 1 s with no two consecutive 0 s is

$\begingroup$

I'm having trouble figuring out a regular expression over the alphabet {0,1} that contains all strings with no TWO consecutive 1's.

I'm also wondering if there is a pattern that could be extended to three consecutive 1s. etc...

Would something like this be correct?

(0 U (10))* U (0 U (10))* 1

$\endgroup$

4

L = set of all string no consecutive 1’s where = {0, 1}.

Answer:

Given a language, L = set of all string no consecutive 1’s i.e. 11.

But it is not very easy to design the above machine because the language of this machine has negation. Negation machine is quite difficult to design.

We previously discussed how to design the negation machine.

Steps to design a negation machine:

Step 1. First, do complement of the given negation language L to a non-negative language LC.

L= Set of all string no consecutive 1’s

LCSet of all string containing two consecutive 1’s

Step 2. Design a machine for LC = Set of all string containing two consecutive 1’s

 LC = {11, 011, 110, 111, 1111, ……}

Regular Expression RE(0 + 1)* 11 (0 + 1)* 

The regular expression have all strings of 0 s and 1 s with no two consecutive 0 s is

M1: Machine Set of all string containing two consecutive 1’s

Another Regular Expression from machine = (010)*1(0 + 1)* 

Step 3. The complement of M1 for the original machine i.e. set of all strings no two consecutive ones.

The regular expression have all strings of 0 s and 1 s with no two consecutive 0 s is

M2: Machine “Set of all string containing two consecutive 1’s

RE = (0 + 10)* + (0 + 10)*1 = (0 +10)* (λ + 1) = (λ + 1) (0 + 10)* 

See the RE = (0 + 10)*is the all combination of strings now we want all string but no consecutive 1’s. Every time when 1 is coming and we put zero (0) be for or after then never consecutive 1’s is possible.

(0 + 10)* in this the last zero prevents making consecutive 1’s because every time when 1 came the zero is coming after that. So, never consecutive 1’s is possible.

But here (0 + 10)* every time string which ends with 0 but there is no string end start with 1. So we put (λ + 1). RE = (0 + 10)*(λ + 1), now string end with 0 or end with 1’s.

15.Consider the production of the grammar S->AA A->aa A->bb Describe the language specified by the production grammar.
a.L = {aaaa,aabb,bbaa,bbbb}
b.L = {abab,abaa,aaab,baaa}
c.L = {aaab,baba,bbaa,bbbb}
d.L = {aaaa,abab,bbaa,aaab}

Page 2 of 15

Please log in or register to add a comment.

Please log in or register to answer this question.

Please log in or register to add a comment.

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Regular Expression – 2”.

1. The RE in which any number of 0′s is followed by any number of 1′s followed by any number of 2′s is? a) (0+1+2)* b) 0*1*2* c) 0* + 1 + 2 d) (0+1)*2*

View Answer

Answer: b
Explanation: The order for the desired string is 012 and for any number of 0s we write 0* for any number of 1s we denote it by 1* and similarly for 2*.Thus 0*1*2*.

2. The regular expression have all strings of 0′s and 1′s with no two consecutive 0′s is? a) (0+1) b) (0+1)* c) (0+∈) (1+10)* d) (0+1)* 011

View Answer

Answer: c
Explanation: From the former bracket we choose 0 or epsilon. Then from the latter part 1 or 10 which can be followed by 1 or 10.

3. The regular expression with all strings of 0′s and 1′s with at least two consecutive 0′s is? a) 1 + (10)* b) (0+1)*00(0+1)* c) (0+1)*011 d) 0*1*2*

View Answer

Answer: b
Explanation: The expression (0+1)*00(0+1)* is where either it initially takes 0 or 1 or 00 followed by string of combination of 0 and 1.

4. Which of the following is NOT the set of regular expression R = (ab + abb)* bbab? a) ababbbbab b) abbbab c) ababbabbbab d) abababab

View Answer

Answer: d
Explanation: abababab doesn’t end with bbab whereas the other 3 options satisfy the given regular expression.

5. String generated by following expression is?

S->aS/bA, A->d/ccA

Check this: MCA MCQs | Compiler Design Books

a) aabccd b) adabcca c) abcca d) abababd

View Answer

Answer: a Explanation: S->aS (substitute S->aS) S->aaS (substitute S->bA) S->aabA (substitute A->ccA) S->aabccA (substitute A->d)

S->aabccd.

6. Consider the production of the grammar S->AA A->aa A->bb Describe the language specified by the production grammar. a) L = {aaaa,aabb,bbaa,bbbb} b) L = {abab,abaa,aaab,baaa} c) L = {aaab,baba,bbaa,bbbb} d) L = {aaaa,abab,bbaa,aaab}

View Answer

Answer: a Explanation: S->AA (substitute A->aa) S->aaaa S->AA (substitute A->aa ) S->aaA (substitute A->bb) S->aabb S->AA (substitute A->bb the A->aa) S->bbaa S->AA (substitute A->bb)

S->bbbb.

7. If R is regular language and Q is any language (regular/ non regular), then Pref (Q in R) is _____________ a) Non-regular b) Equal c) Infinite d) Regular

View Answer

Answer: d
Explanation: So says the definition of Regular Grammar.

8. The production of the form no terminal → Λ is said to be null production. a) False b) True

View Answer

Answer: b
Explanation: Here the non terminal that gives null will said to have a null production.

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

The regular expression have all strings of 0 s and 1 s with no two consecutive 0 s is

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.