What single resource makes both CFGs and PDAs equivalent? → ==a stack (= recursion/nesting)==.
In CFG→PDA, what does the stack hold? → the unmatched suffix of the current sentential form.
When does the CFG→PDA read input? → only when matching a terminal on top of the stack.
What does Apq⇒∗w mean? → ==M goes p→q on input w with net-zero (balanced) stack usage==.
Why do we get exactly two PDA→CFG rule schemas? → the first pushed symbol is popped either at the very end (match) or earlier (split).
Recall Feynman: explain to a 12-year-old
Imagine you're playing with nesting boxes. A grammar is the recipe: "to make a big box, put a smaller box inside, then close the lid." A PDA is a kid with a stack of plates: every time the recipe says "open a box" the kid puts a plate down; every "close a box" the kid takes a plate off. If the kid ends with no plates left and has read the whole sentence, the sentence followed the recipe. Recipes and the plate-kid can do exactly the same set of patterns — that's the whole theorem. (One pile of plates only! Give the kid two piles and suddenly they can do everything a full computer can.)
A language is context-free iff
it is accepted by some (nondeterministic) pushdown automaton.
The shared structural resource behind CFGs and PDAs
a single stack (grammar recursion ↔ machine stack).
In CFG→PDA, how many states are needed
one state; all information lives on the stack.
CFG→PDA transition for rule A→α
δ(q, ε, A) ∋ (q, α) — read nothing, pop A, push α.
CFG→PDA transition for terminal a
δ(q, a, a) ∋ (q, ε) — read a, pop a, push nothing (match).
Invariant maintained by the CFG→PDA construction
(input read so far) · (stack contents) = current sentential form of a leftmost derivation.
Meaning of variable A_pq in PDA→CFG
strings taking M from state p to q with net-zero (balanced) stack change, never dipping below start height.
PDA→CFG split rule
A_pq → A_pr A_rq (stack returns to start height at intermediate state r).
PDA→CFG match rule
A_pq → a A_rs b, when reading a pushes t (p→r) and reading b pops the same t (s→q).
PDA→CFG base rule
A_pp → ε.
Why two PDA→CFG schemas suffice
first pushed symbol is popped either at the very end (match) or strictly before (split) — exhaustive.
Why nondeterminism is required
deterministic PDAs accept only DCFLs, a strict subset; the PDA must guess the rule/derivation.
What does giving a PDA a second stack do
it becomes as powerful as a Turing machine (no longer just context-free).
Dekho, idea bahut simple hai: CFG aur PDA dono ek hi cheez ki do shaklein hain. CFG ek recipe hai jo strings banati hai (rules se), aur PDA ek machine hai jisme ek stack hota hai aur woh strings ko pehchanti hai. Theorem kehta hai: koi bhi language context-free hai agar aur sirf agar koi PDA usse accept karta hai. Reason? Grammar me jo recursion/nesting hoti hai (ek variable doosre ke andar expand hota hai), wahi nesting ek stack ke through machine me aa jaati hai.
Direction 1 (CFG → PDA): ek hi state ka PDA banao, stack me start variable S rakho. Agar stack ke top pe variable hai to bina input padhe (ε move) usse kisi rule ke right-hand side se replace kar do (push). Agar top pe terminal hai to woh next input symbol se match hona chahiye — dono consume kar do. Jab stack empty aur input khatam ho, to accept. Stack basically "abhi tak jo derive nahi hua" usse hold karta hai. Yaad rakho: expansion me input nahi padhte, sirf matching me padhte hain.
Direction 2 (PDA → CFG): har pair of states (p,q) ke liye ek variable Apq banao jiska matlab hai "machine p se q tak jaa sakti hai aur uss dauraan stack jitna push kiya utna pop bhi ho gaya (balanced)". Bas do tarah ke rules: agar pehla push wala symbol bilkul end me pop hota hai to match ruleApq→aArsb; agar beech me hi stack apni height pe wapas aa jaata hai to split ruleApq→AprArq. Plus base App→ε.
Kyun important hai: ye equivalence parsing, compilers, aur language ki theory ki neev hai. Aur ek killer fact yaad rakho — ek stack = context-free, lekin do stacks de do to PDA poora Turing machine ban jaata hai! Aur nondeterminism zaroori hai: deterministic PDA sirf DCFL pakadte hain, poori CFL class nahi.