Selection on X1 + X2 + ··· + Xm with layer-ordered heaps Patrick Kreitzberg1, Kyle Lucke2, Oliver Serang2* 1 Department of Mathematics, University of Montana, Missoula, MT, USA 2 Department of Computer Science, University of Montana, Missoula, MT, USA *
[email protected] Abstract Selection on X1 + X2 + ··· + Xm is an important problem with many appli- cations in areas such as max-convolution, max-product Bayesian inference, calculating most probable isotopes, and computing non-parametric test statistics, among others. Faster-than-naïve approaches exist for m = 2: Frederickson (1993) published the optimal algorithm with runtime O(k) and Kaplan et al. (2018) has since published a much simpler algorithm which makes use of Chazelle’s soft heaps (2003). No fast methods exist for m > 2. Johnson & Mizoguchi (1978) introduced a method to compute the th d m e single k value when m > 2, but that method runs in O(m · n 2 log(n)) d m e time and is inefficient when m 1 and k n 2 . In this paper, we introduce the first efficient methods, both in theory and practice, for problems with m > 2. We introduce the “layer-ordered heap,” a simple special class of heap with which we produce a new, fast selection algorithm on the Cartesian product. Using this new algorithm to perform k-selection on the Cartesian product of m arrays of length n has runtime 2 o(k · m). We also provide implementations of the algorithms proposed and evaluate their performance in practice. Introduction Sorting all values in A + B, where A and B are arrays of length n and A + B arXiv:1910.11993v2 [cs.DS] 16 Aug 2020 is the Cartesian product of these arrays under the + operator, is nontrivial.