Search code examples
regular-language

Regular expressions and automata


I'm studying Regular Expressions by reading Aho's book. I don't understand two of the statements in the book:

Question A:

1(0+1)*1 + 1 : denotes the set of all strings beginning and ending with a 1.

My question why is +1 added at end of the regular expression? Shouldn't 1(0+1)*1 be sufficient?


I'm also having trouble with the following:

Question B:

The set of strings containing only 0's and 1's that have atmost one 1 as below

    0*+0*10* 

Can you explain how the solution 0*+0*10* is arrived at, step by step?


Solution

  • For Question a: 1(0+1)*1 denotes set of all strings beginning and ending with one but does not contain string 1 which has length one and starts and ends with one.

    For Question b: Set of strings containing atmost one 1 = A + B where A is set of all strings containing zero 1s and B is the set of all strings containing exactly one 1

    So A is 0* and B is 0*10* Hence we get the answer as 0* + 0*10*