A Dichotomy on Constrained Topological Sorting
We introduce the constrained topological sorting problem (CTS-problem): given a target language L and a directed acyclic graph (DAG) G with labeled vertices, determine if G has a topological sort which forms a word that belongs to L. This natural problem applies to several settings, including scheduling with costs or verifying concurrent programs. It also generalizes the shuffle problem of formal language theory, which asks if a list of input strings has an interleaving that achieves a target string. We accordingly call constrained shuffle problem (CSh-problem) the restriction of our CTS-problem where the input DAG consists of disjoint strings. We study the complexity of the CTS-problem and CSh-problem for regular target languages: for each fixed regular language L, we call CTS(L) and CSh(L) the corresponding problems, where the input is the DAG. Our goal is to characterize the regular languages for which these problems are tractable. We show that both problems are tractable (in NL) for unions of monomials, a useful language class for pattern matching, as well as some other cases. We extend this for the CSh-problem to unions of district group monomials. We also show NP-hardness for some other languages such as (ab)^*. These results lead to a dichotomy for a different problem phrasing, when the target is specified as a semiautomaton to enforce some closure assumptions, and where the semiautomaton is assumed to be counter-free. In this case, both problems are in NL if the transition monoid of the semiautomaton is in some class, and NP-hard otherwise. Without the counter-freeness assumption, we can extend the dichotomy to a partial result for the CSh-problem. Our proofs use a variety of tools ranging from complexity theory, combinatorics, algebraic automata theory, Ramsey's theorem, as well as a custom reduction and other new techniques.
READ FULL TEXT