CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 3 · CFG, PDA & Context-Free Languages

Lesson 3.4.4 · Item 62 of 91

Drill: regular, DCFL, CFL or not CFL?

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

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

    Read lesson 3.4.3

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

    Read lesson 3.4.1

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

    Read lesson 2.4.4

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.

steps illustration
One stack, one comparison (a’s vs b’s + c’s): deterministic.

The ladder

  1. Finite or only bounded facts? → regular.
  2. 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.
  3. Two independent comparisons (three equal counts), crossing matches, copies (ww), squares/primes → not a CFL.
flowplay illustration
Ask these in order.

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.
languageclassreason
wwᴿCFL, not DCFLguess the middle
aⁿbⁿ ∪ aⁿb²ⁿCFL, not DCFLguess the ratio
aⁱbʲcᵏ, i = j or j = kCFL, not DCFLinherently ambiguous
complement of wwCFL, not DCFLguess a mismatch position
Guessing is the giveaway.

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

languageclass
aⁿbⁿDCFL
wcwᴿDCFL
aⁿbᵐcⁿDCFL
#a = #bDCFL
aⁱbʲ, i ≠ jDCFL
balanced ( )DCFL
Deterministic: the order of symbols says when to push and when to pop.

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}).

Phase 3 language hierarchy
The Language Universe now has the DCFL and CFL shells. Find where aⁿbⁿ, wwᴿ and aⁿbⁿcⁿ live.

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.
aⁿbⁿcᵐ
DCFL
aⁿbⁿcⁿ
not CFL
wwᴿ, |w| ≤ 10
finite ⇒ regular
aⁿbⁿ ∪ {aᵐbⁿ : m ≠ n}
= a*b* ⇒ regular
Read the definition, not the shape.

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 = #c

Worked Examples

Easy

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

Medium

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.

GATE-level

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

  1. MCQ

    Which is a CFL but not a DCFL?

    1. { aⁿbⁿ }
    2. { wwᴿ }
    3. { wcwᴿ }
    4. { aⁿbⁿcⁿ }
  2. MSQ

    Which are DCFLs?

    1. { aⁱbʲ : i ≠ j }
    2. { aⁱbʲcᵏ : i = j + k }
    3. { aⁱbʲcᵏ : i = j or j = k }
    4. { w : #a = #b }
  3. MSQ

    Which are not context-free?

    1. { aⁿbⁿcᵐdᵐ }
    2. { aⁿbᵐcⁿdᵐ }
    3. { aᵐbⁿc^{mn} }
    4. { a^{2ⁿ} }
  4. MCQ

    { aⁿbⁿ : n ≥ 0 } ∪ { aᵐbⁿ : m ≠ n } is:

    1. not CFL
    2. CFL, not DCFL
    3. DCFL, not regular
    4. regular
  5. MCQ

    { aⁿ b aⁿ : n ≥ 0 } is:

    1. regular
    2. DCFL, not regular
    3. CFL, not DCFL
    4. 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

  1. No.
  2. No.
  3. Yes.

Self-test answers

  1. B — Unmarked middle.
    • A: DCFL.
    • C: DCFL.
    • D: Not CFL.
  2. ABD — Deterministic comparisons.
    • C: Needs a guess.
  3. BCD — Crossing, product, unary non-regular.
    • A: Two independent nested pairs in sequence: a CFL (even a DCFL).
  4. D — It is a*b*.
    • A: It collapses.
    • B: It collapses.
    • C: It collapses.
  5. B — The b marks the middle.
    • A: Equal counts.
    • C: No guess needed.
    • D: One comparison.

Flashcards

  1. Classify { aⁱbʲcᵏ : i = j or j = k }.
    Reveal answerCFL, not DCFL (inherently ambiguous).
  2. Classify { aⁿbᵐcⁿ }.
    Reveal answerDCFL.
  3. Classify { aⁿbᵐcⁿdᵐ }.
    Reveal answerNot a CFL (crossing).
  4. Classify { aⁿbⁿcᵐdᵐ }.
    Reveal answerDCFL (two nested pairs in sequence).

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.