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:

{Languages accepted by NPDAs}={Context-Free Languages}\{ \text{Languages accepted by NPDAs} \} = \{ \text{Context-Free Languages} \}

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):

    A    aX1X2XkA \;\to\; aX_1X_2 \cdots X_k

    This form is useful because every production begins with a terminal, which matches nicely with how the PDA reads input.

Construction

  1. The PDA pushes the start symbol onto the stack.

  2. 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.

  3. 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 MM.

  • We want to construct a CFG GG such that L(G)=L(M)L(G) = L(M)

  • The grammar simulates the moves of the PDA.

The trick:

  • A variable of the form [pAq][p A q] means: “the PDA can go from state pp with AA on top of the stack to state qq 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 

  1. For every context-free language, there exists a nondeterministic PDA that accepts it.

  2. 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

Popular posts from this blog

Theory Of Computation PCCST302 KTU Semester 3 BTech 2024 Scheme

Non deterministic Finite Automata NFA

Formal Definition - Turing Machine