Chomsky hierarchy
The four types of grammars (unrestricted, context-sensitive, context-free, regular), the language classes and machines that match them (recursively enumerable and Turing machines, context-sensitive and linear bounded automata, context-free and PDAs, regular and finite automata), the strict inclusions with a witness language for each step, classifying a grammar by the shape of its productions, a context-sensitive grammar for a^n b^n c^n, and the closure and decidability summary.
Why it exists
The classes of languages met so far, regular, deterministic context-free and context-free, fit into a larger chain that ends with everything a computer can recognise. Noam Chomsky classified grammars by the shape of their productions; each shape matches a kind of machine. GATE asks for the chain, the machine of each class, strict inclusion with an example language for each step, and the type of a given grammar.
Prerequisites
You need the closure properties of both regular and context-free languages (regular closure, CFL closure); the top of the chain is the Turing machine (Turing machines).
Precise definitions
A grammar with productions , (at least one variable on the left) and . The type of :
| type | name | shape of every production | machine | class of languages |
|---|---|---|---|---|
| 3 | regular | , , (right-linear) or , , (left-linear) | finite automaton | regular |
| 2 | context-free | with a single variable on the left | pushdown automaton | context-free |
| 1 | context-sensitive | with (nothing shrinks); allowed if is on no right side | linear bounded automaton | context-sensitive |
| 0 | unrestricted | any | Turing machine | recursively enumerable |
(The name "context-sensitive" comes from the equivalent form with : the variable is replaced only in the context ; the form with is also called monotone or non-contracting; they generate the same languages, a textbook result.)
A language has type if some Type grammar generates it. The inclusions are
Between them sit the deterministic CFLs (between regular and context-free) and the recursive (decidable) languages (between context-sensitive and recursively enumerable).
How it works
The grammar types by example
The table gives six grammars; the program decides the type from the shape of the productions:
Which type is this grammar: start
Computed by a script, not typed| grammar | type (by the form of the productions) | shortest strings generated |
|---|---|---|
| S → aS | b | ||
| S → Sa | b | ||
| S → aA; A → Sb | b | ||
| S → aSb | ε | ||
| S → aSBC | aBC; CB → BC; aB → ab; bB → bb; bC → bc; cC → cc | ||
| S → aSb | AB; AB → ε |
Step 0
The type of a grammar is decided by the SHAPE of its productions, not by the language: the last grammar generates the context-free language a^n b^n but is Type 0 because of AB → ε. The third grammar mixes a right-linear and a left-linear production, so it is not Type 3, although its language a^n b^n is context-free.
Points that the table makes:
- The type depends on the shape, not the language. , generates , which is context-free, but the production has two symbols on the left and shrinks: the grammar is Type 0.
- A grammar whose productions are all right-linear or all left-linear is Type 3. A grammar that mixes them is not: , generates (); it is context-free (Type 2) but not regular.
- Every regular grammar is context-free; every context-free grammar without -productions is context-sensitive (a variable replaced by a nonempty string never shrinks).
The strict inclusions and their witnesses
| step | witness language | why |
|---|---|---|
| Type 3 Type 2 | context-free grammar ; not regular (pumping lemma) | |
| Type 2 Type 1 | context-sensitive grammar below; not context-free (pumping lemma) | |
| Type 1 Type 0 | the language of the halting problem, and also some decidable languages | not decidable at all (next batch) / diagonalisation (quoted) |
A grammar for that is context-sensitive (no production shrinks):
Idea: generate first, let 's and 's sort themselves with until all 's precede all 's, then convert from the left: , , , . Because no production shrinks the sentential form, membership is decidable by searching all sentential forms up to the length of the string; the program did exactly this and found that the language is with (all strings up to length ) and that it accepts exactly those strings among all strings over up to length .
Machines and decidability
- Type 3: finite automaton (DFA = NFA). Membership: linear time.
- Type 2: pushdown automaton. Membership: cubic time (CYK).
- Type 1: linear bounded automaton (a Turing machine whose head never leaves the cells of the input); membership is decidable (by the search above) but needs exponential time with the brute-force method.
- Type 0: Turing machine; membership is only semi-decidable: the machine halts and accepts strings of the language but may run forever on others (decidable and recognisable languages).
Closure summary (quoted textbook results)
| operation | regular | context-free | context-sensitive | recursive | r.e. |
|---|---|---|---|---|---|
| union | yes | yes | yes | yes | yes |
| intersection | yes | no | yes | yes | yes |
| complement | yes | no | yes | yes | no |
| concatenation | yes | yes | yes | yes | yes |
| star | yes | yes | yes | yes | yes |
| reversal | yes | yes | yes | yes | yes |
| homomorphism | yes | yes | no | no | yes |
Complement is the revealing column: the context-sensitive languages are closed under complement (Immerman and Szelepcsényi, a nontrivial theorem), while the recursively enumerable languages are not; a language is recursive exactly when it and its complement are both recursively enumerable (decidable and recognisable languages).
Worked examples
EX 1Type of a grammar
Easy: right-linear, Type 3. , , : single variable on the left, Type 2 (not regular because has two variables on the right). : the left side has two symbols and nothing shrinks, Type 1. (left side of length , right side of length ) shrinks: Type 0. alone, with a single variable on the left, is Type 2.
EX 2Machine for a language
Easy: Type 1; recognised by a linear bounded automaton (and by a Turing machine), not by any PDA. : PDA. : DFA. The halting problem: a Turing machine only.
EX 3Derivation in the context-sensitive grammar
MediumFor : (using ) (using ) () () () (). Seven steps. No sentential form is longer than the final string, so the search of all forms up to length finds it.
EX 4Mixed linear grammar
Medium, has Type 2: the first production is right-linear and the second is left-linear, but all productions of one kind are required for Type 3. Its language is not regular, so no regular grammar exists for it at all; a regular grammar for a regular language must use one orientation throughout (and a language like has both a right-linear and a left-linear grammar).
EX 5Typical questions
GATE level(a) "Which of the following is true: Type 3 Type 2 Type 1 Type 0." True, all inclusions strict. (b) "The class of languages accepted by linear bounded automata is:" context-sensitive. (c) "Which language class is not closed under complement:" context-free and recursively enumerable. (d) "A grammar with productions , is of type:" . (e) "Which type of grammar is needed for / :" context-sensitive (Type 1). (f) "Is every context-sensitive language decidable?" Yes; not every decidable language is context-sensitive.
Cheat box
Cheat box
- Type 3 regular (FA), Type 2 context-free (PDA), Type 1 context-sensitive (LBA), Type 0 unrestricted (TM, r.e.). Each inside the next, all strictly.
- Type 3: all productions right-linear or all left-linear. Type 2: one variable on the left. Type 1: . Type 0: anything.
- Witnesses: (2 not 3), (1 not 2), halting problem (0 not 1).
- Context-sensitive languages are decidable; recursive languages are between Type 1 and Type 0.
- Complement: closed for regular, CSL, recursive; not for CFL, r.e.
Traps and GATE patterns
Connections
Unlocks
Across subjects
No cross-subject links yet.
Within this subject
The top of the hierarchy is explained by Turing machines and by decidability (Turing machines, decidable and recognisable languages); the deterministic subclass sits between regular and context-free (DPDA versus NPDA); the regular and context-free closure tables are on the pages for those classes.
PYQs
11 previous year questions from your book. I re-solved each one myself (5 by running or simulating, 6 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the regular grammar:
S → Xa | Ya
X → Za
Z → Sa | ε
Y → Wa
W → Sa
where S is the starting symbol, the set of terminals is
{a} and the set of non-terminals is {S, W, X, Y, Z}. We
wish to construct a deterministic finite automaton
(DFA) to recognize the same language. What is the
minimum number of states required for the DFA?- (a)2
- (b)3
- (c)4
- (d)5 THEORY OF COMPUTATION
Consider the following languages:
L1 = { anwan | w ∈ {a, b}* }
L2 = { wxwr | w, x ∈ {a, b}*, |w|, |x| > 0 }
Note that wr is the reversal of the string w. Which of
the following is/are TRUE?- (a)L1 and L2 are regular.
- (b)L1 and L2 are context-free.
- (c)L1 is regular and L2 is context-free.
- (d)L1 and L2 are context-free but not regular.
Consider the following languages:
L1 = {ap│p is a prime number}
L2 = {anbmc2m | n ≥ 0, m ≥ 0}
L3 = {anbnc2n │ n ≥ 0}
L4 = {anbn │ n ≥ 1}
Which of the following are CORRECT?
I. L1 is context-free but not regular.
II. L2 is not context-free.
III. L3 is not context-free but recursive.
IV. L4 is deterministic context-free.- (a)I, II and IV only
- (b)II and III only
- (c)I and IV only
- (d)III and IV only
Language L1 is defined by the grammar: S1 → aS1b|ε Language L2 is defined by the grammar: S2 → abS2|ε Consider the following statements: P: L1 is regular Q: L2 is regular Which one of the following is TRUE?
- (a)Both P and Q are true
- (b)P is true and Q is false
- (c)P is false and Q is true
- (d)Both P and Q are false
Consider the languages L1,L2 and L3 as given below:
L1 = { 0p 1q | p, q ∈ N },
L2 = { 0p 1q | p, q ∈ N and p = q } and
L3 = { 0p 1q 0r | p, q, r ∈ N and p = q = r }.
Which of the following statements is NOT TRUE?- (a)Push Down Automate (PDA) can be used to recognize L1 and L2
- (b)L1 is a regular language
- (c)All the three languages are context free
- (d)Turing machines can be used to recognize all the languages
Match the following:
E. Checking that
identifiers are
declared before
their use
P. L={ anbmcndm |n≥1,m≥1}
F. Number of formal
parameters in the
declaration of a
function agrees with
the number of actual
parameters in a use of
that function
Q. X→XbX | XcX | dXf | g
G. Arithmetic
expressions with
matched pairs of
parentheses
R. L={wcw|w∈ (a+b)* }
H. Palindromes
S. X→bXb | cXc | ε- (a)E-P, F-R, G-Q, H-S.
- (b)E-R, F-P, G-S, H-Q
- (c)E-R, F-P, G-Q, H-S
- (d)E-P, F-R, G-S, H-Q
For s ∈ (0+1)* let d(s) denote the decimal value of s (e.g.
d(101)=5 ). Let L={s∈(0+1)* |d(s) mod 5=2 and d(s)
mod 7≠4}
Which one of the following statements is true?- (a)is recursively enumerable, but not recursive
- (b)is recursive, but not context-free
- (c)is context-free, but not regular
- (d)is regular
Consider the languages:
L1 = {anbncm | n, m > 0} and L2 = {anbmcm | n, m > 0},
Which one of the following statements is FALSE?- (a)L1 ∩ L2 is a context-free language
- (b)L1 U L2 is a context-free language
- (c)L1 and L2 are context-free languages
- (d)L1 ∩ L2 is a context sensitive language THEORY OF COMPUTATION
The language {0n1n2n | 1<=n<=106} is- (a)Regular
- (b)context-free but not regular
- (c)context-free but its complement is not context-free
- (d)not context free
Let L= L1 ∩ L2 , where L1 and L2 are languages as
defined below:
L1={ambmcnbn | m,n >=0}
L2={aibjck | i,j,k >=0}
Then is L- (a)Not recursive
- (b)Regular
- (c)Context free but not regular
- (d)Recursively enumerable but not context free
Which of the following is true for the language
{ ap| p is prime} ?- (a)It is not accepted by a Turing Machine
- (b)It is regular but not context-free
- (c)It is context-free but not regular
- (d)It is neither regular nor context-free, but accepted by a Turing machine
Self-check
Question 1
Name the machine and a witness language for each strict inclusion in the hierarchy.
Show answerHide
Finite automaton / PDA / LBA / Turing machine; witnesses , , and the halting language.
Question 2
What is the type of , ?
Show answerHide
Type 0 ( shrinks and has two symbols on the left), although its language is context-free.
Question 3
Why is membership decidable for a context-sensitive grammar?
Show answerHide
No production shrinks the string, so a derivation of a string of length only uses forms of length at most ; there are finitely many, and they can be searched.
Question 4
Is the class of context-sensitive languages closed under complement?
Show answerHide
Yes (Immerman–Szelepcsényi theorem, quoted). The context-free and recursively enumerable classes are not.
Revision card
One-screen revision
- 3 regular FA; 2 context-free PDA; 1 context-sensitive LBA; 0 r.e. TM. Strict chain.
- (2 not 3), (1 not 2).
- Type from the shape of productions, not the language.
- CSL decidable; complement closed for CSL, not for CFL or r.e.
References
- ·Sipser, Introduction to the Theory of Computation (3rd edition), Chapters 1 to 3 (finite automata, context-free grammars, Turing machines), which together give the hierarchy; linear bounded automata are treated in the exercises and notes
- ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Chapter 9 (undecidability) and the discussion of the Chomsky hierarchy with unrestricted grammars
Verification
scripts/enum-checks/toc_turing.py: the classifier of the shape of productions (Type 3, 2, 1, 0) was checked on ten grammars; the context-sensitive grammar S -> aSBC | aBC, CB -> BC, aB -> ab, bB -> bb, bC -> bc, cC -> cc generates exactly {a^n b^n c^n : n >= 1} on all strings up to length 12 by an exact breadth-first search (no production shrinks the form, so the search is exhaustive) and decides membership for every string over {a, b, c} up to length 9; the mixed linear grammar S -> aA, A -> Sb | b is Type 2 and generates a^n b^n; S -> aSb | AB, AB -> epsilon is Type 0 and generates a^n b^n for n = 0..3; right-linear and left-linear grammars generate a*b and b a*. That a^n b^n is not regular and a^n b^n c^n is not context-free was checked in the earlier pumping-lemma pages. The closure and decidability tables, the equivalence of non-contracting grammars with context-sensitive grammars, of Type 1 with linear bounded automata and of Type 0 with Turing machines, and the existence of a decidable language that is not context-sensitive are textbook theorems, QUOTED and NOT machine-proved (needs verification). Textbook chapter references are from memory; the treatment of linear bounded automata and of the hierarchy differs between books. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)