0
$\begingroup$

How to design Push Down Automata for a language that has equal number of a's and b's where $n \ge 1$?

I got how to do it for $n \ge 0$, not able to get it for $n \ge 1$.

$\endgroup$
0

1 Answer 1

0
$\begingroup$

The intersection of a context-free language and a regular language is also context-free, and this can be shown using the same Cartesian-product-machine construction used to show the intersection of two regular languages is also regular. This construction gives you a way of finding the PDA for the intersection of a context-free language and a regular language, if a PDA and DFA are known.

A DFA for the language of strings that are non-empty is easy: it has two states, q0 and q1, with q1 accepting and q0 not, and all transitions go to q1.

You say you already have a PDA for the language of strings where #a(w) = #b(w); call its states Q, its accepting states A, its initial state q*, its alphabet S, its stack alphabet Z and its transitions f: Q x S x Z -> Q x Z.

We can define a PDA that accepts the intersection of non-empty strings with the strings that have #a(w) = #b(w) as follows:

  1. Q' = {q0, q1} x Q
  2. A' = {(q1, q) | q in A}
  3. S' = S
  4. Z' = Z
  5. f'(q, s, z) = ((q1, q'), z') where (q', z') = f(q, s, z)
  6. initial state (q0, q*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.