Document Open Access Logo

Enumerating Regular Languages with Bounded Delay

Authors Antoine Amarilli , Mikaël Monet

Thumbnail PDF


  • Filesize: 0.8 MB
  • 18 pages

Document Identifiers

Author Details

Antoine Amarilli
  • LTCI, Télécom Paris, Institut Polytechnique de Paris, France
Mikaël Monet
  • Univ. Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France


We thank Florent Capelli and Charles Paperman for their insights during initial discussions about this problem. We thank user pcpthm on the Theoretical Computer Science Stack Exchange forum for giving the argument for Proposition 6.1 in We thank Jeffrey Shallit for pointing us to related work. We thank Torsten Mütze and Arturo Merino for other helpful pointers. We thank the anonymous reviewers for their valuable feedback. Finally, we are grateful to Louis Jachiet and Lê Thành Dũng (Tito) Nguyễn for feedback on the draft.

Cite AsGet BibTex

Antoine Amarilli and Mikaël Monet. Enumerating Regular Languages with Bounded Delay. In 40th International Symposium on Theoretical Aspects of Computer Science (STACS 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 254, pp. 8:1-8:18, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2023)


We study the task, for a given language L, of enumerating the (generally infinite) sequence of its words, without repetitions, while bounding the delay between two consecutive words. To allow for delay bounds that do not depend on the current word length, we assume a model where we produce each word by editing the preceding word with a small edit script, rather than writing out the word from scratch. In particular, this witnesses that the language is orderable, i.e., we can write its words as an infinite sequence such that the Levenshtein edit distance between any two consecutive words is bounded by a value that depends only on the language. For instance, (a+b)^* is orderable (with a variant of the Gray code), but a^* + b^* is not. We characterize which regular languages are enumerable in this sense, and show that this can be decided in PTIME in an input deterministic finite automaton (DFA) for the language. In fact, we show that, given a DFA A, we can compute in PTIME automata A₁, …, A_t such that L(A) is partitioned as L(A₁) ⊔ … ⊔ L(A_t) and every L(A_i) is orderable in this sense. Further, we show that the value of t obtained is optimal, i.e., we cannot partition L(A) into less than t orderable languages. In the case where L(A) is orderable (i.e., t = 1), we show that the ordering can be produced by a bounded-delay algorithm: specifically, the algorithm runs in a suitable pointer machine model, and produces a sequence of bounded-length edit scripts to visit the words of L(A) without repetitions, with bounded delay - exponential in |A| - between each script. In fact, we show that we can achieve this while only allowing the edit operations push and pop at the beginning and end of the word, which implies that the word can in fact be maintained in a double-ended queue. By contrast, when fixing the distance bound d between consecutive words and the number of classes of the partition, it is NP-hard in the input DFA A to decide if L(A) is orderable in this sense, already for finite languages. Last, we study the model where push-pop edits are only allowed at the end of the word, corresponding to a case where the word is maintained on a stack. We show that these operations are strictly weaker and that the slender languages are precisely those that can be partitioned into finitely many languages that are orderable in this sense. For the slender languages, we can again characterize the minimal number of languages in the partition, and achieve bounded-delay enumeration.

Subject Classification

ACM Subject Classification
  • Theory of computation → Formal languages and automata theory
  • Regular language
  • constant-delay enumeration
  • edit distance


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Margareta Ackerman and Erkki Mäkinen. Three new algorithms for regular language enumeration. In ICCC, 2009. URL:
  2. Margareta Ackerman and Jeffrey Shallit. Efficient enumeration of words in regular languages. Theoretical Computer Science, 410(37), 2009. URL:
  3. Antoine Amarilli, Pierre Bourhis, Stefan Mengel, and Matthias Niewerth. Constant-delay enumeration for nondeterministic document spanners. In ICDT, 2019. URL:
  4. Antoine Amarilli, Pierre Bourhis, Stefan Mengel, and Matthias Niewerth. Enumeration on trees with tractable combined complexity and efficient updates. In, 2019. URL:
  5. Antoine Amarilli and Mikaël Monet. Enumerating regular languages with bounded delay, 2023. Full version with proofs. URL:
  6. Guillaume Bagan. MSO queries on tree decomposable structures are computable with linear delay. In CSL, 2006. Google Scholar
  7. Guillaume Bagan, Arnaud Durand, and Étienne Grandjean. On acyclic conjunctive queries and constant delay enumeration. In CSL, 2007. URL:
  8. Ronald Fagin, Benny Kimelfeld, Frederick Reiss, and Stijn Vansummeren. Document spanners: A formal approach to information extraction. J. ACM, 62(2), 2015. URL:, URL:
  9. Rainer Feldmann and Peter Mysliwietz. The shuffle exchange network has a Hamiltonian path. Mathematical systems theory, 29(5), 1996. Google Scholar
  10. Lukas Fleischer and Jeffrey Shallit. Recognizing lexicographically smallest words and computing successors in regular languages. International Journal of Foundations of Computer Science, 32(06), 2021. Google Scholar
  11. Fernando Florenzano, Cristian Riveros, Martin Ugarte, Stijn Vansummeren, and Domagoj Vrgoc. Constant delay algorithms for regular document spanners. In PODS, 2018. URL:
  12. Alon Itai, Christos H Papadimitriou, and Jayme Luiz Szwarcfiter. Hamilton paths in grid graphs. SIAM Journal on Computing, 11(4):676-686, 1982. URL:
  13. Jerome J. Karaganis. On the cube of a graph. Canadian Mathematical Bulletin, 11(2), 1968. Google Scholar
  14. Wojciech Kazana and Luc Segoufin. Enumeration of monadic second-order queries on trees. TOCL, 14(4), 2013. URL:
  15. Erkki Mäkinen. On lexicographic enumeration of regular and context-free languages. Acta Cybernetica, 13(1):55-61, 1997. URL:
  16. Torsten Mütze. Proof of the middle levels conjecture. Proceedings of the London Mathematical Society, 112(4):677-713, 2016. URL:
  17. Torsten Mütze. Combinatorial Gray codes - An updated survey, 2022. URL:
  18. pcpthm ( Enumerating finite set of words with Hamming distance 1. Theoretical Computer Science Stack Exchange. Version: 2022-07-02. URL:
  19. Jean-Éric Pin. Mathematical foundations of automata theory, 2019. URL:
  20. Jakub Radoszewski and Wojciech Rytter. Hamiltonian paths in the square of a tree. In ISAAC, 2011. URL:
  21. Frank Ruskey. Combinatorial generation. Preliminary working draft, 2003. URL:
  22. Milan Sekanina. On an ordering of the set of vertices of a connected graph. Publ. Fac. Sci. Univ. Brno, 412, 1960. Google Scholar
  23. Yann Strozecki et al. Enumeration complexity. Bulletin of EATCS, 3(129), 2019. URL:
  24. Robert Endre Tarjan. A class of algorithms which require nonlinear time to maintain disjoint sets. Journal of computer and system sciences, 18(2):110-127, 1979. Google Scholar
  25. Takeaki Uno. Two general methods to reduce delay and change of enumeration algorithms. Technical report, National Institute of Informatics, 2003. URL:
  26. Kunihiro Wasa. Enumeration of enumeration algorithms. CoRR, 2016. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail