Introduction

The Chomsky hierarchy organizes grammars and their languages into four classical types: regular (Type-3), context-free (Type-2), context-sensitive (Type-1), and unrestricted (Type-0). Matching machine models are finite automata, PDAs, linear bounded automata (LBAs), and Turing machines. The hierarchy is used for inclusion questions, example witnesses, and closure/decidability contrasts. This note summarises the map; it is not a deep dive into LBAs.

Three kinds of question arise here: which class a language belongs to (tightest class), which grammar type a rule set is, and which machine model matches which class. The finer ladder with DCFL and the decidable languages matters as much as the four classical types.

Prerequisites

  • Turing Machines: Type-0 machine model.
  • Earlier TOC notes on regular and context-free languages.

Core concepts

The four types

TypeGrammar restrictionMachineLanguages
3A→xBA \to xB, A→xA \to x (all right-linear) or all left-linear, x∈Σ∗x \in \Sigma^*FARegular
2A→αA \to \alpha, α∈(V∪Σ)∗\alpha \in (V \cup \Sigma)^*PDAContext-free
1αAβ→αγβ\alpha A \beta \to \alpha \gamma \beta with γ≠ε\gamma \ne \varepsilon; equivalently non-contracting α→β\alpha \to \beta with ∣α∣≤∣β∣\lvert\alpha\rvert \le \lvert\beta\rvert; S→εS \to \varepsilon allowed only if SS is on no right sideLBAContext-sensitive
0α→β\alpha \to \beta, α\alpha contains a variableTMRecursively enumerable

Mixing right-linear and left-linear rules in one grammar leaves Type 3: S→aTS \to aT, T→Sb∣bT \to Sb \mid b generates {anbn∣n≥1}\{a^n b^n \mid n \ge 1\}. Such linear grammars (at most one variable on each right side) give a class strictly between REG and CFL.

Inclusions

REG⊊CFL⊊CSL⊊RE,\mathrm{REG} \subsetneq \mathrm{CFL} \subsetneq \mathrm{CSL} \subsetneq \mathrm{RE},

and the finer ladder is

finite⊊REG⊊DCFL⊊CFL⊊CSL⊊REC⊊RE⊊all languages.\text{finite} \subsetneq \mathrm{REG} \subsetneq \mathrm{DCFL} \subsetneq \mathrm{CFL} \subsetneq \mathrm{CSL} \subsetneq \mathrm{REC} \subsetneq \mathrm{RE} \subsetneq \text{all languages}.

Every CSL is decidable, because an LBA on input ww has only finitely many configurations (∣Q∣⋅(∣w∣+2)⋅∣Γ∣∣w∣+2|Q| \cdot (|w|+2) \cdot |\Gamma|^{|w|+2}), so a decider can search the configuration graph for an accepting configuration (or cut every run off after that many steps) and always halt. Watching a single run for a repeat is not enough, because an LBA is nondeterministic. The inclusion is strict by diagonalization over an enumeration of LBAs; no "natural" witness is needed for GATE.

Nested Chomsky hierarchy with machines and grammar types
Figure 1. Nested language classes REG subset CFL subset CSL subset RE, each annotated with its grammar type and machine model (FA, PDA, LBA, TM).

Witnesses

  • Regular but not finite: a∗a^*.
  • CFL not regular: anbna^n b^n.
  • CSL not CFL: anbncna^n b^n c^n.
  • RE not recursive: ATMA_{\mathrm{TM}} (next note).
  • DCFL not regular: anbna^n b^n. CFL not DCFL: {wwR∣w∈{a,b}∗}\{ww^R\mid w\in\{a,b\}^*\}, {aibjck∣i=j or j=k}\{a^i b^j c^k \mid i = j \text{ or } j = k\}.
  • Not RE: ATM‾\overline{A_{\mathrm{TM}}}.

How it works

Right-linear grammars = regular

Productions A→xBA \to xB or A→xA \to x with x∈Σ∗x \in \Sigma^* generate regular languages; convert to/from NFAs by treating variables as states.

