Chapter 6

Language classes and pumping arguments

Use a construction to establish membership in a class, and an impossibility argument to establish nonmembership. Closure statements are universal guarantees, not predictions of the exact class of every result.

6.1 Closure and mixed operations

Past papers · CS 2014–2026 (23 papers): 13 questions, 15 marks

Let REG denote regular languages, CFL context-free languages, DEC decidable languages and RE Turing-recognisable languages. “Yes” means closure for every pair in the class; “No” means there is a counterexample. All unions and concatenations in this table are finite.

OperationREGCFLDECRE
Union, intersectionYes, YesYes, NoYes, YesYes, Yes
Complement, differenceYes, YesNo, NoYes, YesNo, No
Concatenation, star, reversalYesYesYesYes
Homomorphism, allowing erasureYesYesNoYes
Inverse homomorphismYesYesYesYes

For CC context-free and RR regular, C∩RC\cap R, C∖RC\setminus R, C∪RC\cup R, CRCR and RCRC are context-free. R∖CR\setminus C need not be. For DD deterministic context-free, D∩RD\cap R, D∪RD\cup R, D∖RD\setminus R and R∖DR\setminus D are DCFLs. REG and CFL are closed under prefix, suffix and substring. Their quotients by regular languages are also in the same class; for example C/R={x:∃y∈R,xy∈C}C/R=\{x:\exists y\in R,xy\in C\} is CFL.

Even DEC is not closed under erasing homomorphism: a decidable language of finite valid accepting computation histories can erase the history and retain the accepted input, yielding an undecidable RE language. Non-erasing homomorphisms preserve decidability because every preimage candidate has bounded length.

6.2 Pumping lemma for regular languages

Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark

To disprove regularity: let the opponent choose pp; choose a word depending on pp; handle every legal split; choose an exponent ii that makes the pumped word leave the language. You do not get to select a convenient split. The lemma is necessary, not sufficient, for regularity.

For unary arithmetic progressions, both the cycle step and the lower cutoff matter. Choose a pump that preserves the residue and remains above the cutoff when deleted.

6.3 Pumping lemma for context-free languages

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks

The same strategy disproves context-freeness of {anbnc2n}\{a^nb^nc^{2n}\} and {ambmcm+n:m,n≥1}\{a^mb^mc^{m+n}:m,n\ge1\}; for the latter choose apbpcp+1a^pb^pc^{p+1} and pump up when the pumped pieces lie in the first two blocks. If both those counts increase equally, the cc count becomes too small; if they do not, equality fails. A window reaching cc cannot also reach aa, so pumping down or up breaks the constraints there as well.

6.4 Standard classification patterns

Past papers · CS 2014–2026 (23 papers): 10 questions, 19 marks

For this table, m,n,i,j,k,ℓm,n,i,j,k,\ell are nonnegative integers and w,xw,x range over a binary alphabet unless specified. “Non-CFL” examples here are still decidable: finite input can be checked with enough memory.

Language or constraintSmallest class statedReason to remember
Any finite language; a∗b∗c∗a^*b^*c^*REGFinite union or independent repetition
Fixed modular symbol countsREGFinite residue tuple
anbna^nb^n; anbcna^nb^{cn} for fixed integer c≥1c\ge1DCFL, nonregularOne stack counter
ambncm+na^mb^nc^{m+n}DCFL, nonregularPush for both first blocks; pop for last
ambncndma^mb^nc^nd^mDCFL, nonregularNested comparisons
ambmcndna^mb^mc^nd^nDCFL, nonregularFinish and reset the counter
ambncmdna^mb^nc^md^nNon-CFLTwo crossing comparisons
anbncna^nb^nc^n; anbnc2na^nb^nc^{2n}Non-CFLThree coupled blocks
aibjckdℓa^ib^jc^kd^\ell with ij=k+ℓij=k+\ellNon-CFLFilter to d0d^0; a short pump cannot preserve multiplication
apa^p for prime pp; an2a^{n^2}; a2na^{2^n}Non-CFLUnary CFLs are regular; lengths are not eventually periodic
wwRww^RCFL, not DCFLGuess the middle, then pop
wwww; w#ww\#w with a separatorNon-CFLGeneral copying needs more than a stack
wwRxxRww^Rxx^R; wxxRwRwxx^Rw^RCFLConcatenated or nested mirrors
wxwRxRwxw^Rx^RNon-CFLCrossing mirrors; regular filtering exposes crossing block counts

A unary language is regular exactly when its accepted lengths are eventually periodic: beyond some threshold, membership depends only on the length modulo one fixed positive integer. Every unary CFL is regular (the unary case of the semilinearity theorem). Prime lengths are not eventually periodic: if a prime qq beyond the threshold belongs to an accepted residue with period dd, then the composite q+qd=q(1+d)q+qd=q(1+d) would also belong. Squares and powers of two have unbounded gaps, which eventual periodicity of an infinite set forbids.

For counts of overlapping patterns, check whether they are really independent. Occurrences of 110 end runs of at least two 1's, and occurrences of 011 begin such runs. Interior runs contribute one of each; only boundary runs change the difference. Hence comparing those two counts needs only finite boundary information. Comparing 000 with 111 has no such cancellation: filtering to 0m1n0^m1^n, m,n≥3m,n\ge3, leaves the unbounded comparison m≥nm\ge n.

6.5 Complement of copying

Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks

Although C={ww:w∈{a,b}∗}C=\{ww:w\in\{a,b\}^*\} is not context-free, its complement is context-free. Odd-length words are automatically outside CC. For an even-length word, it suffices to guess two different symbols at corresponding positions of its halves.

The even-length unequal-halves language is exactly UaUb∪UbUaU_aU_b\cup U_bU_a. This is a useful counterexample to the false rule “if a language is non-CFL, its complement must also be non-CFL”.

6.6 Closure-based impossibility proofs

Start by intersecting a suspected CFL with a regular language that fixes block order. If that produces a known non-CFL, the original language cannot be CFL. Homomorphism and inverse homomorphism can remove irrelevant symbols or encode blocks. Always name the operation and the class whose closure you use.

For L1={anbncm}L_1=\{a^nb^nc^m\} and L2={ambncn}L_2=\{a^mb^nc^n\}, both are DCFLs, but their intersection is {anbncn}\{a^nb^nc^n\}, not CFL. If CFLs were closed under complement, De Morgan's identity and union closure would force intersection closure; therefore they are not closed under complement.

For the nonregular language A={anbn}A=\{a^nb^n\}, its complement is also nonregular, because REG is closed under complement. For B={ambn:m≠n}B=\{a^mb^n:m\ne n\}, if BB were regular then a∗b∗∖B=Aa^*b^*\setminus B=A would be regular, a contradiction.

Last-minute recall

  • REG is closed under all finite Boolean operations.
  • CFL is closed under union and intersection with REG, but not general intersection.
  • C∖RC\setminus R is CFL; R∖CR\setminus C need not be.
  • In regular pumping, ∣xy∣≤p|xy|\le p forces the pump near the beginning.
  • In CFL pumping, ∣vxy∣≤p|vxy|\le p limits the window, not its position.
  • One stack handles nesting and signed counts; arbitrary copying is harder.
  • A unary CFL is regular.
  • Complement can change a non-CFL into a CFL.

Revise offline: the whole Theory of Computation handbook as one PDF

40 pages · 1.7 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections