0

I have this confusion related to regular expression. If there are two sets A and B then

is (AB)* = A*B*?

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
user34790
  • 2,020
  • 7
  • 30
  • 37
  • 1
    By "sets", do you mean character classes? – Andrew Clark Nov 13 '12 at 04:49
  • 1
    I’m voting to close this question because it is not about programming as defined in the [help center](https://stackoverflow.com/help/on-topic). Might be better suited at [cs.se] – Tomerikoo May 22 '21 at 14:24

2 Answers2

6

IN CONTEXT OF REGULAR EXPRESSION: is (AB)* = A*B*?

 No, (AB)* is not equals to A*B*

(AB)* means ABABABABAB......AB A sequence of AB (any number of time).
A*B* means AAAA.....BBB...... Any number of A's followed by any number of B's. And A can't appear after B's.

Intersection - Both includes { NULL string, AB } only


Example:

Suppose: A = xy , and B = z

  (AB)* = xyzxyz.....xyz  
  A*B*  =  xyxyxyxy....zzzz....z

Intersection - Both includes { NULL string, xyz} only.


Example:

Suppose -

  A = {a, b},  
  B = {c, d}  

Then,

(AB)* =  ((a + b)(c + d))* , Its language  
L =  { ac, ab, acbd, acac, .....}   

NOTE: All string in this language are of even length!

And

A*B*  =   (a + b)* (c + d)* , Its language     
  L = { a, b, c, d, ac, ad, bc, bd, acbd, addb,.........}   

NOTE: Also contains odd length strings.

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
1
(AB)* = A*B*  ?

No. The first is the language

 {void, ab, abab, ababab, ...}

the second is the language

{void, a, b, aa, ab, bb, aaa, ...}
alinsoar
  • 15,386
  • 4
  • 57
  • 74