Pushdown automata and properties of context free languages — Unit 4 Notes (Theory of Automata and Formal Languages)

BCS404 · Unit 4

Pushdown automata and properties of context free languages notes — Unit 4

Free unit-wise study notes on pushdown automata and properties of context free languages for Theory of Automata and Formal Languages, Semester 4 of B.Tech — Computer Science & Engineering — key concepts, examples, important questions and a revision checklist for semester exams.

Adding memory to the machine. Covers the formal 7-tuple definition of Pushdown Automata (PDA), Acceptance by Final State vs Empty Stack, equivalence of CFG and PDA, and the CFG Pumping Lemma to prove languages are not Context-Free.

Notebook — 9 pages

Page 1

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

1. Introduction to Pushdown Automata (PDA)

A DFA cannot count because it has no memory. It cannot recognize anbna^n b^n.

To process Context-Free Languages (CFLs), we upgrade the DFA by attaching an infinite memory structure: a Stack. This new machine is a Pushdown Automaton (PDA).

1.1 The Stack Mechanism

The memory is strictly LIFO (Last-In, First-Out). The machine can only read, push, or pop the absolute top symbol of the stack. It cannot look deep inside the stack.

How does a PDA solve anbna^n b^n?
1. As it reads the 'a's, it PUSHES an 'A' onto the stack for every 'a' it sees.
2. When the 'b's start, for every 'b' it reads, it POPS one 'A' off the stack.
3. When the string ends, if the stack is exactly empty, it mathematically proves the number of 'a's exactly matched the 'b's.

Next — Formal Definition of a PDA

1 of 9

Page 2

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

2. Formal 7-Tuple Definition of a PDA

A Pushdown Automaton is mathematically defined as a 7-tuple:
M=(Q,Σ,Γ,δ,q0,Z0,F)M = (Q, \Sigma, \Gamma, \delta, q_0, Z_0, F)

  • QQ: A finite set of states.
  • Σ\Sigma: The input alphabet (the tape symbols).
  • Γ\Gamma (Gamma): The Stack Alphabet. A finite set of symbols that are allowed to be pushed onto the stack. It can be completely different from Σ\Sigma.
  • q0q_0: The start state.
  • Z0Z_0: The Initial Stack Symbol. When the machine boots up, the stack is never truly empty; it contains this single bottom marker symbol. (Z0ΓZ_0 \in \Gamma).
  • FF: The set of accepting final states.

2.1 The Transition Function (δ\delta)

The brain of the PDA is significantly more complex than a DFA. It makes decisions based on THREE factors:
1. The current State.
2. The current Input Symbol being read (or
ϵ\epsilon).
3. The current symbol at the TOP of the Stack.

δ(q,a,X)\delta(q, a, X) outputs a set of pairs (p,γ)(p, \gamma), meaning: "Go to state pp, pop XX, and push the string γ\gamma onto the stack".

Next — Determinism in PDA

2 of 9

Page 3

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

3. Deterministic vs Nondeterministic PDA

In Unit 1, we proved DFA \equiv NFA. They have the exact same computing power.

This is absolutely FALSE for Pushdown Automata.

3.1 DPDA vs NPDA

A Deterministic PDA (DPDA) has strictly one valid move for any combination of State, Input, and Top-of-Stack. It cannot guess.

A Nondeterministic PDA (NPDA) can guess. It can branch.

Consider the language of even-length palindromes: wwRww^R (e.g., abbaabba).
An NPDA reads the first half of the string and pushes it to the stack. Then, it magically "guesses" when the exact middle of the string is reached, and switches modes to start popping and matching the reverse half.
A DPDA cannot guess where the middle is. It fails.

Crucial Theorem: NPDA is mathematically MORE POWERFUL than DPDA. Therefore, "PDA" by default always refers to the nondeterministic version. DPDAs define a smaller sub-class of languages (Deterministic Context-Free Languages, which are used to build LR parsers).

Next — Acceptance by PDA

3 of 9

Page 4

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

4. Acceptance by PDA

A DFA accepts a string if it ends in a Final State. Because a PDA has two components (State and Stack), it has two completely different, mathematically equivalent ways to accept a string.

4.1 Acceptance by Final State

The standard way. The machine processes the entire input string. If, after the last character is read, the machine is physically located inside a state belonging to the set FF, the string is accepted. We completely ignore whatever garbage might be left on the stack.

4.2 Acceptance by Empty Stack

The machine processes the entire input string. We completely ignore what state the machine is in (the set FF is irrelevant and usually empty).
If, after reading the last character, the machine pops the final
Z0Z_0 bottom marker, leaving the stack absolutely, perfectly empty, the string is accepted.

Theorem: These two acceptance methods are mathematically equivalent. An algorithm exists to convert a Final-State PDA into an Empty-Stack PDA, and vice versa.

Next — Equivalence of CFG and PDA

4 of 9

Page 5

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

5. Equivalence of CFG and PDA

Just as Kleene's Theorem linked RE to DFA, there is a fundamental theorem linking grammars to stack machines:

Theorem: A language is Context-Free if and only if it is accepted by some Pushdown Automaton.
CFG
\equiv PDA.

5.1 Converting CFG to PDA

We can mechanically build an Empty-Stack PDA that acts as a "Top-Down Parser" to simulate any CFG.

The PDA has only ONE single state (qq).
1. Push the Start Symbol
SS onto the stack.
2. For every production rule
AαA \rightarrow \alpha, add a ϵ\epsilon-transition: δ(q,ϵ,A)=(q,α)\delta(q, \epsilon, A) = (q, \alpha). (This allows the PDA to magically expand variables on the stack).
3. For every terminal symbol 'a', add a matching transition:
δ(q,a,a)=(q,ϵ)\delta(q, a, a) = (q, \epsilon). (If the top of the stack matches the input character, pop it to consume the input).

