Confusion related to regular expression

为君一笑 提交于 2020-01-25 00:57:27

问题


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

is (AB)* = A*B*?


回答1:


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.




回答2:


(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, ...}


来源:https://stackoverflow.com/questions/13355710/confusion-related-to-regular-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!