$\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. Show 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 LC= Set 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)* 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. 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.
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 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 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 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 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 8. The production of the form no terminal → Λ is said to be null production. a) False b) True View Answer Answer: b Sanfoundry Global Education & Learning Series – Compilers. To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.
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. |