Recall warm-up
- Is { ww } context-free?
Stuck? Peek at 3.4.3 Pumping lemma for CFLs
- L CFL ⇒ ∃p ∀z ∈ L, |z| ≥ p: z = uvwxy, |vwx| ≤ p, |vx| ≥ 1, uvⁱwxⁱy ∈ L ∀i ≥ 0. p = 2ᵏ (CNF, k variables).
- Non-CFL: aⁿbⁿcⁿ, ww, aⁿbᵐcⁿdᵐ, #a=#b=#c, a^{n²}, a^{prime}, aⁱbʲcᵏ (i<j<k).
- Unary CFL ⇒ regular. Complement of ww is a CFL.
- Are CFLs closed under intersection?
Stuck? Peek at 3.4.1 Closure properties of CFLs and DCFLs
- CFL closed: ∪, concat, *, reversal, h, h⁻¹, substitution, ∩R, −R. Not: ∩, complement, difference.
- DCFL closed: complement, ∩R, ∪R, −R, h⁻¹. Not: ∪, ∩, concat, *, reversal, h.
- Counterexample: aⁿbⁿcᵐ ∩ aᵐbⁿcⁿ = aⁿbⁿcⁿ. Non-CFL proof: L ∩ R non-CFL ⇒ L non-CFL.
- Is { w x wᴿ : w, x ∈ Σ⁺ } regular?
Stuck? Peek at 2.4.4 Drill: regular or not?
- Bounded fact (mod, flag, last k, capped count, bounded difference) ⇒ regular.
- Exact comparison of two unbounded counts, ww, wwᴿ, squares, primes, 2ⁿ ⇒ not regular.
- Finite ⇒ regular. Unary: regular ⇔ lengths eventually periodic.
- wxwᴿ, wxw (x ∈ Σ⁺) regular. #ab = #ba regular. ww over one letter regular.
The Hook
The single most frequent TOC question type on GATE: “Which of the following languages is context-free but not regular?” or “… is a DCFL?”. Speed comes from a ladder of questions you ask in order, plus a memory bank of the standard examples.
Predict First
Classify { aⁱbʲcᵏ : i = j + k }.
Core Concept
Prediction check
DCFL (not regular). Push a’s; pop one a per b, then one per c; accept if the stack is back to Z₀ exactly at the end. No guessing, one count matched against a sum.
The ladder
- Finite or only bounded facts? → regular.
- One comparison of counts that a stack can do in one left-to-right sweep (nested or sequential, never crossing)? → CFL. If you can tell when to switch from pushing to popping without guessing → DCFL.
- Two independent comparisons (three equal counts), crossing matches, copies (ww), squares/primes → not a CFL.
Signals of “CFL but not DCFL”
- Unmarked middle: wwᴿ, palindromes.
- Union of two different comparisons: aⁱbʲcᵏ with i = j or j = k; aⁿbⁿ ∪ aⁿb²ⁿ.
- Non-deterministic choice of what to compare: { aⁱbʲ : i ≠ j } is still a DCFL (just compare), but { aⁱbʲcᵏ : i ≠ j or j ≠ k } is a CFL not DCFL.
| language | class | reason |
|---|---|---|
| wwᴿ | CFL, not DCFL | guess the middle |
| aⁿbⁿ ∪ aⁿb²ⁿ | CFL, not DCFL | guess the ratio |
| aⁱbʲcᵏ, i = j or j = k | CFL, not DCFL | inherently ambiguous |
| complement of ww | CFL, not DCFL | guess a mismatch position |
Signals of “DCFL”
A marker or a fixed order tells the machine when to switch: wcwᴿ, aⁿbⁿ, aⁿbᵐcⁿ, aⁱbʲcᵏ with i = j + k, balanced brackets, #a = #b, { aⁱbʲ : i ≠ j }, { aⁱbʲ : i ≥ j }.
| language | class |
|---|---|
| aⁿbⁿ | DCFL |
| wcwᴿ | DCFL |
| aⁿbᵐcⁿ | DCFL |
| #a = #b | DCFL |
| aⁱbʲ, i ≠ j | DCFL |
| balanced ( ) | DCFL |
Signals of “not CFL”
aⁿbⁿcⁿ, #a = #b = #c, ww (|w| unrestricted, ≥ 2 symbols), aⁿbᵐcⁿdᵐ, aⁱbʲcᵏ with i < j < k, a^{n²}, a^{2ⁿ}, a^{prime}, { aⁿbⁿ… } with a product (aᵐbⁿc^{mn}).
Traps
- { aⁿbⁿcᵐ } is a DCFL; { aⁿbⁿcⁿ } is not even a CFL.
- { wwᴿ : |w| ≤ 10 } is finite ⇒ regular.
- { aⁿbⁿ : n ≥ 0 } ∪ { aᵐbⁿ : m ≠ n } = a*b* ⇒ regular.
- { ww : w ∈ a* } = (aa)* ⇒ regular.
- { aⁿ b aⁿ } is DCFL; { aⁿbⁿ } ∩ R is CFL for regular R.
Putting it together
- Ask the ladder in order: bounded? one deterministic comparison? one guessed comparison? two comparisons?
- “or” usually means CFL not DCFL; “and” usually means not CFL.
- Watch for finite bounds and unions that collapse.
Visual
REGULAR DCFL CFL (not DCFL) NOT CFL
a*b* aⁿbⁿ wwᴿ aⁿbⁿcⁿ
(ab)ⁿ wcwᴿ aⁿbⁿ ∪ aⁿb²ⁿ ww
aⁿbⁿ,n≤9 aⁿbᵐcⁿ aⁱbʲcᵏ: i=j or j=k aⁿbᵐcⁿdᵐ
wxwᴿ #a = #b complement of ww a^{n²}, a^{prime}
aⁱbʲ, i≠j #a = #b = #cWorked Examples
Classify { aⁿb²ⁿ }.
Show the full solution
DCFL: push one A per a and pop one per two b’s (or push AA per a). Not regular (unbounded comparison).
Classify { aⁱbʲcᵏ : i = j and j = k }, { aⁱbʲcᵏ : i = j or j = k }, { aⁱbʲcᵏ : i = j }.
Show the full solution
“and”: aⁿbⁿcⁿ — not CFL. “or”: CFL, not DCFL. i = j alone: aⁿbⁿc* — DCFL.
Which is context-free but not regular? (A) { aⁿbᵐ : n + m even } (B) { aⁿbⁿ : n ≤ 1000 } (C) { aⁿbᵐ : n ≥ m } (D) { aⁿbⁿcⁿ }
Show the full solution
(A) regular (parity). (B) finite ⇒ regular. (C) DCFL, not regular ✓. (D) not CFL. Answer (C).
GATE Traps
- “And” of two comparisons usually kills context-freeness; “or” usually gives CFL-not-DCFL.
- Bounds (n ≤ 1000) make a language finite and regular.
- Check whether the union collapses to something simple (a*b*).
- The complement of ww is a CFL; ww itself is not.
Memory Hook
Regular = goldfish. DCFL = a waiter who knows when to start clearing plates. CFL = a waiter who must guess when. Not CFL = a job needing two stacks of plates.
Connect the Dots
Phase 3 complete: one stack gives CFLs, determinism gives DCFLs, and two comparisons break even CFLs. Phase 4 removes the stack’s restriction: an endless tape the machine can read and write anywhere — the Turing machine, as powerful as any computer.
Self-Test
- MCQ
Which is a CFL but not a DCFL?
- { aⁿbⁿ }
- { wwᴿ }
- { wcwᴿ }
- { aⁿbⁿcⁿ }
- MSQ
Which are DCFLs?
- { aⁱbʲ : i ≠ j }
- { aⁱbʲcᵏ : i = j + k }
- { aⁱbʲcᵏ : i = j or j = k }
- { w : #a = #b }
- MSQ
Which are not context-free?
- { aⁿbⁿcᵐdᵐ }
- { aⁿbᵐcⁿdᵐ }
- { aᵐbⁿc^{mn} }
- { a^{2ⁿ} }
- MCQ
{ aⁿbⁿ : n ≥ 0 } ∪ { aᵐbⁿ : m ≠ n } is:
- not CFL
- CFL, not DCFL
- DCFL, not regular
- regular
- MCQ
{ aⁿ b aⁿ : n ≥ 0 } is:
- regular
- DCFL, not regular
- CFL, not DCFL
- not CFL
Rule Card
- Ladder: bounded → regular; one comparison, no guess → DCFL; one comparison with a guess → CFL; two comparisons / crossing / copy / squares → not CFL.
- “or” of comparisons → CFL not DCFL; “and” → not CFL.
- Always check finiteness and collapses (unions that become a*b*).
Concept Ledger
- classification ladder
- CFL-not-DCFL signals
- DCFL signals
- non-CFL signals
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- No.
- No.
- Yes.
Self-test answers
- B — Unmarked middle.
- A: DCFL.
- C: DCFL.
- D: Not CFL.
- ABD — Deterministic comparisons.
- C: Needs a guess.
- BCD — Crossing, product, unary non-regular.
- A: Two independent nested pairs in sequence: a CFL (even a DCFL).
- D — It is a*b*.
- A: It collapses.
- B: It collapses.
- C: It collapses.
- B — The b marks the middle.
- A: Equal counts.
- C: No guess needed.
- D: One comparison.
Flashcards
- Classify { aⁱbʲcᵏ : i = j or j = k }.
Reveal answer
CFL, not DCFL (inherently ambiguous). - Classify { aⁿbᵐcⁿ }.
Reveal answer
DCFL. - Classify { aⁿbᵐcⁿdᵐ }.
Reveal answer
Not a CFL (crossing). - Classify { aⁿbⁿcᵐdᵐ }.
Reveal answer
DCFL (two nested pairs in sequence).