Back to the 2025 paper

Module 1: Introduction & Regular Languages

20257m

Explain the Chomsky hierarchy of languages with examples.

Worked SolutionAI Assisted

Answer

Chomsky Hierarchy (Noam Chomsky, 1956) classifies formal grammars and their languages by production rule restrictions into 4 types, forming a strict containment hierarchy.


Hierarchy Overview

Type Name Production Form Language Class Recognizing Automaton
Type-0 Unrestricted α→β\alpha \rightarrow \beta, α,β∈(V∪T)∗\alpha,\beta \in (V\cup T)^*, $\alpha
eq \epsilon$ Recursively Enumerable (RE) Turing Machine (TM)
Type-1 Context-Sensitive ∣α∣≤∣β∣|\alpha| \le |\beta|, α→β\alpha \rightarrow \beta with context Context-Sensitive (CSL) Linear Bounded Automaton (LBA)
Type-2 Context-Free A→γA \rightarrow \gamma, A∈VA \in V, γ∈(V∪T)∗\gamma \in (V\cup T)^* Context-Free (CFL) Pushdown Automaton (PDA)
Type-3 Regular A→aB∣aA \rightarrow aB \mid a (right-linear) or A→Ba∣aA \rightarrow Ba \mid a (left-linear) Regular (REG) Finite Automaton (DFA/NFA)

Containment:
REG⊂DCFL⊂CFL⊂CSL⊂RE⊂ALL \text{REG} \subset \text{DCFL} \subset \text{CFL} \subset \text{CSL} \subset \text{RE} \subset \text{ALL}
Each is a proper subset of the next.


Detailed Explanation with Examples

Type-3: Regular Languages

  • Grammar: Right-linear (A→aB∣aA \rightarrow aB \mid a) or Left-linear.
  • Automaton: DFA/NFA/ϵ\epsilon-NFA (equivalent power).
  • Properties: Closed under union, intersection, complement, concatenation, star. Membership in O(n)O(n).
  • Example 1: L={ambn∣m,n≥0}L = \{a^m b^n \mid m,n \ge 0\}
    • Grammar: S→aS∣bA∣ϵS \rightarrow aS \mid bA \mid \epsilon, A→bA∣ϵA \rightarrow bA \mid \epsilon
  • Example 2: Binary strings with even number of 1's: (0∗10∗1)∗0∗(0^*10^*1)^*0^*
    • DFA: 2 states tracking parity

Type-2: Context-Free Languages (CFL)

  • Grammar: A→γA \rightarrow \gamma (single non-terminal LHS).
  • Automaton: PDA (NPDA > DPDA in power).
  • Properties: Closed under union, concat, star. Not closed under intersection, complement. Parsing O(n3)O(n^3) (CYK).
  • Example 1: L={anbn∣n≥0}L = \{a^n b^n \mid n \ge 0\} (matching counts)
    • Grammar: S→aSb∣ϵS \rightarrow aSb \mid \epsilon
    • PDA: push aa's, pop for bb's
  • Example 2: Balanced parentheses
    • Grammar: S→(S)∣SS∣ϵS \rightarrow (S) \mid SS \mid \epsilon
  • Example 3: {wwR∣w∈{a,b}∗}\{ww^R \mid w \in \{a,b\}^*\} (palindromes)
    • NPDA guesses middle

Type-1: Context-Sensitive Languages (CSL)

  • Grammar: ∣α∣≤∣β∣|\alpha| \le |\beta|, productions like αAβ→αγβ\alpha A \beta \rightarrow \alpha \gamma \beta (context around AA).
  • Automaton: LBA = TM with tape bounded by k∣w∣k|w|.
  • Properties: Membership decidable (PSPACE-complete). Closed under union, intersection, complement.
  • Example: L={anbncn∣n≥1}L = \{a^n b^n c^n \mid n \ge 1\}
    • Grammar: S→aBC∣aSBCS \rightarrow aBC \mid aSBC, CB→BCCB \rightarrow BC, aB→abaB \rightarrow ab, bB→bbbB \rightarrow bb, bC→bcbC \rightarrow bc, cC→cccC \rightarrow cc
    • Generates anbncna^n b^n c^n by expanding and reordering

Type-0: Recursively Enumerable (RE)

  • Grammar: No restrictions (unrestricted).
  • Automaton: Turing Machine (TM).
  • Properties: Not closed under complement. Halting problem undecidable. Semi-decidable.
  • Example: L={⟨M⟩∣M halts on empty input}L = \{\langle M \rangle \mid M \text{ halts on empty input}\} (Halting problem)
  • Note: All computable languages are RE; recursive (decidable) are subset where TM always halts.

Summary Table with Examples

Type Language Grammar Example Automaton
3 (REG) (a+b)∗(a+b)^* S→aS∣bS∣ϵS \rightarrow aS \mid bS \mid \epsilon DFA
3 (REG) {w∣#0(w) even}\{w \mid \#_0(w) \text{ even}\} S→0S∣1AS \rightarrow 0S \mid 1A, A→0A∣1SA \rightarrow 0A \mid 1S DFA (2 states)
2 (CFL) {anbn}\{a^n b^n\} S→aSb∣ϵS \rightarrow aSb \mid \epsilon PDA
2 (CFL) {wwR}\{ww^R\} S→aSa∣bSb∣ϵS \rightarrow aSa \mid bSb \mid \epsilon NPDA
1 (CSL) {anbncn}\{a^n b^n c^n\} (as above) LBA
0 (RE) Halting Problem Unrestricted TM

Practical Implications

  • Type-3: Lexical analysis, regex matching
  • Type-2: Syntax analysis (parsers), programming language grammars
  • Type-1: Rare in practice; natural language features
  • Type-0: Theoretical limits, computability

Final Answer

Chomsky hierarchy organizes languages by grammar restrictiveness: Type-3 (Regular) ⊂ Type-2 (CFL) ⊂ Type-1 (CSL) ⊂ Type-0 (RE), each with corresponding automaton (FA, PDA, LBA, TM). Examples: REG → DFA, CFL → PDA, CSL → LBA, RE → TM.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.