• edited by
13,091 views
34 34 votes

Which of the following regular expressions describes the language over$\{0, 1\}$ consisting of strings that contain exactly two $1$'s?

  1. $(0 + 1)^ * \ 11(0 + 1) ^*$
  2. $0 ^* \ 110 ^*$
  3. $0 ^* 10 ^* 10 ^*$
  4. $(0 + 1) ^* 1(0 + 1) ^* 1 (0 + 1) ^*$

4 Answers

Best answer
47 47 votes
  1. with at least $2$ consecutive $1$'s, any no of $0$'s and any no of $1$'s
  2. exactly two consecutive $1$'s
  3. exactly two $1$'s but need not be consecutive
  4. any no of $1$'s and $0$'s with at least two $1$'s


Hence, (C) is the correct option.

• edited by
14 14 votes
A. We can get any number of 1.

B.More strict .. means it is covering only one possibility of containing exactly two ones.eg. 0110 ,11  . But 0101 is also satisfying the condition which is not covered by option B.

C. It is covering all d possibility of containing exactly two one's . 101,11,0011,01010........

D. Any no. Of one we can take from here

 

So, answer is option C.
1 1 vote

Draw the Deterministic finite automata with all the transitions for ∑ = {0,1} for no. of 1’s equal to two and get it’s corresponding Regular expression.

0 0 votes

SINCE THE QUESTION ASKS FOR "STRINGS WITH EXACTLY TWO 1S" :

We solve as follows:

(A) and (D) options we see that it has (0+1)* which means that it can generate any no of 1s and 0s combination which completely violates our condition so both are wrong

Now coming to (B) and (C), IN (B) the 1s are forced nex to each other which means it misses on strings which has two 1s but both 1s are not together hence (C) is correct 

The language is defined as: "All strings over {0,1} that contain exactly two 1's."

Let's look at some valid strings that perfectly satisfy this definition:

  • String 1: 101 (It has exactly two 1's)

  • String 2: 01010 (It has exactly two 1's)

  • String 3: 10001 (It has exactly two 1's)

Now, try to generate any of these three strings using Trap B (0*110*):

  • You cannot. Because the two 1's in the expression are written directly next to each other (11), Trap B strictly forces the two 1's to be physically adjacent in every single string it creates.

By forcing the 1's to stick together, Trap B completely leaves out an infinite number of valid strings where the two 1's are separated by zeroes.

 

SUMMARY:

  • What 0*110* describes: The language of strings containing exactly two 1's that must appear consecutively (right next to each other).

  • What 0*10*10* describes: The true language of strings containing exactly two 1's anywhere in the string, separated by any number of zeroes.

When a regular expression leaves out valid strings that belong to the definition, it is incorrect, even if every string it does manage to generate happens to be legal!

Answer:
Position:
Show:

Related questions

46 46 votes
3 answers 3 answers
11.1k
11.1k views
Ishrat Jahan asked Oct 29, 2014
11,099 views
A Binary Search Tree (BST) stores values in the range $37$ to $573$. Consider the following sequence of keys.$81, 537, 102, 439, 285, 376, 305$$52, 97, 121, 195, 242, 381...
47 47 votes
3 answers 3 answers
11.8k
11.8k views
Ishrat Jahan asked Oct 28, 2014
11,815 views
Match the following flag bits used in the context of virtual memory management on the left side with the different purposes on the right side of the table below.$$\small ...
34 34 votes
4 answers 4 answers
9.2k
9.2k views
Ishrat Jahan asked Oct 28, 2014
9,155 views
If the time-slice used in the round-robin scheduling policy is more than the maximum time required to execute any process, then the policy willdegenerate to shortest job ...
33 33 votes
7 answers 7 answers
18.0k
18.0k views
Ishrat Jahan asked Oct 28, 2014
18,044 views
Consider the C program below. What does it print?# include <stdio.h # define swap1 (a, b) tmp = a; a = b; b = tmp void swap2 ( int a, int b) { int tmp; tmp = a; a = b; b ...