Deterministic and Non Determinstic Push Down automata
1. Context-Free Languages and Their Automata
-
Context-Free Languages (CFLs) are those generated by Context-Free Grammars (CFGs).
-
They are more powerful than regular languages, which are generated by finite automata.
-
Why finite automata are not enough?
-
A finite automaton has only finite memory.
-
Some CFLs (like { aⁿbⁿ : n ≥ 0 }) require counting an unbounded number of symbols.
-
Some others (like palindromes { wwᴿ }) require storing a sequence and matching it in reverse.
-
This motivates a stronger machine: the Pushdown Automaton (PDA).
-
A PDA is like an NFA but with an extra stack memory.
-
The stack provides unbounded storage but in a restricted LIFO (Last-In-First-Out) way.
2. Nondeterministic Pushdown Automata (NPDA)
-
Definition: An NPDA is like a nondeterministic finite automaton (NFA) with an added stack.
-
The PDA can:
-
Read the current input symbol (or ε = empty move).
-
Look at the top of the stack.
-
Based on these, decide nondeterministically what to do:
-
Push a symbol onto the stack,
-
Pop the stack,
-
Or leave it unchanged.
-
-
-
Key Result :
-
Every CFL can be recognized by some NPDA.
-
Every NPDA recognizes a CFL.
-
Thus, NPDA ⇔ CFL.
-
So, nondeterminism is crucial: with it, PDAs exactly capture the family of CFLs.
3. Deterministic Pushdown Automata (DPDA)
-
A DPDA is restricted:
-
For any given configuration (state, input symbol, top of stack), there must be at most one possible move.
-
No nondeterministic choices are allowed.
-
No simultaneous ε-move and input-move from the same configuration.
-
-
Observation:
-
DPDAs cannot recognize all CFLs.
-
Example: The language { aⁿbⁿcⁿ : n ≥ 0 } is not CFL at all. But even within CFLs:
-
{ aⁿbⁿ : n ≥ 0 } is deterministic.
-
Palindromes { wwᴿ } require nondeterminism, so not recognized by DPDA.
-
-
-
Key Result :
-
DPDA languages = Deterministic CFLs (DCFLs).
-
DCFLs ⊂ CFLs (proper subset).
-
4. Why the Distinction Matters
-
For regular languages, DFA = NFA (deterministic and nondeterministic are equivalent).
-
For context-free languages, DPDA ≠ NPDA.
-
This asymmetry is one of the main conceptual differences between finite automata and pushdown automata.
-
Programming Languages:
-
Most programming languages are designed to be deterministic context-free languages (DCFLs).
-
This is important because parsers (like LR, LL parsers) are based on deterministic PDAs.
-
5. Summary Table
Machine | Memory | Determinism | Language Class | Notes |
---|---|---|---|---|
DFA/NFA | None (finite states only) | Equivalent | Regular Languages | DFA = NFA |
NPDA | Stack (LIFO) | Nondeterminism allowed | CFLs | NPDA ⇔ CFG |
DPDA | Stack (LIFO) | Deterministic only | DCFLs ⊂ CFLs | Not all CFLs are DCFLs |
Key Difference (NPDA vs DPDA)
-
NPDA: δ may give multiple possible next moves (nondeterministic choices).
-
DPDA: δ must give at most one move for each configuration.
Comments
Post a Comment