# counting_linear_extensions_of_sparse_posets__add195b5.pdf Counting Linear Extensions of Sparse Posets Kustaa Kangas Teemu Hankala Teppo Niinim aki Mikko Koivisto University of Helsinki, Department of Computer Science, Helsinki Institute for Information Technology HIIT, Finland {jwkangas,tjhankal,tzniinim,mkhkoivi}@cs.helsinki.fi We present two algorithms for computing the number of linear extensions of a given n-element poset. Our first approach builds upon an O(2nn)-time dynamic programming algorithm by splitting subproblems into connected components and recursing on them independently. The recursion may run over two alternative subproblem spaces, and we provide heuristics for choosing the more efficient one. Our second algorithm is based on variable elimination via inclusion exclusion and runs in time O(nt+4), where t is the treewidth of the cover graph. We demonstrate experimentally that these new algorithms outperform previously suggested ones for a wide range of posets, in particular when the posets are sparse. 1 Introduction Determining the number of linear extensions of a given poset (equivalently, topological sorts of a directed acyclic graph) is a fundamental problem in order theory, with applications in areas such as sorting [Peczarski, 2004], sequence analysis [Mannila and Meek, 2000], convex rank tests [Morton et al., 2009], preference reasoning [Lukasiewicz et al., 2014], and learning probabilistic models from data [Wallace et al., 1996; Niinim aki and Koivisto, 2013]. Brightwell and Winkler [1991] showed that exact counting of linear extensions is #P-complete and therefore not tractable for general posets unless P = NP. By dynamic programming over the lattice of upsets (see, e.g., De Loof et al. [2006]) linear extensions can be counted in time O(|U| w), where U is the set of upsets and w is the poset width. This implies the worst case bound O(2nn) for a poset on n elements, which to our knowledge is the best to date. Though exponential in n, the algorithm can be very fast for posets with few upsets. In particular, it holds that |U| = O(nw), since every poset can be partitioned into w chains and an upset can be specified by the number of elements it contains from each chain. Hence the algorithm runs in polynomial time for bounded width. Conversely, the set U can be very large when the order relation is This work was supported in part by the Academy of Finland, grants 125637, 255675, and 276864. sparse, which raises the question if sparsity can be exploited for counting linear extensions faster. In this work we present two approaches to counting linear extensions that target sparse posets in particular. In Section 2 we augment the dynamic programming algorithm by splitting each upset into connected components and then computing the number of linear extensions by recursing on each component independently. We also survey previously proposed recursive techniques for comparison. In Section 3 we show that the problem is solvable in time O(nt+4), where t is the treewidth of the cover graph. While our result stems from a well-known method of nonserial dynamic programming [Bertel e and Brioschi, 1972], known as variable elimination and by other names [Dechter, 1999; Koller and Friedman, 2009, Chap. 9] global constraints in the problem hamper its direct, efficient use. To circumvent this obstacle, we apply the inclusion exclusion principle to translate the problem into multiple problems without such constraints, which are then solved by variable elimination. In Section 4 experimental results are presented to compare the two algorithms against previously known techniques. We conclude with some open questions in Section 5. 1.1 Related Work A number of approaches for breaking the counting task into subproblems have been considered before. Peczarski [2004] reports a significant gain on some families of posets by recursively decomposing them into connected components and so called admissible partitions; however, this procedure has an unknown asymptotic complexity. Li et al. [2005] present another algorithm that recursively splits a poset into connected components and so called static sets. Besides bounded width, polynomial-time algorithms exist for several restricted families of posets such as series-parallel posets [M ohring, 1989], posets whose cover graph is a polytree [Atkinson, 1990], posets with a bounded decomposition diameter [Habib and M ohring, 1987], and N-free posets of a bounded activity [Felsner and Manneville, 2014]. Fully polynomial time randomized approximation schemes are known for estimating the number of linear extensions [Dyer et al., 1991; Bubley and Dyer, 1999]. For listing all linear extensions there exist algorithms that spend O(1) time per linear extension on average [Pruesse and Ruskey, 1994] and in the worst case [Ono and Nakano, 2007]. Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence (IJCAI-16) Figure 1: A poset (left) and its cover graph as a Hasse diagram. The reflexive arcs in the poset are omitted for clarity. 1.2 Preliminaries A partially ordered set or a poset is a pair (P, P ), where P is a set and P is an order relation on P, that is, a binary relation that is reflexive, antisymmetric, and transitive. The elements (a, b) of P are denoted simply a P b. Elements a, b 2 P are comparable if a P b or b P a, and otherwise incomparable, denoted a||P b. We say that a is a predecessor of b, denoted a