regexkleene-star

Automata Regular expression - difference between concatenation & union


What is the difference between the following regular expressions? (a U b)* and (ab)*

Difference between union and concatenation ? which of the above regex accepts strings in which 'a' is always before 'b' ?

Please clarify.. Thanks in advance.


Solution

  • (ab)* means zero of more instances of the sequence ab. For example,

    <empty>, ab, abab, ababab
    

    Consider a* and b*:

    a*: <empty>, a, aa, aaa, aaa, ...
    b*: <empty>, b, bb, bbb, bbb, ...
    

    Concatenation is to add one set onto another. a* concat b* would be concatenating the sequence resulting from a* with the one resulting from b*, so:

    <empty>, ab, aab, abb, aaaabbbb, bbbbb
    

    Union is to combine two sets and results in the distinct results.So, a* U b* would be the regular expressions of zero or more instances of a and zero or more instances of b:

    <empty>, a, aa, aaa, aaaa, b, bb, bbb, bbbb