Non Deterministic Push Down Automata and Context Free Languages
📌 NPDA
The relationship between pushdown automata (PDA) and context-free languages (CFLs) is exactly analogous to the relationship between finite automata and regular languages:
-
Every CFL can be accepted by some nondeterministic PDA (NPDA).
-
Every language accepted by a NPDA is a CFL.
So:
This is why PDAs are the machine model for CFLs.
📌 Direction 1: From CFG → NPDA
We want to show: For every context-free grammar, there is an NPDA that accepts the same language.
Key Idea
-
A PDA has a stack, which is like "memory".
-
To accept a CFL, the PDA can simulate the derivation of the grammar using the stack.
-
For simplicity, we use a grammar in Greibach Normal Form (GNF):
This form is useful because every production begins with a terminal, which matches nicely with how the PDA reads input.
Construction
-
The PDA pushes the start symbol onto the stack.
-
At each step, it looks at the top of the stack:
-
If the top is a variable (nonterminal), the PDA nondeterministically chooses a production rule and replaces the variable with its RHS (pushes the RHS).
-
If the top is a terminal and matches the next input symbol, the PDA pops it and consumes the input.
-
If there is a mismatch, that branch fails.
-
-
If the input is completely read and the stack is empty, the PDA accepts.
📌 Direction 2: From NPDA → CFG
Now we show: Every language accepted by an NPDA is context-free.
Idea
-
Suppose we have an NPDA .
-
We want to construct a CFG such that
-
The grammar simulates the moves of the PDA.
The trick:
-
A variable of the form means: “the PDA can go from state with on top of the stack to state after completely processing that portion of input.”
-
Productions are added to capture the possible transitions.
Though technical, the result guarantees that for every PDA, there exists such a CFG.
📌 The Two Major Results
-
For every context-free language, there exists a nondeterministic PDA that accepts it.
-
For every nondeterministic PDA, the language it accepts is context-free.
Thus, CFLs = Languages accepted by NPDAs.
⚠️ Note: This equivalence only holds for nondeterministic PDAs.
Deterministic PDAs (DPDA) accept only a proper subset of CFLs, called deterministic CFLs (important in programming languages).
✅ In summary:
Pushdown Automata are the machine counterpart of context-free languages. The stack in a PDA provides the necessary unbounded memory to handle things like balanced parentheses, matching a^n b^n
, or palindromes, which finite automata cannot manage.
Comments
Post a Comment