Telling regular, context-free and non-context-free languages apart: the Chomsky hierarchy, closure properties of regular, deterministic CF and CF languages, and the pumping lemmas used to prove a language is not regular or not context-free.
1. Classifying a language: how much memory does it need?
Ask how much the machine must remember while reading the string left to right.
Bounded memory (a fixed number of facts, such as a count modulo , or the last few symbols) → regular.
One unbounded counter or one stack, used last-in first-out (match 's with later 's, nested or mirrored structure) → context-free.
Two or more independent unbounded comparisons, or copying () → usually not context-free.
Language
Class
, , any finite language
regular
, ,
DCFL, not regular
,
CFL, not DCFL
, , ,
context-sensitive, not CFL
Two quick rules:
Every finite language is regular, so is regular.
Every context-free language over a one-letter alphabet is regular. So a unary language is either regular or not context-free at all: is regular, is not CFL.
Watch for disguised regular languages. only needs parity: regular. needs a count: CFL, not regular. is not regular, but is.
The Chomsky hierarchy: each class is a proper subset of the one around it
2. Closure properties
A class is closed under an operation if applying it to languages of the class always gives a language of the class.
Operation
Regular
DCFL
CFL
Union
Yes
No
Yes
Intersection
Yes
No
No
Intersection with a regular language
Yes
Yes
Yes
Complement
Yes
Yes
No
Concatenation
Yes
No
Yes
Kleene star
Yes
No
Yes
Reversal
Yes
No
Yes
Homomorphism
Yes
No
Yes
Inverse homomorphism
Yes
Yes
Yes
The standard counterexample for CFL intersection: and are both CFLs, but is not. Since and CFLs are closed under union, they cannot be closed under complement either.
Using closure to classify.
CFL regular is a CFL. Regular CFL need not be a CFL.
To show is not regular, intersect with a regular language to reach a known non-regular one. , so the first language is not regular.
Closure is for one application or finitely many. A finite union of regular languages is regular, but an infinite union need not be: is a union of finite (regular) languages and is not regular. Also, " is regular" does not mean and are regular.
3. Pumping lemma for regular languages
Lemma. If is regular, there is a constant (the pumping length) such that every with can be split as with
,
,
for every .
Why it holds. A DFA with states reading symbols visits states, so some state repeats within the first symbols. The loop between the repeats is , and it can be taken any number of times. So can be taken as the number of states of any DFA for .
Using it (proof by contradiction) as a game.
Assume is regular with pumping length .
You choose a string with , chosen to make the split easy to analyse.
The opponent chooses any split satisfying 1 and 2. You must handle every such split.
You choose (often 0 or 2) so that .
For take . Since , with . Then .
The lemma is a necessary condition only. Every regular language satisfies it, but some non-regular languages also satisfy it. So the lemma can prove a language is not regular; it can never prove a language is regular.
The minimum pumping length of a regular language is the smallest for which the conditions hold. It is at most the number of states of the minimal DFA, and can be smaller.
4. Pumping lemma for context-free languages
Lemma. If is context-free, there is a constant such that every with can be split as with
,
(at least one of is non-empty),
for every .
Why it holds. In a CNF parse tree of a long enough string, some root-to-leaf path repeats a variable . The upper derives , so this part can be repeated or removed. Two pieces, and , are pumped together, which is why a single stack can match two counts but not three.
Example: is not context-free. Take . Because , the window cannot contain both an and a (there are 's between them). So pumping changes at most two of the three counts. With , at least one count grows and at least one stays the same, so . (If or mixes two letters, pumping also breaks the order .)
When to use which tool.
Goal
Tool
Not regular
regular pumping lemma, or closure (intersect with a regular set)
Not CFL
CFL pumping lemma, or closure (intersect with a regular set to reach )
Is regular / is CFL
build a DFA/regex or a CFG/PDA; pumping cannot prove this
As with the regular version, the CFL lemma is necessary but not sufficient: some non-CFLs satisfy it.
Formulas to remember
Regular pumping conditions
CFL pumping conditions
Pumping length from a DFANumber of states of the minimal DFA works as a pumping length
Intersection via complementWhy CFLs cannot be closed under complement
Common mistakes
Using the pumping lemma to claim a language is regular or context-free; it can only prove that a language is not.
Choosing the split yourself in a pumping proof; the opponent chooses the split, so your argument must work for every legal split.
Assuming CFLs are closed under intersection or complement; only intersection with a regular language is safe.
Treating an infinite union of regular languages as regular; closure holds only for finitely many operations.
Missing that a finite language is always regular, even when it looks like aⁿbⁿ with a bound on n.
Calling a unary language context-free but not regular; for one-letter alphabets the two classes coincide.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Proving a language is not regular
conceptual
Show that is not regular using the pumping lemma.
Step 1: Pick a string that pins the split.
Try it on paper first.
Example 2: Intersection of two CFLs
conceptual
Let and . Classify , , and .
Step 1: Classify $L_1$ and $L_2$.
Try it on paper first.
Example 3: Minimum pumping length
numerical
Find the minimum pumping length of (an followed by any number of 's).
Step 1: Test $p = 1$.
Try it on paper first.
Example 4: Unary languages
conceptual
Classify and .
Step 1: $L_1$: find a regular expression.
Try it on paper first.
Previous year questions
25 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.