Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 853
Jadyarun Avatar asked Oct 16 '15 16:10

Jadyarun


People also ask

What is concatenation in regular expression?

Concatenation: If R1 and R2 are regular expressions, then R1R2 (also written as R1. R2) is also a regular expression. L(R1R2) = L(R1) concatenated with L(R2). Kleene closure: If R1 is a regular expression, then R1* (the Kleene closure of R1) is also a regular expression.

What is concatenation in automata theory?

Concatenation. The concatenation of languages L and M, denoted L.M or just LM , is the set of strings that can be formed by taking any string in L and concatenating it with any string in M. Example. If L = {001, 10, 111} and M = {ǫ,001} then. L.M = {001, 10,111, 001001, 10001, 111001}

What is difference between union and concatenation?

CONCATENATION is equivalent to UNION-ALL . This combines the input tables and returns all the rows. UNION combines the input tables.

What's the difference between regular expressions and finite automata?

Finite automata are formal (or abstract) machines for recognizing patterns. These machines are used extensively in compilers and text editors, which must recognize patterns in the input. Regular expressions are a formal notation for generating patterns.


1 Answers

(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
like image 71
ryuu9187 Avatar answered Sep 23 '22 22:09

ryuu9187