Unrestricted grammars = TMs

Type-0 productions α→β\alpha \to \beta (α\alpha nonempty) generate exactly the r.e. languages.

Algorithms and pseudocode

Membership:

  • Regular: DFA run linear time.
  • CFL: CYK cubic time.
  • CSL: decidable (LBA space), expensive.
  • RE: semidecidable (enumerate TM acceptors).

Mathematical explanation

Properness of inclusions

Each witness separates adjacent classes: anbna^n b^n has infinitely many Myhill-Nerode classes (the prefixes aia^i are pairwise distinguishable by bib^i), anbncna^n b^n c^n fails the CFL pumping lemma, and ATMA_{\mathrm{TM}} is undecidable by diagonalization.

A context-sensitive grammar for anbncna^n b^n c^n

S→aSBC∣aBCS \to aSBC \mid aBC, CB→BCCB \to BC, aB→abaB \to ab, bB→bbbB \to bb, bC→bcbC \to bc, cC→cccC \to cc. Every rule is non-contracting. Derivation of aabbcc: S⇒aSBC⇒aaBCBC⇒aaBBCC⇒aabBCC⇒aabbCC⇒aabbcC⇒aabbccS \Rightarrow aSBC \Rightarrow aaBCBC \Rightarrow aaBBCC \Rightarrow aabBCC \Rightarrow aabbCC \Rightarrow aabbcC \Rightarrow aabbcc. The rule CB→BCCB \to BC sorts the variables; aB→abaB \to ab and bB→bbbB \to bb turn BB's into bb's only once they sit right after the aa's or bb's, so letters never get out of order. Because no rule shrinks a sentential form, membership of ww can be decided by searching only forms of length ≤∣w∣\le |w|, which is the grammar view of "CSL ⊆\subseteq REC".

Decidable versus r.e.

Recursive languages are those decided by total TMs; they properly contain the context-sensitive languages under standard textbook presentations used in GATE, and are properly contained in RE.

Worked examples

Example 1: place the language

LanguageClass (tight)
{a,b}∗\{a,b\}^*regular
{anbn}\{a^n b^n\}CFL, not regular
{anbncn}\{a^n b^n c^n\}CSL, not CFL
ATMA_{\mathrm{TM}}RE, not recursive

Example 2: grammar type check

S→aS∣εS \to aS \mid \varepsilon right-linear (Type-3). S→aSb∣εS \to aSb \mid \varepsilon Type-2. The rule aAb→aabbaAb \to aabb rewrites AA as abab in the context a_ba\_b, so it is Type-1. AB→AAB \to A is contracting, so it is Type-0 only. S→SS∣aS \to SS \mid a is Type-2 although its language a+a^+ is regular: the type of a grammar is set by the rule shapes, the class of a language by the best grammar that exists for it.

Example 3: machine upgrade

FA cannot store nn for anbna^n b^n; PDA can; PDA cannot store two independent counts for anbncna^n b^n c^n; TM can.

Example 4: closure glance

Regular languages, DCFLs, CSLs and decidable languages are closed under complement; CFLs and RE languages are not. CSL closure under complement is the Immerman-Szelepcsenyi theorem. The full table across all classes is in Closure and Decision Properties of CFLs.

Example 5: exam diagram

Draw nested ovals labelled REG, CFL, CSL, RE and write each witness inside the ring of the smallest class that contains it: anbna^n b^n in the CFL ring outside REG, anbncna^n b^n c^n in the CSL ring outside CFL, ATMA_{\mathrm{TM}} in the RE ring.

Example 6: tightest class

