arXiv:2610.29280cs.DSOct 2026

Manuscript Offprint

arXiv:2610.29280

On the Largest Cardinality Subset Sum

Deepak Bhati, Anubhav Dhar, Pranjal Dutta, Mahesh Sreekumar Rajasree, Karol Węgrzycki

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We study Largest Cardinality Subset Sum (LCSS): given nn nonnegative integers and a target tt, compute a subset summing to tt with maximum cardinality. We also consider its all-targets version (AT-LCSS), which asks for this maximum for every sum s∈{1,…,t}s \in \{1, \ldots, t\}. The LCSS problem sits squarely between the subset sum and the knapsack problem. A straightforward dynamic-programming algorithm runs in time O(nt)\mathcal{O}(nt) and solves AT-LCSS, and using Jin and Bringmann (both in STOC 2024, independent work) 0-1 knapsack results we achieve O~(n+amax⁡2)\widetilde{\mathcal{O}}(n + a_{\max}^2)-time1^1 deterministic algorithm for LCSS.

Our main result is a randomized O~(n+nt)\widetilde{\mathcal{O}}(n + \sqrt{n}t)-time algorithm for LCSS. Then, we complement this result with a randomized O~(n+t3/2)\widetilde{\mathcal{O}}(n + t^{3/2})-time algorithm for AT-LCSS. Together, our two algorithms give an O~(n+tmin⁡{n,t})\widetilde{\mathcal{O}}(n + t \min\{\sqrt{n}, \sqrt{t}\})-time algorithm for LCSS.

As an application of AT-LCSS, we solve the search version of Projection Subset Sum, introduced by Dutta and Rajasree (SYNSAC 2023), in O~(n+t3/2)\widetilde{\mathcal{O}}(n+t^{3/2}) time for every fixed ℓp\ell_p norm with p⩾1p \geqslant 1. For ℓ1\ell_1, we obtain O~(n+t)\widetilde{\mathcal{O}}(n+t) time, removing the unique-representation assumption required by their algorithm. Both algorithms output an optimal modified vector and a witnessing subset.

2012 ACM Subject Classification Theory of computation → Design and analysis of algorithms

Keywords and phrases subset sum, cardinality, pseudopolynomial algorithms

Funding Anubhav Dhar: Supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) grant number 559177164.

Pranjal Dutta: Supported by Nanyang Assistant Professorship as well as by the SUG Grant (#025774-00001), funded by Nanyang Technological University Singapore.

Mahesh Sreekumar Rajasree: Funded by the European Union (ERC, LACONIC, 101041207). Views and opinions expressed are those of the authors only and do not necessarily reflect those of the European Union or the European Research Council. Neither the European Union nor the granting authority can be held responsible for them.

Karol Wegrzycki: Supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) grant number 559177164.

1^{1} The notation O~(⋅)\widetilde{\mathcal{O}}(\cdot) hides polylogarithmic factors in the argument

1 Introduction

The Subset Sum problem asks whether, given nonnegative integers a1,…,ana_1, \ldots, a_n and a target tt, there exists a subset of the input items that sums exactly to tt. It is a basic example of an NP-complete problem that admits a pseudopolynomial algorithm: Bellman's dynamic program takes O(nt)\mathcal{O}(nt) time [3]. Subsequent work has substantially improved the dependence on nn and tt. Koiliaris and Xu gave a deterministic O~(nt)\tilde{\mathcal{O}}(\sqrt{n}t)-time algorithm [15], and Bringmann [4] and, later, Jin and Wu [14] gave randomized O~(n+t)\tilde{\mathcal{O}}(n+t)-time algorithms. Recently, Chan derandomized these results and gave a deterministic O~(t)\tilde{\mathcal{O}}(t)-time algorithm for Subset sum [6]. These algorithms determine which sums in {0,…,t}\{0, \ldots, t\} are attainable, i.e. appear as a sum of some subset of input items. A natural next question is what can be learned about the subsets attaining a given target. We study the maximum size of such a subset. Items are distinguished by their indices, even when their values are equal.

▶ Definition 1 (Largest Cardinality Subset Sum (LCSS)). Given nonnegative integers a1,…,ana_1, \ldots, a_n and a positive target tt, LCSS asks for max⁡{∣S∣:S⊆{1,…,n},∑i∈Sai=t}\max\{|S| : S \subseteq \{1, \ldots, n\}, \sum_{i \in S} a_i = t\}, else report if tt is unattainable.

