We show in Section 3.2 an algorithm with complexity O ( N $^{3}$) for the K -sample prob- lem for computing the aggregation by maximum for all m at once. This algorithm also enables calculating the regularized maximum statistic of Section 2.1 in O ( N $^{3}$). The algorithms for aggregating by maximum in the independence problem are ex- ponential in m , and therefore infeasible for modest N and m > 4. However, for m = 3 and m = 4 we provide efficient algorithms with O ( N $^{2}$) and O ( N $^{3}$) complexity, respectively, for the DDP test statistics. The algorithms for aggregation by summation are efficient due to two key observa- tions. First, because the score per partition is a sum of contributions of individual cells, and the total number of cells is much smaller than the number of partitions (unless m = 2 in the K -sample problem, and m ≤ 4 when using DDP in the indepen- dence problem, see Remark 3.1 below). Therefore, we can interchange the order of summation between cells and partitions and thus achieve a big gain in computational efficiency, since it is easy to calculate in how many partitions each cell appears, see equations (3.1) and (3.4). Second, because for a fixed m the number of partitions in which a specific cell appears depends only on the width (and for independence testing, also length) of the cell, the data-dependent computations do not depend on m : the test statistics are the sum of cell scores for every width for the K -sample test, and for every combination of width and length for the independence test, see equations (3.2) and (3.5). The complexity of the algorithm remains the same even when the scores are computed for all m s, since the complexity is determined by a preprocessing phase which is shared by all m s. Therefore, the complexity for the regularized scores is the same as the complexity for a single m . 21 3.1 Aggregation by summation