Generating and ranking of Dyck words
A new algorithm to generate all Dyck words is presented, which is used in ranking and unranking Dyck words. We emphasize the importance of using Dyck words in encoding objects related to Catalan numbers. As a consequence of formulas used in the ranking algorithm we can obtain a recursive formula for the nth Catalan number.
💡 Research Summary
The paper presents a comprehensive study of Dyck words—binary strings of length 2n that never dip below the horizontal axis when interpreted as a walk with up‑steps (0) and down‑steps (1) and that end at height 0. After formally defining Dyck words via the valuation function h(0)=+1, h(1)=−1, the authors introduce four distinct algorithms for generating all Dyck words of a given semilength n, for ranking them in a prescribed order, and for unranking (i.e., reconstructing a Dyck word from its rank).
-
Lexicographic Generation
A recursive procedureLexDyckWordstracks the number of 0’s (n0) and 1’s (n1) placed so far. Depending on five mutually exclusive cases (both counts below n, equality, or one count already saturated), the algorithm decides whether to append a 0, a 1, or both. When n0 = n1 = n the current word is a complete Dyck word and is output. The method enumerates every Dyck word exactly once in standard lexicographic order; for n = 4 it yields the 14 classic Dyck strings. -
Generation via Positions of 1’s
Observing that the positions b₁,…,bₙ of the 1’s in a Dyck word satisfy 2i ≤ bᵢ ≤ n + i, the authors proposePosDyckWords. Starting from the minimal admissible vector (bᵢ = 2i) they repeatedly increase the rightmost component that can be raised without violating the upper bound, resetting all later components to their minimal feasible values. This produces all admissible position vectors in reverse‑lexicographic order, and each vector corresponds uniquely to a Dyck word. -
“10 → 01” Transformation Generation
A third algorithm exploits the fact that any Dyck word can be transformed into the canonical word (01)ⁿ by repeatedly replacing the leftmost occurrence of the pattern “10” with “01”. Starting from (01)ⁿ, the recursive routineDyckWords(X,k)scans the suffix beginning at position k, finds the first “10”, flips it, outputs the new word, and recurses from the position just after the changed pair. The authors prove that by iterating this operation all Dyck words are reachable, establishing the completeness of this generation scheme. -
Ranking Using Lattice‑Path Counts
To rank a Dyck word, the paper introduces the lattice‑path function f(i,j), the number of monotone paths from (0,0) to (i,j) that never cross the diagonal x = y. f satisfies the recurrence
f(i,j) = f(i−1,j) + f(i,j−1) for 1 ≤ j < i ≤ n,
with boundary conditions f(i,0)=1 and f(i,i−1)=Cᵢ (the i‑th Catalan number). It follows that Cₙ₊₁ = f(n+1,n) = ∑_{i=0}^{n} f(n,i).
Given a Dyck word represented by its 1‑positions b₁…bₙ, the ranking algorithm first computes a helper vector cᵢ = max(bᵢ−1 + 1, 2i). Then, for each i from 1 to n−1, it adds ∑_{j=cᵢ}^{bᵢ−1} f(n−i, n + i − j) to a running total nr, which finally yields the 1‑based lexicographic rank. An example with b =
Comments & Academic Discussion
Loading comments...
Leave a Comment