Thus LCSS refines the usual decision problem: it distinguishes two attainable representations of the same target by their cardinalities. It also has a direct interpretation as a structured 0-1 knapsack problem: we give item ii weight aia_i and profit Mai+1Ma_i + 1, where M>nM > n, and set the knapsack capacity to tt. Every subset of weight exactly tt has profit Mt+∣S∣Mt + |S|, whereas every subset of weight at most t−1t - 1 has profit at most M(t−1)+n<MtM(t - 1) + n < Mt. Consequently, if tt is attainable, an optimal knapsack solution is a subset that sums to tt and has maximum cardinality among all the subsets that sum to tt; if it is unattainable, the optimal profit is below MtMt. This embedding explains why recording only attainable sums, as in ordinary subset sum, does not immediately give the desired optimum. In fact, at the fine-grained level, this places LCSS in between the subset sum and the knapsack problem; LCSS is at least as hard as subset sum, and knapsack is at least as hard as LCSS. These observations make LCSS an interesting problem to study.

0-1 knapsack for single capacity: Jin [12] gave a deterministic algorithm that runs in time O~(n+amax⁡2)\tilde{\mathcal{O}}(n+a_{\max}^2), whereas Bringman [5] also (independently) gave a deterministic O~(n+amax⁡2)\tilde{\mathcal{O}}(n+a_{\max}^2)-time algorithm for the bounded knapsack problem (where each item comes with a multiplicity). Here amax⁡a_{\max} denotes the maximum weight item. Using the above reduction and these two algorithms, we get O~(n+amax⁡2)\tilde{\mathcal{O}}(n+a_{\max}^2)-time algorithm for LCSS.

There is also a useful analogy with change-making. The change-making problem minimizes the number of coins summing to a target, with unlimited use of each denomination. In LCSS, each input item can be used at most once, and the number of selected items is maximized. Both problems invite a distinction between a single specified target and all targets up to a bound. This distinction has proved consequential for change-making: Chan and He obtained near-linear-in-t algorithms for the single-target problem and an O~(t4/3)\tilde{\mathcal{O}}(t^{4/3})-time algorithm for its all-targets version [7]. We likewise study both versions of LCSS.

▶ Definition 2 (All-Targets Largest Cardinality Subset Sum (AT-LCSS)). Given nonnegative integers a1,…,ana_1, \ldots, a_n and a positive integer tt, AT-LCSS asks, for every s∈{1,…,t}s \in \{1, \ldots, t\}, for the maximum cardinality of a subset S⊆{1,…,n}S \subseteq \{1, \ldots, n\} with Σ(S)=s\Sigma(S) = s, else report if ss is unattainable.

A straightforward dynamic program computes the optimum for every sum up to tt in O(nt)\mathcal{O}(nt) time: when item aia_i is processed, the best cardinality at sum ss is compared with one plus the previous best cardinality at s−ais - a_i. Koiliaris and Xu [15] also discuss the problem of subset sums with cardinality information. They further provide an O~(nt)\tilde{\mathcal{O}}(nt)-time algorithm that gives

On the Largest Cardinality Subset Sum

all the attainable subset sums with complete cardinality information, not just the maximum. However, their improvement of the complexity from O~(nt)\tilde{\mathcal{O}}(nt) to O~(nt)\tilde{\mathcal{O}}(\sqrt{nt}) loses information regarding cardinalities. This suggests that solving LCSS in O~(nt)\tilde{\mathcal{O}}(\sqrt{nt}) time is an interesting problem. On the other hand, Axiotis and Tzamos [2] give an O(Dt)\mathcal{O}(Dt)-time algorithm for the knapsack problem, with all weights being less than or equal to t, where D denotes the number of distinct items in the instance. This algorithm, with the aforementioned reduction of LCSS to knapsack, gives a O(Dt)\mathcal{O}(Dt)-time algorithm for AT-LCSS, and consequently for LCSS too.

The subset-sum algorithms in [4, 14, 6] do not, on their own, preserve the largest cardinality for each sum. Related work has examined other forms of cardinality information: Dutta and Rajasree [9] study the Hamming weights of all solutions when the number of solutions is bounded, while Antonopoulos, Pagourtzis, Petsalakis, and Vasilakis [1] discuss algorithms for subset-sum variants with target-cardinality constraints.

References (25)