Is (a|b)* the same as a*|b*?
Asked Answered
T

3

8

Is (a|b)* the same as a*|b*? In other words, does (a|b)* accept string which are combinations of as and bs?

Thurmond answered 15/7, 2014 at 17:48 Comment(2)
I'm Mr. Meeseeks, look at meee!Slowworm
@meeseeks wubalubadubdub!!!Thurmond
D
11

Is (a|b)* the same as a*|b*?

They are not the same.

  • a*|b* means "(0 or more as) or (0 or more bs)"

  • (a|b)* means "0 or more (a or b)s"

So, for example, ab will be matched by (a|b)* but not by a*|b*. Note also that anything matched by a*|b* will also be matched by (a|b)*.

Dionysus answered 15/7, 2014 at 17:50 Comment(0)
L
9

No.

In case of (a|b)*, you can mix As and Bs (see demo).

In case of a*|b*, you can have either As or Bs (see demo).

Lindo answered 15/7, 2014 at 17:50 Comment(0)
B
0

a*|b* denotes {ε, "a", "b", "aa", "bb", "aaa", "bbb", ...}

(a|b)* denotes {ε, "a", "b", "aa", "ab", "ba", "bb", "aaa", aab, abb, aba, baa ...}

ε denote empty

Bobseine answered 9/11, 2021 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.