Topological Sorting with Regular Constraints

Authors Antoine Amarilli, Charles Paperman

Thumbnail PDF


  • Filesize: 450 kB
  • 14 pages

Document Identifiers

Author Details

Antoine Amarilli
  • LTCI, Télécom ParisTech, Université Paris-Saclay
Charles Paperman
  • Université de Lille

Cite AsGet BibTex

Antoine Amarilli and Charles Paperman. Topological Sorting with Regular Constraints. In 45th International Colloquium on Automata, Languages, and Programming (ICALP 2018). Leibniz International Proceedings in Informatics (LIPIcs), Volume 107, pp. 115:1-115:14, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2018)


We introduce the constrained topological sorting problem (CTS): given a regular language K and a directed acyclic graph G with labeled vertices, determine if G has a topological sort that forms a word in K. This natural problem applies to several settings, e.g., scheduling with costs or verifying concurrent programs. We consider the problem CTS[K] where the target language K is fixed, and study its complexity depending on K. We show that CTS[K] is tractable when K falls in several language families, e.g., unions of monomials, which can be used for pattern matching. However, we show that CTS[K] is NP-hard for K = (ab)^* and introduce a shuffle reduction technique to show hardness for more languages. We also study the special case of the constrained shuffle problem (CSh), where the input graph is a disjoint union of strings, and show that CSh[K] is additionally tractable when K is a group language or a union of district group monomials. We conjecture that a dichotomy should hold on the complexity of CTS[K] or CSh[K] depending on K, and substantiate this by proving a coarser dichotomy under a different problem phrasing which ensures that tractable languages are closed under common operators.

Subject Classification

ACM Subject Classification
  • Mathematics of computing → Graph algorithms
  • Topological sorting
  • shuffle problem
  • regular language


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


  1. Kunal Agrawal, Jing Li, Kefu Lu, and Benjamin Moseley. Scheduling parallel DAG jobs online to minimize average flow time. In Proc. SODA, 2016. Google Scholar
  2. J. Almeida. Finite Semigroups and Universal Algebra. Series in algebra. World Scientific, 1994. Google Scholar
  3. Antoine Amarilli. Generalization of Dilworth’s theorem for labeled DAGs, 2016. URL:
  4. Antoine Amarilli, M. Lamine Ba, Daniel Deutch, and Pierre Senellart. In Proc. TIME, 2017.
  5. Antoine Amarilli and Charles Paperman. A dichotomy on constrained topological sorting. CoRR, abs/1707.04310, 2017. URL:
  6. Manuel Bodirsky and Jan Kára. The complexity of temporal constraint satisfaction problems. JACM, 57(2):9, 2010. Google Scholar
  7. Manuel Bodirsky, Barnaby Martin, and Antoine Mottet. Discrete temporal constraint satisfaction problems, 2015. URL:
  8. Sam Buss and Michael Soltys. Unshuffling a square is NP-hard. JCSS, 80(4), 2014. Google Scholar
  9. Robert P. Dilworth. A decomposition theorem for partially ordered sets. Annals of Mathematics, 1950. Google Scholar
  10. Joey Eremondi, Oscar H Ibarra, and Ian McQuillan., 2016. URL:
  11. Tomás Feder and Moshe Y. Vardi. The computational structure of monotone monadic SNP and constraint satisfaction: A study through Datalog and group theory. SIAM J. Comput., 28(1), 1998. Google Scholar
  12. M. R. Garey and David S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman and Company, 1979. Google Scholar
  13. Michael R. Garey and David S. Johnson. Complexity results for multiprocessor scheduling under resource constraints. SIAM J. Comput, 1975. Google Scholar
  14. M. Holcombe. Algebraic Automata Theory. Cambridge Studies in Advanced Mathematics. Cambridge University Press, 1982. Google Scholar
  15. Neil Immerman. Nondeterministic space is closed under complementation. SIAM J. Comput, 17(5), 1988. Google Scholar
  16. David S. Johnson. The NP-completeness column: an ongoing guide. Journal of Algorithms, 5(2), 1984. Google Scholar
  17. John Kececioglu and Dan Gusfield. Reconstructing a history of recombinations from a set of sequences. Discrete Applied Mathematics, 88(1-3), 1998. Google Scholar
  18. Takayuki Kimura. An algebraic system for process structuring and interprocess communication. In Proc. STOC, 1976. Google Scholar
  19. Anthony Mansfield. On the computational complexity of a merge recognition problem. Discrete Applied Mathematics, 5(1), 1983. Google Scholar
  20. Robert McNaughton and Seymour Papert. Counter-Free Automata. MIT Press, 1971. Google Scholar
  21. W. F. Ogden, W. E. Riddle, and W.C. Rounds. Complexity of expressions allowing concurrency. In Proc. POPL, 1978. Google Scholar
  22. Charles Paperman. Semigroup online, 2018. URL:
  23. Jean-Éric Pin. Syntactic semigroups. In Handbook of formal languages, Vol. 1, pages 679-746. Springer, Berlin, 1997. Google Scholar
  24. Jean-Éric Pin and Pascal Weil. Polynominal closure and unambiguous product. TCS, 30(4), 1997. Google Scholar
  25. Jean-Éric Pin. Polynomial closure of group languages and open sets of the Hall topology. TCS, 169(2), 1996. Google Scholar
  26. Romeo Rizzi and Stéphane Vialette. On recognizing words that are squares for the shuffle product. TCS, 2017. Google Scholar
  27. M. P. Schützenberger. Sur le produit de concaténation non ambigu. Semigroup forum, 13, 1976/77. Google Scholar
  28. Róbert Szelepcsényi. The method of forced enumeration for nondeterministic automata. Acta Informatica, 26(3), 1988. Google Scholar
  29. Pascal Tesson and Denis Thérien. The computing power of programs over finite monoids. J. Autom. Lang. Comb., 7(2), 2001. Google Scholar
  30. Pascal Tesson and Denis Thérien. Semigroups, algorithms, automata and languages, 1, 2002.
  31. Denis Thérien and Thomas Wilke. Over words, two variables are as powerful as one quantifier alternation. In Proc. STOC, 1998. Google Scholar
  32. Manfred K. Warmuth and David Haussler. On the complexity of iterated shuffle. JCSS, 28(3), 1984. Google Scholar