Reputation: 11
w = w^R means the reverse of w is the same as w
I am trying to create a push down automaton for L = {w ∈ {a, b}∗ | (w = w^R) and number of a’s = number of b’s}.
I have the PDA for equal number of a's and b's and PDA for a palindrome. Is trying to combine them the right step?
Upvotes: 1
Views: 1913
Reputation: 28322
We will prove this language is non context-free using the pumping lemma for context-free languages. Assume the language were context-free. Then, by the pumping lemma for context-free languages, any word w in the language could be written w = uvxyz where the following hold:
Consider the string (a^p)(b^1.5p)(a^p)(b^1.5p)(a^p) in the language (it has the same number of a as b and it's the same forward as backward). There are various cases for the substring vxy:
All remaining cases are perfectly symmetric to the ones already covered. This means there is no choice for vxy such that pumping gives us strings in the language. This is a contradiction, so our assumption about the language being context-free was wrong.
We relied on |vxy| <= p for this to keep the number of cases small and make pumping fail. If we picked the middle segment of a to have length less than p - 2, this wouldn't have worked since we could have chosen v = (b^n)(a^n) and y = (a^n)(b^n) and it would have pumped just fine.
Upvotes: 1