Next — The Pumping Lemma for CFLs

5 of 9

Page 6

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

6. The Pumping Lemma for Context-Free Languages

We know anbna^n b^n is context-free. But what about anbncna^n b^n c^n?
A PDA has only one stack. If it pushes 'A's to count the 'a's, and pops them to match the 'b's, the stack is now empty. It has completely forgotten the count
nn, and cannot verify the 'c's.
Therefore,
anbncna^n b^n c^n is NOT context-free.

To prove this mathematically, we use the advanced Pumping Lemma for CFLs.

6.1 The Theorem Statement

If LL is a CFL, there exists a pumping length pp. Any string winLw in L where wp|w| \ge p can be split into exactly FIVE pieces:
w=uvxyzw = uvxyz

Satisfying three strict conditions:

  • 1. vy>0|vy| > 0: You must pump at least one character. Either vv or yy (or both) must not be empty.
  • 2. vxyp|vxy| \le p: The middle three pieces combined must be shorter than the pumping length.
  • 3. For all i0,uvixyizLi \ge 0, uv^ixy^iz \in L: You must pump vv and yy simultaneously, the exact same number of times, and the resulting string must remain in the language.

Next — Using the CFL Pumping Lemma

6 of 9

Page 7

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

7. Using the CFL Pumping Lemma

7.1 Prove L={anbncn}L = \{a^n b^n c^n\} is not context-free.

  • Step 1: Assume LL is a CFL. Let pp be the pumping length.
  • Step 2: Choose string w=apbpcpw = a^p b^p c^p. (Length is 3p3p, which is p\ge p).
  • Step 3: The lemma states w=uvxyzw = uvxyz, and vxyp|vxy| \le p.
    Because the "pumpable window"
    vxyvxy has a maximum length of pp, it is physically impossible for this window to span across all three letters ('a', 'b', and 'c').
    The window can contain only 'a's, only 'b's, only 'c's, or straddle the boundary of 'a/b' or 'b/c'. It absolutely CANNOT contain both 'a's and 'c's.
  • Step 4: Pump the string: uv2xy2zuv^2xy^2z.
    Because
    vv and yy do not contain all three letters, pumping them will increase the count of one or two letters, but NOT the third.
    (e.g., if the window was in the 'a's, we now have more 'a's than 'b's or 'c's).
  • Step 5: The pumped string loses its n=n=nn=n=n balance. It is impossible for uv2xy2zuv^2xy^2z to be in LL.

Conclusion: Contradiction achieved. The language is NOT context-free.

Next — Closure Properties of CFLs

7 of 9

Page 8

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

8. Closure Properties of Context-Free Languages

Unlike Regular Languages (which are practically indestructible), Context-Free Languages are incredibly fragile. Because of the nature of the single stack, they break under many standard mathematical operations.

8.1 Operations where CFLs are CLOSED (Safe)

If L1L_1 and L2L_2 are CFLs, the following are guaranteed to be CFLs:

  • Union: L1L2L_1 \cup L_2. (Create a new start symbol SS1S2S \rightarrow S_1 \mid S_2).
  • Concatenation: L1L2L_1 \cdot L_2. (Create a new start symbol SS1S2S \rightarrow S_1 S_2).
  • Kleene Star: L1L_1^*. (Create a new start symbol SS1SϵS \rightarrow S_1 S \mid \epsilon).

8.2 Operations where CFLs are NOT CLOSED (Unsafe)

If L1L_1 and L2L_2 are CFLs, the following are NOT guaranteed to be CFLs:

  • Intersection: L1L2L_1 \cap L_2 is NOT closed.
    Proof: Let L1={anbncm}L_1 = \{a^n b^n c^m\} (CFL, stack matches a/b, ignores c).
    Let
    L2={ambncn}L_2 = \{a^m b^n c^n\} (CFL, stack ignores a, matches b/c).
    The intersection is
    {anbncn}\{a^n b^n c^n\}. We just proved using the Pumping Lemma that this is NOT a CFL.
  • Complement: L\overline{L} is NOT closed.
    Proof: By De Morgan's Law, L1L2=L1L2L_1 \cap L_2 = \overline{ \overline{L_1} \cup \overline{L_2} }. If CFLs were closed under complement, then because they are closed under union, they would HAVE to be closed under intersection. We just proved they aren't.

Next — Summary Checklist

8 of 9

Page 9

Wink Notes

B.Tech CSE — 4th Semester

Theory of Automata and Formal Languages

Unit - 4

9. Summary Checklist

Unit 4 merges the algebraic grammars of Unit 3 into the physical machine world.

9.1 University Exam Checklist

  • Write the formal 7-tuple definition of a Pushdown Automaton. Explain the role of Γ\Gamma and Z0Z_0.
  • Explain the difference between DPDA and NPDA. Why is NPDA more powerful?
  • What are the two methods of acceptance for a PDA? Are they equivalent?
  • Draw a complete PDA state diagram (or write the δ\delta transition functions) for the language L={anbnn1}L = \{a^n b^n \mid n \ge 1\}.
  • Draw a PDA for the language of even-length palindromes wwRww^R. (Requires non-determinism).
  • Explain the algorithmic process to convert a Context-Free Grammar directly into an Empty-Stack PDA.
  • State the Pumping Lemma for Context-Free Languages, detailing the 5-part split uvxyzuvxyz.
  • Use the CFL Pumping Lemma to mathematically prove that L={anbncn}L = \{a^n b^n c^n\} and L={ww}L = \{ww\} (copy language) are NOT context-free.
  • List the closure properties of Context-Free Languages. Prove mathematically why CFLs are NOT closed under Intersection.

9 of 9

Continue in this subject