Give a regular expression for $A = \{1^{k}y|k \geq 1, y \in \{0,1\}^{*}$ and $y$ contains at least $k$ $1$'s $\}$

770 Views Asked by At

The regular expression that is given is $1(0 \cup 1)^{*}10^{*}$. I'm having trouble realizing why this regular expression describes the language given. For example, the string (for $k$ = 4) $1111$ $1111$ $01101010$ is in the language, but I don't see how this can be derived from the regular expression. In particular, the part that says there are at least $k$ $1$'s doesn't seem to be satisfied in the regular expression. Any clarifications will be appreciated.

1

There are 1 best solutions below

7
On BEST ANSWER

The definition of $A$ is misleading. There is no reason to ever have $k>1$. Think of it as $$A=\{1y|y\in\{0,1\}^\star\textrm{ and }y\textrm{ contains at least one }1\}$$


The question from the commments is why does the regular expression equal this. There are many ways to express a string that contains at least one 1. $(0\cup 1)^\star10^\star$ is one such way; the mandatory 1 is of necessity the last 1 in the string, since it is followed only by zeroes. Another, more natural way, is $(0\cup 1)^\star 1 (0\cup 1)^\star$. Another way is $0^\star 1 (0\cup 1)^\star$; now the mandatory 1 is the first 1 in the string.