edited by
742 views
0 votes
0 votes

Give a regular expression for the set of binary strings where every $0$ is immediately followed by exactly $k$ number of $1's$ and preceded by at least $k$ number of $1's$ ($k$ is a fixed integer).Choose the correct one out of two.

  1. $1^*1^k(01^k)^*1^*$       
  2. $1^*(1^k01^k)^*$
edited by

1 Answer

1 votes
1 votes

None is Correct. The Correct Regular Expression for the language described, will be :

$1^* + 1^*1^k0(1^k0)^*1^k$

 The Condition is "followed by exactly k number of 1's"Exactly K number of 1's means that Not more than K 1's, Not less than K 1's after Every Zero. 

Because of this Condition, Only the First $0$ can be preceded by more than $k$ 1's. All the other Zeroes (i.e. Except the First Zero) will be both Preceded and followed by Exactly $k$ 1's.


Note that If R and S are any Two RE then $R(SR)^*$ and $(RS)^*R$ Always denote the same language. Same logic can be applied here and the above RE can also be written as follows :

$1^* + 1^*1^k(01^k)^*$

Credit : @Bhanukumar

edited by