Math 2.0

Computer science Automata and formal languages Example

Dyck language

Builds on Dyck wordContext-free grammarRegular languagePumping lemma for regular languagesDeterministic context-free languageDyck words are counted by Catalan numbers

Example

Let Σ={(,)}\Sigma = \set{(, )}. The Dyck language D1⊆Σ∗D_1 \subseteq \Sigma^* is the set of balanced strings of brackets. In such a string ww, every prefix has at least as many (( as )). The string ww itself has as many (( as )). Its elements are the Dyck words, for example ε\varepsilon, ( )(\,), ( )( )(\,)(\,) and (( ))((\,)). More generally, DnD_n is the language of balanced strings over nn kinds of bracket pairs. In DnD_n, each closing bracket must match the kind of the last unmatched opening bracket.

D1D_1 is a context-free language: it is generated by the context-free grammar with rules S→SSS \to SS, S→(S)S \to (S) and S→εS \to \varepsilon. To check this, note that each rule keeps the strings balanced. Conversely, a nonempty balanced string either splits into two shorter nonempty balanced strings or has the form (u)(u) with uu balanced.

D1D_1 is not a regular language. Let pp be the pumping length of the pumping lemma for regular languages. The word (p )p(^p\,)^p can only be pumped inside its first block, which unbalances it.

Remarks

D1D_1 is even a deterministic context-free language: a pushdown automaton pushes on ((, pops on )), and never needs to guess. The number of Dyck words of length 2n2n is the Catalan number 1n+1(2nn)\frac{1}{n+1}\binom{2n}{n}, see Dyck words are counted by Catalan numbers. The languages DnD_n play a central role in the Chomsky–Schützenberger representation theorem.

Reading path

To understand this page from the ground up, read these 11 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Catalan numbers definition
  2. Context-free grammar concept
  3. Deterministic context-free language concept
  4. Deterministic finite automaton concept
  5. Dyck word definition
  6. Dyck word concept
  7. Regular language concept
  8. String concept
  9. Dyck words are counted by Catalan numbers statement
  10. Pumping lemma for regular languages statement
  11. Dyck language example

Where this leads

1 page builds on this one.

Further reading

  1. Web https://en.wikipedia.org/wiki/Dyck_language
About this page
TagB80FATJ43P
URIm2://B80FATJ43P
Kindexample
WritingW0 stub
MSC68Q45, 68R15, 05A15
Instance ofContext-free language
UsesDyck word, Context-free grammar, Regular language, Pumping lemma for regular languages, Deterministic context-free language, Dyck words are counted by Catalan numbers
Same as
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

Used by