THEORY OF COMPUTATION/Student Engineering Notebook
Page 05·notes
CONTEXT-FREE GRAMMARS, AMBIGUITY & PUSHDOWN AUTOMATA—~30 MIN READ

CFG Derivations, Ambiguity Proofs & Chomsky Normal Form

“Parse tree multiplicity, inherent ambiguity, CNF 2n-1 steps, and CYK parsing.”

1.Context-Free Grammars & The Ambiguity Problem

A Context-Free Grammar (CFG) is a 4-tuple G = (V, T, P, S), where production rules have the form A \to \alpha, with A \in V (a single non-terminal variable) and \alpha \in (V \cup T)^*.

Ambiguity in Grammars:

A grammar G is ambiguous if there exists at least one string w \in L(G) that has two or more distinct leftmost derivations (or equivalently, two or more distinct parse trees).

Inherent Ambiguity:

A context-free language L is inherently ambiguous if EVERY grammar that generates L is ambiguous. Classic inherently ambiguous language:

$L = { a^n b^n c^m d^m \mid n, m ≥ 1 } \cup { a^n b^m c^m d^n \mid n, m ≥ 1 }$

For strings where n = m (a^n b^n c^n d^n), every grammar is forced to generate duplicate parse trees.

Chomsky Normal Form (CNF):

A grammar is in CNF if all production rules are strictly of the form: A \to BC or A \to a (where A, B, C \in V and a \in T).

CNF Derivation Length Theorem: If a string w \in L(G) has length n ≥ 1, any derivation of w in a CNF grammar requires EXACTLY 2n - 1 steps (specifically: n - 1 rule applications of A \to BC, followed by n rule applications of A \to a).

WORKED EXAM ANALYSIS · STEP-BY-STEP DERIVATION2 Marks (High Frequency)

2. GATE Worked Numerical: Derivation Steps in CNF Grammar

⚠️ Pitfall Warning:

The formula 2n - 1 applies ONLY when the grammar is in Chomsky Normal Form (CNF)! For general grammars, derivation lengths can vary.

Problem: A context-free grammar G is in Chomsky Normal Form. A string w of length 15 is derived in G. How many derivation steps were executed?

Step 1: Identify CNF production structure:

Binary productions (A -> BC) increase the count of non-terminals by 1.

To grow from 1 start symbol S to 15 non-terminals requires: 15 - 1 = 14 applications of A -> BC.

Step 2: Terminal productions (A -> a):

Each of the 15 non-terminals must be converted into a terminal symbol: 15 applications of A -> a.

Step 3: Total derivation steps:

Total steps = (n - 1) + n = 2n - 1 = 2(15) - 1 = 30 - 1 = 29 steps.

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
Introduction to Automata Theory, Languages, and Computation (3rd Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Gate Smashers · Theory of Computation↗Instructor: Varun Singla · Covers: DFA/NFA, minimization, CFG, PDA, Turing machines, decidability

GATE-focused with clear minimal DFA construction and language classification.

Open YouTube↗
Knowledge Gate · TOC for GATE↗Instructor: Sanchit Jain · Covers: Regular expressions, pumping lemma, closure properties, Rice's theorem

Exam-pattern oriented with closure table drilling and decidability proofs.

Open YouTube↗
Ravindrababu Ravula · TOC Lectures↗Instructor: Ravindrababu Ravula · Covers: Formal proofs, Myhill-Nerode theorem, undecidability reductions

Mathematically rigorous treatment for high-rank GATE aspirants.

Open YouTube↗