Language Accepted By a Push Down Automata
Definition: Language Accepted by a Pushdown Automata
Let
be a nondeterministic pushdown automaton (NPDA), where:
-
: set of states
-
: input alphabet
-
: stack alphabet
-
: transition function
-
: initial state
-
: initial stack symbol (bottom-of-stack marker)
-
: set of final states
Language Accepted by Final State
The language accepted by M is defined as:
Explanation (in words)
-
Start in initial configuration:
-
State =
-
Input = entire string
-
Stack = just the start symbol
-
-
Apply transitions according to , consuming input and modifying the stack.
-
If, after reading all input symbols ( left), the automaton is in a final state (), then w is accepted.
-
The final stack content u does not matter (it can be empty or non-empty).
Important Point
-
This definition of acceptance is called acceptance by final state.
-
There is another notion: acceptance by empty stack, where a string is accepted if the stack becomes empty (regardless of final state).
-
Peter Linz later proves that both definitions are equivalent: every language accepted by empty stack can also be accepted by final state and vice versa.
A PDA accepts a string if it can consume the entire input and enter a final state. The remaining stack content does not matter in this definition.
Example:
1. The Problem
We want to construct an NPDA for the language:
That is, the set of all strings with the same number of a’s and b’s, regardless of order.
Examples:
-
Accepted:
ab,ba,aabb,abab,baab, … -
Not accepted:
aab,bba,aaabb, …
2. Why Finite Automata Fail
A finite automaton cannot solve this, because it needs to count arbitrarily many a’s and b’s, which requires unbounded memory.
So, we use a pushdown automaton (NPDA) with a stack.
3. The Idea of the NPDA
We use the stack as a counter, with two different stack symbols:
-
0→ represents one unmatcheda. -
1→ represents one unmatchedb.
Rules:
-
When we see an
a:-
If there’s a
1on top (an unmatchedbwaiting), pop it. -
Otherwise, push a
0(record an unmatcheda).
-
-
When we see a
b:-
If there’s a
0on top (an unmatchedawaiting), pop it. -
Otherwise, push a
1(record an unmatchedb).
-
At the end:
-
If all
a’sandb’sare matched, the stack returns to bottom markerZ₀. -
If input finished and stack has only
Z₀, accept.
4. Transition Graph
-
States:
-
q0= start and processing state -
qf= accepting state
-
-
Transitions (informal):
-
On
awith topZ→ push0Z -
On
awith top0→ push another0 -
On
awith top1→ pop the1 -
On
bwith topZ→ push1Z -
On
bwith top1→ push another1 -
On
bwith top0→ pop the0 -
On ε, with top
Z→ move toqf
-
5. Example Run: Input = baab
Let’s trace step by step:
Initial config: (q0, baab, Z)
-
Read
b: top isZ→ push1→(q0, aab, 1Z) -
Read
a: top is1→ pop1→(q0, ab, Z) -
Read
a: top isZ→ push0→(q0, b, 0Z) -
Read
b: top is0→ pop0→(q0, ε, Z) -
Input finished, stack = Z → ε-move to accept.
✅ baab is accepted.

Comments
Post a Comment