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$.
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityThe 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: