Using pumping lemma, we can easily prove that the language L1 = {WcW^R|W ∈ {a,b}*}
is not a regular language. (the alphabet is {a,b,c}; W^R represents the reverse string W)
However, If we replace character c
with "x"(x ∈ {a,b}+)
, say, L2 = {WxW^R| x, W ∈ {a,b}^+}
, then L2 is a regular language.
Could you give me some ideas?
The question says W ∈ {a,b}^+ , so a^n(a+b)a^n should be in the language L2. Now there is no such DFA that will accept the string a^n(a+b)a^n because, after accepting n number of a and (a+b)^+, there is no way for the dfa to remember exactly how many a it accepted in the begining, so L2 should not be regular.........But every where i search for this answer it says it is regular.....this bugs me
Yes,
L2
is Regular Language :).You can write regular expression for
L2
too.Language L2 = {WXWR| x, W ∈ {a,b}+} means:
a
andb
that isW
and end with reverse string WR.a
orb
)a
andb
in middle that isX
. (because of+
, length ofX
becomes greater than one|X| >= 1
)Example of this kind of strings can be following:
aabababa, as follows:
or it can be also:
babababb, as follows:
See length of
W
is not a constraint in language definition.so any string WXWR can be assume equals to
a(a + b)
+a
orb(a + b)
+b
or
And Regular Expression for this language is:
a(a + b)
+a
+
b(a + b)
+b
Don't mix
WXW
R withWCW
R, itsX
with+
that makes language regular. Think by includingX
that is(a + b)*
we can have finite choice forW
that isa
andb
(finite is regular).Language
WXW
R can be say: if start witha
ends witha
and if start withb
end withb
. so correspondingly we need two final states.W
isa
W
isb
ITs DFA is as given below.
Any string in the language with |W| > 1 can be interpreted as a string in the language where |W| = 1. Thus, a string is in the language if it begins and ends with the same symbol. There are two symbols: a and b. So that language is equivalent to the language
a(a+b)(a+b)*a + b(a+b)(a+b)*b
. To prove this, you should formalize the argument that "if y is in WxW, then y is in a(a+b)(a+b)*a + b(a+b)(a+b)*b; and if y is in a(a+b)(a+b)*a + b(a+b)(a+b)*b, then y is in WxW".It doesn't work in the other case since c is a fixed symbol, and can't include all but the characters on the ends. As soon as you bound the length of "x" in your example, the language becomes non-regular.