LanguageTightest classWhy
{anbn∣n≤1000}\{a^n b^n \mid n \le 1000\}regularfinite
{ambn∣m≠n}\{a^m b^n \mid m \ne n\}DCFLone counter, decided at end of input
{w∈{a,b}∗∣#a(w)=#b(w)}\{w \in \{a,b\}^* \mid \#_a(w) = \#_b(w)\}DCFLcounter with a sign
{wwR∣w∈{a,b}∗}\{ww^R\mid w\in\{a,b\}^*\}CFL, not DCFLthe centre must be guessed
{ww∣w∈{a,b}∗}\{ww\mid w\in\{a,b\}^*\}, {anbncn}\{a^n b^n c^n\}, {an2}\{a^{n^2}\}, {a2n}\{a^{2^n}\}, {aq∣q prime}\{a^q \mid q \text{ prime}\}CSL, not CFLeach is decided in linear space
{⟨G⟩∣G a CFG with L(G)=∅}\{\langle G \rangle \mid G \text{ a CFG with } L(G) = \emptyset\}decidable; known CSL upper bound under the ordinary grammar encoding, not a tightest-class claimmarking generating variables
HALTTMHALT_{\mathrm{TM}}, ATMA_{\mathrm{TM}}RE, not co-REsimulate; diagonalization
ATM‾\overline{A_{\mathrm{TM}}}, ETME_{\mathrm{TM}}co-RE, not REcomplement of an RE, undecidable language
EQTMEQ_{\mathrm{TM}}neither RE nor co-REATM‾≤mEQTM\overline{A_{\mathrm{TM}}} \le_m EQ_{\mathrm{TM}} and ATM≤mEQTMA_{\mathrm{TM}} \le_m EQ_{\mathrm{TM}}

Traps: a subset of a regular language need not be regular (anbn⊆a∗b∗a^n b^n \subseteq a^*b^*); a finite union of regular languages is regular, an infinite union need not be (⋃n{anbn}\bigcup_n \{a^n b^n\}); every finite language is regular, however complicated its definition.

Important properties and observations

  • Hierarchy is about descriptive power, not asymptotic runtime.
  • Ambiguity, determinism (DCFL) and decidability cut across the hierarchy with their own subclasses.
  • An LBA is a nondeterministic TM whose head never leaves the input; whether deterministic LBAs are as powerful is an open problem.
  • Type-0 grammars and TMs are equivalent: a TM can enumerate all derivations, and a grammar can simulate a TM run backwards.

Common misconceptions.

  • "CSL means 'almost CFL'." CSLs properly contain CFLs; anbncna^n b^n c^n is the emblem.
  • "RE means regular expression." In computability, RE means recursively enumerable.
  • "All TM languages are decidable." Only the recursive ones.
  • "Every CSL is a CFL with context." CSLs contain all CFLs, and also non-CFLs such as anbncna^n b^n c^n.
  • "A grammar with a left-linear and a right-linear rule is still regular." Mixed linear grammars can generate anbna^n b^n.

GATE examination perspective

  • NESTED DRAWING. Four classes with witnesses.
  • VOCABULARY. RE vs regular expression vs recursive.
  • MACHINE MATCHING. FA/PDA/LBA/TM.
  • LIGHT CSL. Do not invent LBA transition tables unless asked.
  • TIGHTEST CLASS. An option may name a true but loose class; pick the smallest one.
  • GRAMMAR VERSUS LANGUAGE. A Type-2 grammar can generate a regular language.
  • FINITE IS REGULAR. Any bound on nn makes the language finite.

Summary

Sources

  1. P. Linz, An Introduction to Formal Languages and Automata, 6th ed., Jones & Bartlett Learning, Section 11.1 (recursive and recursively enumerable languages), Section 11.2 (unrestricted grammars), Section 11.3 (context-sensitive grammars and languages; relation between recursive and context-sensitive languages), Section 11.4 (the Chomsky hierarchy), Section 10.5 (linear bounded automata).
  2. J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages, and Computation, 3rd ed., Pearson Addison-Wesley: Section 9.1 (a language that is not recursively enumerable), Section 9.2 (an undecidable problem that is RE).
  3. M. Sipser, Introduction to the Theory of Computation, 3rd ed., Cengage Learning: Section 4.2 (undecidability; a Turing-unrecognizable language).

Next steps