Вопрос

the language is: { An B(2n) Cn | where n>=0 }

I think it has, because you can process it like this: push A's, push B's, for each C pop three times from stack, if there are no C's and stack is empty, return true, else return false.

Это было полезно?

Решение 2

Use the pumping lemma to prove this is not a context-free language.

Consider s = ap b2p cp
Then we consider vxy, |vxy|<=p, |vy|>0 and uvixyiz in L
We have the possibilities

  1. vxy = aj, j<=p
  2. vxy = aj bk, j+k<=p
  3. vxy = bj, j<=p
  4. vxy = bj ck, j+k<=p
  5. vxy = cj, j <=p

In any case, there are no constants u and v s.t. the string is in L, because there can only be two symbols in vxy and we would then need a variable amount of the third to show in up u or v

Your proposed automata fails on AAAC, returning true. It doesn't guarantee that you have twice as many B's as A's.

Другие советы

No such PDA exists because this language is not context-free. Here's a short proof of this. This relies on the fact that context-free languages are closed under inverse homomorphism (as mentioned in these slides).

Given the language L = { AnB2nCn | n in N }, consider the homomorphism h defined from

  • h(A) = A
  • h(B) = BB
  • h(C) = C

The inverse of this homomorphism, as applied to L, is the language h-1(L) = { x in Σ* | h(x) ∈ L }. Looking over the choice of h, this is the language { AnBnCn | n in N }. This language is a canonical example of a non-context-free language. Howver, the CFLs are closed under inverse homomorphism, so because h-1(L) is not context-free, L cannot be context-free. Therefore, there is no PDA for it.

Hope this helps!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top