Manuscript Offprint
arXiv:2610.29280On the Largest Cardinality Subset Sum
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 nonnegative integers and a target , compute a subset summing to with maximum cardinality. We also consider its all-targets version (AT-LCSS), which asks for this maximum for every sum . The LCSS problem sits squarely between the subset sum and the knapsack problem. A straightforward dynamic-programming algorithm runs in time and solves AT-LCSS, and using Jin and Bringmann (both in STOC 2024, independent work) 0-1 knapsack results we achieve -time deterministic algorithm for LCSS.
Our main result is a randomized -time algorithm for LCSS. Then, we complement this result with a randomized -time algorithm for AT-LCSS. Together, our two algorithms give an -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 time for every fixed norm with . For , we obtain 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.
The notation hides polylogarithmic factors in the argument
1 Introduction
The Subset Sum problem asks whether, given nonnegative integers and a target , there exists a subset of the input items that sums exactly to . It is a basic example of an NP-complete problem that admits a pseudopolynomial algorithm: Bellman's dynamic program takes time [3]. Subsequent work has substantially improved the dependence on and . Koiliaris and Xu gave a deterministic -time algorithm [15], and Bringmann [4] and, later, Jin and Wu [14] gave randomized -time algorithms. Recently, Chan derandomized these results and gave a deterministic -time algorithm for Subset sum [6]. These algorithms determine which sums in 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 and a positive target , LCSS asks for , else report if 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 weight and profit , where , and set the knapsack capacity to . Every subset of weight exactly has profit , whereas every subset of weight at most has profit at most . Consequently, if is attainable, an optimal knapsack solution is a subset that sums to and has maximum cardinality among all the subsets that sum to ; if it is unattainable, the optimal profit is below . 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 , whereas Bringman [5] also (independently) gave a deterministic -time algorithm for the bounded knapsack problem (where each item comes with a multiplicity). Here denotes the maximum weight item. Using the above reduction and these two algorithms, we get -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 -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 and a positive integer , AT-LCSS asks, for every , for the maximum cardinality of a subset with , else report if is unattainable.
A straightforward dynamic program computes the optimum for every sum up to in time: when item is processed, the best cardinality at sum is compared with one plus the previous best cardinality at . Koiliaris and Xu [15] also discuss the problem of subset sums with cardinality information. They further provide an -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 to loses information regarding cardinalities. This suggests that solving LCSS in time is an interesting problem. On the other hand, Axiotis and Tzamos [2] give an -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 -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.
A related motivation for Projection Subset Sum comes from neural-network pruning. The strong lottery ticket hypothesis asks whether a randomly initialized network contains a subnetwork that approximates a given target network [20, 18]. Pensia et al. [19] study this question using random subset sums, while Xiong, Liao, and Kyrillidis [22] additionally allow bounded perturbations of the weights. This combines selecting existing weights with slightly modifying them to improve approximation. Projection Subset Sum captures a related question for a list of numbers: how little must the numbers be changed so that some subset sums exactly to a prescribed target?
1.2 Our results
The previous discussion already gives us -time and -time algorithms for LCSS. Our main result is a faster pseudopolynomial-time algorithm for the regime when and . Note that hides polylogarithmic factors.
▶ Theorem 3. For any fixed integer constant , there exists a randomized algorithm that solves LCSS on nonnegative integers with target in time , with error probability at most .
Thus, up to polylogarithmic factors, our algorithm reduces the coefficient of t from n to in the running time complexity. It computes the exact maximum cardinality of a subset summing to t, or reports that t is unattainable, with high probability.
Very recently, Jin and Mao [13, Proposition D.3] give a conditional result for LCSS on positive inputs. If there is an algorithm running in that decomposes all subset sums of positive integers bounded by into an arithmetic progression with a common, then they managed to show that LCSS can be solved in time. Their result would match the running time of our result, if , however the existence of such a fast algorithm is open [13]. Theorem 3 avoids this unresolved assumption and achieves the same running-time bound unconditionally.
Our second result focuses on the all-targets version, in which the maximum cardinality must be computed for every target .
▶ Theorem 4. For any fixed integer constant , there exists a randomized algorithm that solves AT-LCSS on nonnegative integers with target in time , with failure probability at most .
This algorithm improves the discussed algorithm when . The probability guarantee holds simultaneously for all targets. Beyond the time needed to read the input, the running time depends only on , rather than on the number of items. The two bounds are complementary. Since the all-targets algorithm also solves any single-target instance, together they yield an -time algorithm for LCSS.
By exploiting the cardinality information provided by AT-LCSS, we also give a randomized -time algorithm for Projection Subset Sum in the norm (PSS ) for all fixed .
▶ Theorem 5. For fixed , given nonnegative integers and an integer , there is a randomized algorithm that outputs an optimal solution to in time , with failure probability at most .
And, for the norm, we give a randomized -time algorithm using Bringmann's subset-sum algorithm; see Theorem 27. Both the PSS algorithms output an optimal vector and a set witnessing its feasibility, with failure probability at most , without the unique-representation assumption.
Organization of the paper. Section 2 gives an overview of our algorithms. Section 3 introduces the notation and tools used. Section 4 presents the algorithm for LCSS via solving TCSS. The algorithm for AT-LCSS can be found in Section 5. The algorithms for Projection Subset Sum can be found in Section 6. Appendix A contains deferred lemmas and proofs.
Declaration on the Use of AI Tools. Generative AI tools, including ChatGPT and Claude, were used solely for proofreading, language editing, improving presentation, and identifying potential inconsistencies. All technical contributions are original to the authors, who independently verified relevant AI-generated suggestions and take full responsibility for the manuscript.
2 Technical Overview
Previously, Bringmann [4] gave an -time algorithm to output all possible subset sums capped by an integer , in a collection of elements. This was later simplified by Jin and Wu [14], and then derandomized by Chan [6]. For this paper, we give a bivariate equivalent result of [14], which computes both cardinalities and sums of all possible subsets with caps in both cardinality and the sum.
On the Largest Cardinality Subset Sum
▶ Lemma 6. Given nonnegative integers , positive integers and , and a parameter , there is a randomized algorithm with one-sided error probability at most that computes the set in time
The returned set is always a subset of .
A proof idea is as follows: Consider Bringmann's algorithm [4]. Essentially, the algorithm consists of a collection of convolutions to keep track of sums. Whenever a sum exceeds t, this sum is dropped from further consideration. One can modify Bringmann's algorithm to simply consider pairs of cardinalities and sums, then convolve these sets of pairs, and drop pairs which exceed either the cardinality bound or the sum cap. The resulting algorithm has the required running time. Similarly, Jin and Wu's algorithm [14] can also be modified accordingly to prove Lemma 6; for completeness, we provide a complete proof in Appendix A.2.
2.1 Solving Largest Cardinality Subset Sum
We start by focusing on the intermediate problem of finding whether a subset of a given sum and a given cardinality exists.
▶ Definition 7 (Target Cardinality Subset Sum (TCSS)). Let be nonnegative integers. TCSS asks whether there is a subset with and .
We first provide an algorithm for TCSS, and then use it to solve LCSS.
Algorithm for TCSS. Our approach can be informally described as follows. We process items smaller than and items larger than separately. At most many large items can contribute to a solution; we use Lemma 6 to essentially list all cardinalities and sums of all relevant subsets with at most large items. Next, we color the indices randomly into colors. For each color class, we compute all cardinality–sum pairs of the small items (using Lemma 6) with a sum cap of . We merge these cardinality–sum pairs in a merge-sort fashion: at each step, merge two sets of cardinality–sum pairs to get a larger one. However, doing this naively would blow up the sizes of these sets. We overcome this issue by keeping only the pairs whose cardinality deviates from the expected cardinality of any solution by at most , while discarding others. This crucial step aids in making the algorithm efficient ( time spent on each level), while the Chernoff bound guarantees that with high probability, a solution is not discarded. Finally, our algorithm decides if a solution exists by checking the existence of a compatible subset among the small items for each cardinality–sum pair of the large items. An overview of the details and the techniques is as follows.
Assume that the number of items is a power of 4, and all items are bounded by . We start by color coding the indices into color classes. Formally, construct a random partition of the indices. We define , for .
Assume that a solution exists, i.e. let be such that and . Consider the following breakup of the input elements into heavy elements and light elements , with their respective intersection with the solutions being and .
It is easy to see that has size at most , as all elements of have a value of at least . Using Lemma 6 on the indices in , we compute
in time . We must have .
We now focus on the light items. Using the Chernoff bound, we show that (i) each color class is of size , (ii) the size of intersection of with a given subset of color classes deviates by at most from its expected intersection size, and (iii) the sum of elements in from any fixed color class is at most , i.e. the color classes split the sum somewhat evenly. More formally, we prove the following lemma.
▶ Lemma 16 (Simplified). With probability at least , we have all of the following.
-
, for ,
-
, for , , and
-
, for .
We now use these guarantees to compute the cardinalities and sums of relevant subsets of the light items. For each , we use Lemma 6 on , with cardinality bound and a cap of on the sum, to compute
An intuition behind is as follows. Notice that the expected value of over the randomness of color coding is exactly ; we only consider simply to work with integers, while staying close to the actual expected value. Moreover, since , it can be shown that the expected value of is in . Therefore, a pair corresponds to the existence of (at least) one subset which sums up to and has deviation of from the expected cardinality of . In fact, another application of the Chernoff bound shows that a pair corresponding to is in the set with high probability. Note that computing for all color classes takes time .
Continuing in the same spirit of working with pairs representing (i) deviation from expected size, and (ii) sum of the subset, our next aim is to obtain such pairs for subsets , even for . Observe that . If a subset deviates from the expected size (i.e. ) by , and a subset deviates from the expected size (which is again ) by , then their union deviates from the expected size of by . Moreover, the sum of is the sum of plus the sum of . This allows us to define a set of pairs and compute them recursively by taking the sum sets of the two lower-level sets and . Since we are working with the floor of the expectation, we must be slightly careful in the recursion
On the Largest Cardinality Subset Sum
computation. Formally, for and , we recursively compute
Note that we further trim the sets with the condition . This ensures that the sizes of these sets are bounded by . Further, it is enough to guarantee (from the Chernoff bound) that with high probability, the pair corresponding to deviation and sum for survives this trimming, (in this and all other lower levels of the recursion) and stays in the set . In particular, with high probability, the pair is in the set . We therefore return YES if some satisfies , and NO otherwise. Such a pair gives disjoint subsets of and whose union has cardinality and sum .
It remains to bound the time for computing the sets . Every satisfies and it can be shown that . Hence computing takes time using a fast convolution algorithm (see Lemma 28). There are such computations for a fixed value of , and many values of . Hence, the total running time amounts to . Together with the other steps, the total running time is . The details can be found in Theorem 17.
From TCSS to LCSS. To solve LCSS, we first decide whether there exists a subset with sum t and cardinality in an interval : This can be done by appending zero-valued items and calling a TCSS algorithm with target sum t and target cardinality h. With this, we can binary search for the largest cardinality of a subset summing up to t.
We first check if is a possible subset sum; if not, we terminate. Henceforth, assume that there exists a subset summing up to . Let be the largest cardinality of a subset summing to . We use binary search, starting with and , and maintain the invariant of throughout. At each iteration, we set , and check if there exists a subset with sum and cardinality in . Following the binary search framework, we set if such a subset exists; otherwise we set . When , we output .
There are calls, each on items, giving a total running time of . More details can be found in Section 4.
It still remains open whether one can get better algorithms for LCSS, possibly with a running time of .
2.2 Solving All-targets Largest Cardinality Subset Sum
For AT-LCSS, we assume without loss of generality that all items are positive (otherwise we simply delete all zero items and add back their count in all outputs). Bellman's dynamic program for knapsack [11, 3] can be adapted to give us an algorithm for AT-LCSS. We provide an algorithm with running time , which is an improvement in the regime , for some .
We follow the framework by Bringmann and Kociumaka as discussed in [17] (also see [7, Section 3]). They consider the all-targets change-making problem; recall that given a set of denominations, the problem asks for the smallest number of coins which sum up to 1, 2, ..., t (as discussed in Section 1). The framework can be broadly described as follows.
-
Set a threshold . Classify denominations larger than as heavy and the others light.
-
Compute relevant information from the heavy denominations in time . The crucial observation is to notice that in any solution, at most many coins appear from a heavy denomination.
-
Incorporate on top all light denominations using a classical dynamic programming approach, which takes a total time of . The crucial observation here is to notice that there are at most many light denominations.
This framework produces an algorithm with a running-time of . Setting minimizes this to .
Although AT-LCSS can be viewed as a 0-1 variant of the all-targets change-making problem, the specific algorithm for change-making does not directly give us an algorithm for AT-LCSS. We follow this broad framework of splitting into heavy and light items, but modify the specifics as follows.
Handling heavy items. Firstly, the algorithm for handling heavy denominations does not directly work for AT-LCSS. We overcome this obstacle using Lemma 6 instead: We compute the cardinalities and sums of all subsets of the heavy items with sum at most t and cardinality at most . This takes a total time of and allows us to extract the necessary information regarding the heavy items.
Reducing the count of light items. Secondly, the algorithm for light denomination crucially requires the number of light denominations to be bounded by . This is not the case for AT-LCSS; in fact, it is quite possible that all input items in an AT-LCSS are light, for some . Moreover, it is important to keep track of the exact multiplicities of items. We resolve this issue using a multiplicity reduction trick by Lawler [16] (see also the discussion on preprocessing multisets in [4, Section 2]) as follows. Consider each item initially having a profit of 1, then maximizing cardinality is equivalent to maximizing profit. Whenever there are at least three copies of items with value w and profit p, we delete two such copies and add a new element with value 2w and profit 2p. Such an operation is safe as the maximum profits for all target sums remain unchanged. Moreover, this additionally guarantees the number of items is at most . Moreover, this can be done in time .
Solving All-Targets Largest Cardinality Subset Sum. We present an overview of the algorithm solving AT-LCSS following the above framework. First, we count the number of zeros appearing in our input, and delete all such items. We add back to every output at the final step of our algorithm. Now, fix a threshold . Let be the indices of the heavy elements, and let be the indices of the light elements.
We start by computing the output of AT-LCSS for just the heavy items. For , let denote the largest cardinality of a subset of the heavy items summing up to exactly . Since all heavy items have value at least , we must have . Therefore to compute for all , we use Lemma 6 on with cardinality bound and a cap of on the sum. That is, we compute
On the Largest Cardinality Subset Sum
this can be done in time . Then we iterate over all pairs , and update to , if this causes an increase in its value.
To incorporate the light items, we use the multiplicity reduction trick by Lawler, i.e. in time , we transform the light items into a multiset of at most pairs of value and profit.
This allows us to use a dynamic programming approach as follows. First, let denote the maximum of the number of some selected heavy items plus the profit of some selected pairs among the first pairs of , such that their total weight is . Formally, if contains the elements , where are the values and are the respective profits, then for and ,
For the base case, we set for all ; these are the largest cardinalities of subsets summing up to , when no elements from are considered. For transitions, notice that can either contain the -th pair or not contain it. We take the maximum of the two. Formally,
After processing all items in , the answer is stored in for all . We finally add back the count of the deleted zero-valued items giving us the output
The dynamic program takes time . The total running time of the algorithm is therefore . Selecting minimizes this running time to . The details can be found in Section 5.
It is interesting to note that although it is possible to modify Bringmann and Kociumaka's framework for AT-LCSS, the improvements by Chan and He [7] do not extend directly. For the all targets change-making problem, they handle the heavy items identically, however for incorporating the light items a faster approach using binary (min, +)-convolution is used, making this step take merely time. Their algorithm hence has a total running time of . This is minimized by setting to . This approach crucially uses the fact that coins of a particular denomination can be selected an arbitrary number of times as opposed to the 0-1 nature of AT-LCSS. It remains open to get -time algorithms for AT-LCSS, possibly using a smarter modification of the framework by Chan and He.
3 Preliminaries
All logarithms are base 2. For a positive integer , we define and . We consider a multiset containing non-negative integers . We denote . For sets of pairs, we define their convolution as . This can be computed efficiently (see Lemma 28 in Appendix A.1). For completeness, we also state the well-known Chernoff bound.
▶ Lemma 8 (Chernoff Bound). Let be independent Bernoulli random variables. Let and let . Then, for all ,
Moreover, for any , we have .
4 Largest Cardinality Subset Sum
In this section we present a randomized algorithm for LCSS on nonnegative integers and target (recall Definition 1). We first describe an algorithm for TCSS with target cardinality (recall Definition 7), and then use it as a subroutine to solve LCSS. The running time of both algorithms is .
4.1 Algorithm for Target Cardinality Subset Sum
We may assume the following:
■ for every (if not, we replace values greater than by ), and
■ n is a power of four (if not, we simply add dummy items of value ).
The last assumption makes sure that , , etc are integers.
4.1.1 Color coding
We perform a random color coding of the indices into colors. Formally, let be a random partition of . That is, for each index , an integer is chosen uniformly at random, and is added to . We refer to these sets as color classes. For and , let .
4.1.2 Segregating the input and the solution
Assuming there exists a solution, we fix a solution , i.e. with and . First, we segregate the items into heavy and light weights as follows.
We also define the following sets.
Here and are defined for every integer . We refer to the sets as layers. We observe that these sets partition the sets and respectively;
These sets will help us define and derive various probabilistic guarantees. These, in turn, culminate in useful structural properties that we leverage to design our algorithm.
On the Largest Cardinality Subset Sum
4.1.3 Probabilistic guarantees
The goal of this section is to prove that the randomness in the color coding step guarantees that the input would be somewhat well structured. We prove various guarantees and unify them later in Lemma 16. All the probabilities in this section are over the random choice of the partition, i.e. the color coding. Moreover, recall that is a fixed constant.
We begin by showing that each color class has items with high probability. This bounds the size of the sub-instances processed by the algorithm. For this bound, we define
▶ Lemma 9. For every , .
Proof. We write , where is a random variable indicating whether . These variables are independent and . Therefore making Lemma 8 applicable. This gives .
We next bound the deviation of from its expectation . At each level, this deviation is with high probability. To state the bound, we define
▶ Lemma 10. For all , ,
Proof. If , both and lie in . Their difference in absolute value is therefore at most .
Otherwise, is a sum of independent Bernoulli variables with mean . We set . Since and , we have . Lemma 8 gives \Pr\left[||X \cap Z_j^{(\ell)}| - \mu\right| \geqslant \sqrt{3(4c + 1) \mu \log n}\right] \leqslant 2 \exp(-(4c + 1) \log n) \leqslant n^{-4c}. The last inequality follows from , since logarithms are base two and . Finally, , , and imply by Equation (2), proving the claim.
Note that , as every item of has value greater than ; if , then , a contradiction. Removing these items changes the preceding cardinality bound by at most , giving the following bound for . For this, we define
▶ Lemma 11. For all and ,
Proof. Using and , we obtain
By Equations (2) and (3), since , a deviation of at least on the left implies a deviation of at least for X. Lemma 10 now gives the desired bound.
the next lemma states that each color class contains at most items from , the large items of the fixed solution, with high probability. For this, we first define
▶ Lemma 12. For all , we have .
Proof. We observe that , where the inequality is because . Moreover, , where is the indicator variable of whether . Since , by Lemma 8 and Equation (4) we have .
For each layer , we similarly bound the number of solution items in a color class. The bound is with high probability. To state it, we define
▶ Lemma 13. Pr \left|X_\ell \cap Z_j\right| \geqslant \Gamma_{\ell,Z}^{(\text{size})}\right] \leqslant n^{-4c} for all .
Proof. We observe that , as for every and . Therefore, . Moreover, , where is the indicator variable of whether . Since by Equation (5), Lemma 8 gives . The last equality uses Equation (4). This proves the lemma.
We next convert this cardinality bound into a weight bound: for fixed and , the items in have total weight with high probability. For this bound, define
▶ Lemma 14. Pr for all .
Proof. Note that and for every . Assume the event . This implies . Substituting the values of , and (see Equations (4)–(6)), we get
Lemma 13 therefore implies .
Summing over the layers and including the smallest items in gives a bound of on the total weight of , with high probability. We define
▶ Lemma 15. For , we have .
On the Largest Cardinality Subset Sum
Proof. There are exactly layers . By Lemma 14 and a union bound, with probability at least , every one of them satisfies . Also, deterministically, . Since is the disjoint union of and the sets , these inequalities imply . The last inequality uses Equations (6) and (7). The probability of this is therefore at least .
The thresholds used in the preceding bounds are collected in Table 1 for reference.
Table 1 Thresholds in the color-class analysis.
| Threshold | Exact value | Asymptotic bound | Relevant lemma |
|---|---|---|---|
| Lemma 9 | |||
| Lemma 10 | |||
| Lemma 11 | |||
| Lemma 12 | |||
| Lemma 13 | |||
| Lemma 14 | |||
| Lemma 15 |
The next lemma aggregates all proven guarantees into one single statement. It follows by a union bound from Lemmas 9, 11, and 15.
▶ Lemma 16 (List of probabilistic guarantees). Over the random choice of the partition of the set , all the events below happen with probability at least
-
, for ,
-
, for , , and
-
, for .
Proof. There are color classes and sets . The first two properties have total failure probability at most . The proof of Lemma 15 bounds the failure probability of the third property, over all color classes, by . Thus the total is at most , since for .
4.1.4 Algorithm steps.
We now have the ingredients to describe our -time algorithm for TCSS. We use Lemma 16 to guarantee certain probabilistic structures. Then, with repeated usage of Lemma 6, we compute the cardinalities and sums of relevant subsets, while pruning out subsets which are 'far from expectation' and hence are ruled out as irrelevant by Lemma 8.
▶ Theorem 17. For any fixed integer constant , there exists a randomized algorithm solving TCSS on nonnegative integers with target in time , with error probability at most .
Proof. We first describe the algorithm, prove its correctness, bound its failure probability, and analyze its running time.
Description of the algorithm. We form the random color classes and the sets as described in Sections 4.1.1 and 4.1.2. If some color class has size more than , we return NO. In every call to Lemma 6 below, we set and use fresh randomness.
We apply Lemma 6 to with cardinality bound and target , to obtain . Every subset of of sum at most has fewer than items.
For each , we apply Lemma 6 to with cardinality bound and target . This gives us . We define
For , and , we define
For every , there is a subset of summing up to and having size . We return YES if some satisfies , NO otherwise.
Correctness. We first show that the pairs in and represent cardinalities and sums of existing subsets. Lemma 6 implies that for every there is with and . Likewise, for every there is with and .
▷ Claim. For every , , and , there is a subset such that and .
Proof. We proceed by induction on . If , the definition of gives with . Therefore, there is with and . Now, suppose and . By construction, there are and with , and .
By the induction hypothesis, there are subsets and such that, for , and . The sets and are disjoint and their union is . Hence has sum and cardinality , as required.
If the algorithm returns YES, there are and . The first pair gives a subset with and . Since , the claim gives a subset with and . The sets and are disjoint because and are disjoint. Thus has cardinality and sum , so the algorithm cannot return YES on a NO-instance.
Now fix a subset with and , independently of the random choices. Let be the event that all three properties of Lemma 16 hold. Let be the event that , and let be the event that for every . On , the algorithm does not return NO at its initial check, and for every .
On the Largest Cardinality Subset Sum
We next bound the shifted cardinality of used in the definition of . For every and , the event implies
Since , , and are integers, is an integer. The expression on the left is also an integer, and hence it is at most .
▷ Claim. If and both occur, then for every and , we have
Proof. We proceed by induction on . If , the pair belongs to by . Assuming , Equation (8) gives . Thus the contains . Now, suppose . By induction hypothesis,
The componentwise sum of these two pairs is , where
Substituting this value of into the defining relation for gives
Again, Equation (8) shows that , implying that the pair in Equation (9) belongs to .
At and , we have and . Thus, on , . On , the pair belongs to . Because and , these two pairs satisfy the acceptance condition, and the algorithm returns YES.
Failure probability. By Lemma 16, . By Lemma 6, each call fails with probability at most . Thus . For every partition satisfying , each of the calls for contains its eligible pair with failure probability at most . A union bound gives . Hence the total failure probability is at most .
Running time. The initial partition into color classes and preprocessing take time. Since , the dependence on in Lemma 6 contributes only polylogarithmic factors. Our initial check based on sizes of color classes ensures that every color class has at most items whenever we perform the remaining computations. The call to Lemma 6 for computing takes time. By Equation (7), the call to Lemma 6 for computing takes time. In total, computing for all takes
time. Next we compute for using Lemma 28. We bound for all .
▷ Claim 18. For , and , we have .
Proof. We proceed by induction on . If , the definition of gives for some . Every pair in is realized by a subset of with nonnegative sum at most , so . Now, suppose . By the definition of , some belongs to . Thus there are and with . By the induction hypothesis, . Hence .
Fix and . Every in either or satisfies by definition and by the claim. Therefore, Lemma 28 computes their sumset in time by Equations (3) and (7). Every pair in this sumset has and , so the sumset contains pairs. Scanning them to form also takes time. There are such computations for this value of , so their total time over all is
Finally, we store in a Boolean array indexed by . Its definition gives , and the claim gives ; thus initializing and populating the array takes time. The set has at most pairs, so scanning it and checking the acceptance condition takes time. This proves the theorem. Algorithm 1 summarizes the construction.
4.2 Algorithm for Largest Cardinality Subset Sum
TCSS asks to decide if there exists a subset with sum t and cardinality k. Our next step to solve LCSS is to decide if there exists a subset with sum t and cardinality in an interval . We show that this can be done by simply adding zeros to the instance and asking whether a subset exists with sum t and cardinality h.
▶ Lemma 19 (Target cardinality to cardinality in an interval). Let and be nonnegative integers, and let be integers. Then the following are equivalent:
-
There is a subset with and .
-
The TCSS instance obtained by appending zero-valued items, with target cardinality and target , is a YES-instance.
On the Largest Cardinality Subset Sum
Algorithm 1 FasterTCSS((a₁, ..., aₙ), t, k); see Theorem 17
1: Replace values greater than t by t + 1 and add values of t + 1 to get a power-of-four size. 2: Define A, B as above. ▷ see Section 4.1.2 3: , , , 4: ▷ Color classes; see Section 4.1.1 5: for do 6: Choose j independently and uniformly from . 7: 8: end for 9: if some then 10: return NO 11: end if 12: for do 13: ▷ Lemma 6 14: 15: end for 16: ▷ Lemma 6 17: for do 18: for do 19: 20: 21: end for 22: end for 23: for do 24: if then 25: return YES 26: end if 27: end for 28: return NO
Proof. Suppose the first statement holds, and let have and . Since , we can add of the appended zeros to . The resulting subset has cardinality and sum , proving the second statement. Conversely, suppose the second statement holds, and let have cardinality and sum in the augmented instance. The subset has sum , since all appended items have value zero. Moreover, , while . Thus satisfies the first statement.
This allows us to solve LCSS using a binary-search approach.
▶ Theorem 3. For any fixed integer constant , there exists a randomized algorithm that solves LCSS on nonnegative integers with target in time , with error probability at most .
Proof. First we test feasibility by calling Theorem 17 with target t and target cardinality n on the original items augmented by n zeros. A correct call returns YES exactly when the original instance has a subset of sum t and cardinality in . Since , this is equivalent to the existence of a subset of sum t. If the call returns NO, we output that no solutions exist. The test takes time and never declares an infeasible instance feasible.
If the feasibility test succeeds, set , . Let be the cardinality of the largest subset summing up to . Our invariant throughout will be ; this holds at initialization. At each iteration, we set and apply Theorem 17 with target cardinality to the original items augmented by zeros. By Lemma 19, a correct YES answer occurs exactly when the original instance has a subset of sum and cardinality in . From the invariant in the previous iteration, we had . Thus a correct YES answer implies , and a correct NO answer implies . We update and respectively for these cases, preserving the invariant. When , the invariant gives . Including the feasibility test, there are at most calls to Theorem 17, each on at most items. Their total time is . Conditioning on the history before any call fixes its input, Theorem 17 bounds its conditional error probability of any specific call by . A union bound gives total error at most . Algorithm 2 summarizes this.
Algorithm 2 FasterLCSS((a₁, ..., aₙ), t); see Theorem 3
1: if FasterTCSS((a₁, ..., aₙ, 0, ..., 0), t, n) = NO then ▷ Algorithm 1
2: return "No Subset with sum t"
3: end if
4: ,
5: while do
6:
7: if FasterTCSS((a₁, ..., aₙ, 0, ..., 0), t, h) = YES then
8:
9: else
10:
11: end if
12: end while
13: return
On the Largest Cardinality Subset Sum
5 All-Targets Largest Cardinality Subset Sum
We recall the problem of AT-LCSS (Definition 2): Given nonnegative integers and a positive integer , the task is to compute, for every , the largest cardinality of a subset of indices whose sum is . For this section, we assume without loss of generality that all items are positive (otherwise we simply delete all zero items and add back their count in all outputs, see proof of Theorem 4).
We fix an integer threshold . We define heavy and light elements as follows.
▶ Definition 20 (Heavy elements and light elements ). Let be heavy elements, and let be light elements.
We handle heavy items and light items separately, and then incorporate them to get an efficient algorithm for AT-LCSS.
5.1 Handling heavy items
A simple application of Lemma 6 allows us to efficiently compute and store for every the largest cardinality of a subset of the heavy element indices which sum up to .
▶ Lemma 21. There exists a randomized algorithm computing for every in time with failure probability .
Proof. Each item in is greater than . Hence every subset with sum at most has cardinality less than . We apply Lemma 6 once to with and to obtain with probability at least . Every returned pair is realized by a subset of . Since , the call takes time.
We initialize the array to and, for each returned pair , we replace by the maximum of its current value and ; the resulting entry is precisely the largest cardinality of a subset with sum .
For each sum , it is sufficient to store only this maximum cardinality . All items subsequently added come from the light items in the input.
5.2 Processing light items
We consider all items in the input to have an associated profit of 1. Then AT-LCSS asks for every , the maximum profit subset with values summing up to .
We now represent items by a pair , where is its value and is its profit. We consider the light items in the input. Initially, each light item is represented by . We now use the multiplicity reduction trick from Lawler [16], which deletes some of the existing items and introduces new items (possibly with profit more than 1) such that the maximum profit of subsets summing up to some does not change. This leads to a reduced total number of light items. We formally state it in the following lemma.
▶ Lemma 22 (Small number of (weight, profit) pairs from light items). In time , one can construct a multiset of size at most , which contains pairs of positive integers, such that for every
Proof. For each pair , we refer to as its weight and to as its profit. We first describe the construction of , prove that Equation (10) holds, then bound the size of and finally argue about the time complexity to compute .
Construction of . Initially, for each index we add to the pair . We repeatedly perform the following operations. We stop when neither applies.
-
If a pair occurs at least three times, we remove two copies and insert one copy of .
-
We delete every pair with .
Proof of Equation (10). We prove that for every , the value of
remains unchanged after each iteration, where denotes the current multiset. Fix . We suppose that in some iteration we replace two copies of a pair occurring at least three times by one copy of . We compare the value of this maximum on the multisets and immediately before and after this operation, respectively. We refer to all copies of which were not removed in this iteration as surviving copies.
The maximum cannot increase: given any submultiset of containing the newly inserted copy of , we replace that copy by the two copies of removed from . These two copies are distinct from all surviving copies, so this replacement respects multiplicities and preserves both total weight and total profit. On the other hand, a submultiset that does not contain the newly inserted copy is already available in .
The maximum cannot decrease either. Given any submultiset of containing at least two copies of , we replace two of its copies by the newly inserted copy of . We can select its remaining copies of from those surviving in . If the submultiset contains exactly one copy of , we select a surviving copy; such a copy exists because there were at least three copies before the operation. If it contains no copies of , we leave it unchanged. In each case, we retain all other selected pairs and preserve total weight and total profit.
Each iteration decreases the number of pairs by at least one. Hence the construction terminates after at most such iterations. Initially, we have one pair for each index . Thus subsets of correspond to submultisets of the initial pairs with the same total weight and with total profit equal to their cardinality, establishing Equation (10) at initialization. Since each iteration preserves the maximum in Equation (10), the equality holds for the final multiset as well.
Size of . We first observe that every pair occurring during the construction has the form for some . This is because initially this holds with and subsequently if we replace two copies of , the inserted pair is .
At termination, every pair in has weight at most and multiplicity at most two. For a pair in , its weight is at most , so . For each , there are thus possible pairs, each of multiplicity at most two. This gives us .
On the Largest Cardinality Subset Sum
Running time. For completeness, we describe an efficient implementation of the construction of . We start by storing the multiplicity of each possible pair in a two-dimensional array indexed by and . Distinct indices represent distinct pairs: the profit determines , and the weight then determines . We initialize the array to zero and count the input occurrences in the entries with , in time .
For each , we scan its entries in increasing order of . While the current multiplicity is at least three, we (i) decrease it by two and, (ii) if , increase the next entry (i.e. indexed by and ) by one. Each such step decreases the total number of items by at least one, so there are at most steps in total. Since updates only affect the entries with a larger value of , each entry which has already been processed has a multiplicity of at most two. We output these remaining copies. Scanning the array and writing the output take time. Hence the total running time is bounded by .
5.3 Algorithm for All-Targets Largest Cardinality Subset Sum
We now have all ingredients to prove Theorem 4.
▶ Theorem 4. For any fixed integer constant , there exists a randomized algorithm that solves AT-LCSS on nonnegative integers with target in time , with failure probability at most .
Proof. Let be the number of items with value 0. We now discard all items of value 0 (we simply add to every output in the end) and all items of value greater than . We set . Let and be the sets of indices of remaining items with values at most and greater than , respectively (recall Definition 20).
By Lemma 21, we compute for every , where is the maximum cardinality of a subset of whose sum is . By Lemma 22, we construct a multiset of weight-profit pairs such that, for every , the maximum profit of a submultiset of of weight equals the maximum cardinality of a subset of of sum . We enumerate the occurrences in as , where . For the correctness proof, we condition on the event that the call to Lemma 21 was successful. This happens with probability at least .
We approach using dynamic programming. The entry stores the maximum of the number of selected heavy items plus the profit of selected pairs among the first pairs of , subject to their total weight being . Formally, for and , we define
We initialize and, for , we compute
We prove by induction on that the recurrence computes the stated value of for every . For , no pair from is available, so by their definitions. Now let and assume the claim for . If , then a subset of the first pair indices having total weight at most cannot contain the -th pair . Consequently, . From now, we suppose that .
For the upper bound, we consider and satisfying such that . If , then . If , then , and hence . As at least one of these inequalities holds, we get
For the reverse inequality, we consider and satisfying such that . Since these subsets are also considered in the definition of , we get . Similarly, we consider and satisfying such that . We retain and replace by , thereby selecting the -th pair . The total weight becomes , so . Together, these inequalities give
The two inequalities Equations (11) and (12) give the desired equality and complete the induction.
It remains to relate to the original instance. For every , the definition of gives
The first equality is the definition of . For the second equality, we group the subsets by and maximize the heavy cardinality and light profit independently for each . The third equality follows from the definition of and Equation (10). The fourth equality follows from observing that subsets and form precisely the subsets of which sum up to . Every subset of of sum can be enlarged by all zero-valued items. Conversely, deleting zero-valued items from any original solution of sum leaves a subset of of the same sum. Thus the required answer is if .
Preprocessing takes time. The two lemmas take and time, respectively. The dynamic program takes time, and output takes time. Since and , the total is
The only randomized step is the heavy-item computation, which is correct for all targets simultaneously with probability at least by Lemma 21.
6 Projection Subset Sum
We consider the search version of Projection Subset Sum, introduced by Dutta and Rajasree [10].
On the Largest Cardinality Subset Sum
Throughout this section, and denote the vectors and , respectively. For an input , we set for every .
▶ Definition 23 (Projection Subset Sum (PSS_p)). Fix . Given nonnegative integers and a nonnegative integer , the PSS_p problem asks for a vector and a set such that and is minimized.
We assume and write . A sum is attainable if for some . When , we return and . When and , we return and . The proofs of the two PSS theorems below therefore assume and , so every feasible set is nonempty.
6.1 Projection Subset Sum for all norms
Before presenting our algorithm for , we first show how to use the AT-LCSS algorithm of Theorem 4 to find a largest subset whose elements sum to a prescribed target. When applying this theorem to items indexed by , we denote its output by and include .
▶ Lemma 24. Given nonnegative integers and an integer , there is a randomized algorithm that, with probability at least 5/6, outputs a largest subset with , or fail if no such subset exists, in time .
Proof. We first describe the algorithm, prove its correctness, bound its failure probability, and analyze its running time.
Description of the algorithm. Start with and . On a recursive instance , return if . For and , return if , and fail otherwise.
For and , split with . For each , append one item of value to and solve AT-LCSS with sum cap using Theorem 4 with (the addition of the item simply to ensures that the number of items in any recursive call is at least 2, hence the failure probability is at most ). The added item cannot occur in a subset of sum at most . Execute this algorithm independently times and let be the median of its outputs (across the independent runs) for each . Scan with and , and choose one maximizing . If no such exists, return fail. Apply the same procedure to and . If either invocation returns fail, return fail; otherwise, return the union of the two subsets it outputs.
Correctness. For each half, when a majority of the executions of Theorem 4 return the required cardinalities, the medians equal these cardinalities at every sum. When this holds for both halves, the chosen split gives the largest possible cardinality of a subset of I with sum u: every such subset splits between the two halves, and conversely any two subsets with these sums have union of sum u. Induction on therefore proves the asserted output guarantee when this majority condition holds at every recursive split.
Failure probability. Each execution has at least two input items, so its failure probability is at most by Theorem 4. For either half, independence bounds the probability that at least R/2 executions fail by
This bound holds conditioned on all preceding computations. There are at most halves on which we compute the medians. A union bound gives total failure probability at most .
Running time. At a fixed depth of the recursion, let be the number of recursive instances and let and be the size and target of instance . Their index sets are disjoint and their targets sum to at most . Handling the base cases, computing the two AT-LCSS arrays for each remaining instance, and scanning its possible splits take a total time at that depth of
Here and . There are at most depths. The executions per half and the computation of their medians contribute only to the displayed logarithmic factors. Summing over all depths gives total time.
For a nonempty , define
For fixed , evaluating and comparing values of take constant time in our running-time bounds. The following lemma shows that is the minimum value of subject to .
▶ Lemma 25. Fix . For every nonempty , the minimum of over satisfying is . Let minimize over nonempty , and choose any with . For an integer , is 1 if , 0 if , and -1 if . The vector defined by
together with is an optimal solution to , of cost . For a fixed sum , a subset of largest cardinality minimizes .
Proof. Fix a nonempty . Setting for preserves and cannot increase . Writing for , we minimize over integers satisfying . For with , replacing by does not increase , by convexity of . Repeating these operations terminates because strictly decreases. At termination, the integers differ by at most one. Since their sum is , there are copies of and copies of . Thus the minimum of is . The vector
On the Largest Cardinality Subset Sum
satisfies , and the choice of makes optimal for .
For nonempty with and , choose integers , for , satisfying and . Assign these integers to distinct indices of , and assign zero to the remaining indices. Denote the resulting integers by . Then and . Because is the minimum value of among vectors satisfying , we have , proving the largest-cardinality assertion.
We can now compute an optimal solution by choosing a sum and recovering a largest subset with that sum.
▶ Theorem 5. For fixed , given nonnegative integers and an integer , there is a randomized algorithm that outputs an optimal solution to in time , with failure probability at most .
Proof. We first describe the algorithm, prove its correctness, bound its failure probability, and analyze its running time.
Description of the algorithm. Let satisfy . If , set and for , and return . Otherwise, , and we proceed as follows. We solve AT-LCSS on with sum cap using Theorem 4 with , and denote its output by . Let . For each , compute
Choose minimizing , or return fail if is empty. Apply the algorithm of Lemma 24 to with target , using independent randomness. If this algorithm returns fail or an empty subset, return fail. Otherwise, let be its output, construct according to Lemma 25, and return .
Correctness. If , fix a nonempty . Then . Applying Jensen's inequality [21, Appendix B] to the convex function , with weights and , gives
Moreover, since and ,
Consequently,
Thus the singleton is optimal. It remains to consider . We first justify the sum cap .
▷ Claim. There is a nonempty subset minimizing with .
Proof. Fix with and . Choose with . Choose nonnegative integers for , with exactly indices satisfying , and with . By the definitions of , , and ,
Let . Then
If , then , since . Otherwise, . We can therefore choose integers for with . Setting for and for gives a feasible pair . Since ,
For with , the singleton satisfies . Thus no subset minimizing has sum greater than .
Now suppose the algorithm of Theorem 4 returns the required cardinalities. Then consists exactly of the sums at most attainable by nonempty subsets, and is the largest cardinality of a subset of sum for every . Let minimize with , as guaranteed by the claim, and write . For each , is the value of for any largest subset of sum . By Lemma 25, . Hence
If the algorithm of Lemma 24 also returns a largest subset of sum , then . Since minimizes over all nonempty subsets, the inequalities above must be equalities. Thus minimizes , and Lemma 25 guarantees that is feasible and optimal for .
Failure probability. The execution of Theorem 4 fails with probability at most . Conditioned on its successful return and the selected , the independent algorithm of Lemma 24 fails with probability at most 1/6. The total failure probability is therefore at most , since .
Running time. The algorithm of Theorem 4 with sum cap 3t and the algorithm of Lemma 24 with target each take time. Computing for and writing X and S take additional time.
On the Largest Cardinality Subset Sum
6.2 Faster algorithm for Projection Subset Sum on the norm
For , it is in fact enough to find a sum closest to t among sums of nonempty subsets. This allows us to solve in near-linear pseudopolynomial time. First, we recover a subset with that sum using Bringmann's algorithm [4].
▶ Lemma 26. Given nonnegative integers , an attainable integer sum , there is a randomized algorithm that returns a subset with , or fail. It returns fail with probability at most and runs in time .
Proof. We first describe the algorithm, prove its correctness, bound its failure probability, and analyze its running time.
Description of the algorithm. We use Bringmann's algorithm [4, Theorem 1.1]: on positive items with sum cap and error parameter , it outputs only attainable sums at most and omits any fixed attainable sum with probability at most , in time for an input indexed by .
Set and start with and . For , return the empty set. If and , we return when , and fail otherwise. For and , we split with . For each , apply Bringmann's algorithm to with sum cap and error parameter , using randomness independent of all previous executions. Discard items of value zero or greater than before this execution, and let be its output together with 0. If no item remains, set ; if one item remains, compute its subset sums directly. We find with and , returning fail if none exists. Apply the same procedure to and . If either invocation returns fail, return fail; otherwise, return the union of the two subsets it outputs.
Correctness. Since contains only sums of subsets of , every recursive target is attained by a subset of its recursive index set. Induction on shows that the returned set has sum , since and are disjoint.
Failure probability. Conditioned on the recursion history at , fix a subset of sum . Bringmann's algorithm reports both in and in with probability at least , so the split search succeeds with at least this probability. There are at most recursive splits. A union bound over their split searches gives failure probability at most .
Running time. At each depth of the recursion, the recursive index sets are disjoint and their targets sum to at most . Executing Bringmann's algorithm on both halves of each index set and scanning the possible split sums take time per depth. There are depths. Summing over the depths with gives total time.
We now use Lemma 26 to output the modified vector and a set whose modified values sum to t.
▶ Theorem 27. Given nonnegative integers and an integer , there is a randomized algorithm that outputs an optimal solution to in time , with failure probability at most .
Proof. We first describe the algorithm, prove its correctness, bound its failure probability, and analyze its running time.
Description of the algorithm. Let satisfy . If , set and for , and return .
For , proceed as follows. Apply Bringmann's algorithm [4, Theorem 1.1] to the items of with values in , with sum cap and error parameter . If at most one such item exists, compute its subset sums directly. Let be the resulting set of sums together with , delete 0 if , and choose minimizing .
If , set ; otherwise, apply the algorithm of Lemma 26 to with target , using randomness independent of the preceding Bringmann computation. If this algorithm returns fail, return fail; otherwise, let be its output. Choose any , set and for , and return .
Correctness. For , any feasible vector has a nonempty with , so
If , every nonempty has , so is a lower bound on the optimal cost. The returned pair attains this lower bound.
For , fix a sum of a nonempty subset minimizing , independently of the algorithm's randomness. Since and , whereas for , we have . The set is nonempty and contains only sums attained by nonempty subsets. If , the chosen is closest to among sums of nonempty subsets. When the algorithm of Lemma 26 returns a subset of sum , or and , the returned vector and are feasible and have cost . Whenever is closest to among sums of nonempty subsets, this cost attains the lower bound on for every feasible vector .
Failure probability. The probability that is omitted is at most 1/6. For , conditioned on the selected , the independent algorithm of Lemma 26 returns fail with probability at most 1/6. Hence an optimal pair is returned with probability at least 2/3.
Running time. Since , Bringmann's algorithm with sum cap 2t and the algorithm of Lemma 26 with target each take time, and the scan of and construction of and take time.
References
1 Antonis Antonopoulos, Aris Pagourtzis, Stavros Petsalakis, and Manolis Vasilakis. Faster algorithms for k-subset sum and variations. Journal of Combinatorial Optimization, 45(1):24, 2023.
2 Kyriakos Axiotis and Christos Tzamos. Capacitated dynamic programming: Faster knapsack and graph algorithms. arXiv preprint arXiv:1802.06440, 2018.
3 Richard Bellman. Dynamic Programming. Princeton University Press, 1957.
4 Karl Bringmann. A near-linear pseudopolynomial time algorithm for subset sum. In Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 1073–1084. SIAM, 2017.
5 Karl Bringmann. Knapsack with small items in near-quadratic time. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, pages 259–270, 2024.
On the Largest Cardinality Subset Sum
6 Timothy M Chan. Derandomizing pseudopolynomial algorithms for subset sum. In Proceedings of the 2026 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 3600–3610. SIAM, 2026.
7 Timothy M. Chan and Qizheng He. More on change-making and related problems. In 28th Annual European Symposium on Algorithms (ESA 2020), volume 173 of Leibniz International Proceedings in Informatics (LIPics), pages 29:1–29:14, 2020. doi:10.4230/LIPics.ESA.2020.29.
8 Thomas H Cormen, Charles E Leiserson, Ronald Rivest, and Clifford Stein. Algorithmen: eine Einführung. Walter de Gruyter GmbH & Co KG, 2025.
9 Pranjal Dutta and Mahesh Sreekumar Rajasree. Efficient reductions and algorithms for variants of subset sum. arXiv preprint arXiv:2112.11020, 2022.
10 Pranjal Dutta and Mahesh Sreekumar Rajasree. On the variants of subset sum: Projected and unbounded. In 2023 25th International Symposium on Symbolic and Numeric Algorithms for Scientific Computing (SYNASC), pages 86–93. IEEE, 2023.
11 Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman, 1979.
12 Ce Jin. 0-1 knapsack in nearly quadratic time. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, pages 271–282, 2024.
13 Ce Jin and Xiao Mao. Subset Sum in Almost-Linear Time. arXiv preprint arXiv:2610.20742v1, 2026. URL: https://arxiv.org/abs/2610.20742v1.
14 Ce Jin and Hongxun Wu. A simple near-linear pseudopolynomial time randomized algorithm for subset sum. In 2nd Symposium on Simplicity in Algorithms (SOSA 2019), pages 17:1–17:6. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2019. doi:10.4230/OASIcs.SOSA.2019.17.
15 Konstantinos Koiliaris and Chao Xu. Faster pseudopolynomial time algorithms for subset sum. ACM Transactions on Algorithms, 15(3):40:1–40:20, 2019. doi:10.1145/3329863.
16 Eugene L Lawler. Fast approximation algorithms for knapsack problems. Mathematics of operations research, 4(4):339–356, 1979.
17 Andrea Lincoln, Adam Polak, and Virginia Vassilevska Williams. Monochromatic triangles, intermediate matrix products, and convolutions. In ITCS, volume 151 of LIPIcs, pages 53:1–53:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2020.
18 Eran Malach, Gilad Yehudai, Shai Shalev-Schwartz, and Ohad Shamir. Proving the lottery ticket hypothesis: Pruning is all you need. In International conference on machine learning, pages 6682–6691. PMLR, 2020.
19 Ankit Pensia, Shashank Rajput, Alliot Nagle, Harit Vishwakarma, and Dimitris Papailiopoulos. Optimal lottery tickets via subset sum: Logarithmic over-parameterization is sufficient. In Advances in Neural Information Processing Systems, volume 33, pages 2599–2610, 2020.
20 Vivek Ramanujan, Mitchell Wortsman, Aniruddha Kembhavi, Ali Farhadi, and Mohammad Rastegari. What's hidden in a randomly weighted neural network? In 2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pages 11890–11899. IEEE, 2020.
21 Sebastien Roch. Modern discrete probability: An essential toolkit. Cambridge University Press, 2024.
22 Zheyang Xiong, Fangshuo Liao, and Anastasios Kyrillidis. Strong lottery ticket hypothesis with -perturbation. In Proceedings of The 26th International Conference on Artificial Intelligence and Statistics, volume 206, pages 6879–6902. PMLR, 2023.
A Deferred Lemmas and Proofs
A.1 Fast convolution of sets of pairs
For finite sets , we show how to compute their convolution efficiently.
▶ Lemma 28. Let , then can be computed in time .
Proof. Set and represent a pair in either input set by the exponent . We form a polynomial for each set whose coefficients indicate the represented pairs, then compute their product by exact integer convolution (for example, using fast Fourier transform; see [8]). The exponent contributed by a pair is . Since , there is no carry between the coordinates. Thus a coefficient of the product is positive exactly when its exponent represents a pair in . The polynomials and their product have degree , and each coefficient of the product is at most . Exact fast convolution and a scan of the coefficients therefore take time.
A.2 Proof of Lemma 6
We recall Lemma 6 from 2 and prove it.
▶ Lemma 6. Given nonnegative integers , positive integers and , and a parameter , there is a randomized algorithm with one-sided error probability at most that computes the set in time
The returned set is always a subset of .
Proof. The proof follows the generating-function approach of Jin and Wu [14], with an additional variable recording the cardinality. The algorithm computes coefficients modulo a random prime. A zero integer coefficient is never reported as nonzero, but a positive coefficient may vanish modulo the chosen prime. We bound this one-sided error below.
Since the are nonnegative, an index with cannot belong to any subset with , and we henceforth disregard such indices. Let .
For a bivariate formal power series , let
denote the coefficient of the monomial . We also define its -truncation by
Thus, after every polynomial operation, terms of x-degree larger than t or y-degree larger than k may be discarded.
Consider the following bivariate generating function defined by
The subset sum instance has a solution for sum of cardinality if and only if . Formally, we have for every and ,
On the Largest Cardinality Subset Sum
We first explain how to compute these coefficients modulo a prime. Let be a prime, and let denote the residue ring modulo . All computations in the remainder of this paragraph are over . Let
▶ Proposition 29. For prime , in time one can compute .
Proof. The zero-valued items contribute the factor to . Over the rational formal power series, using
we have
For every , let
be the multiplicity of a among the input integers. Truncating (2) gives
Every denominator occurring in (3) satisfies , and is therefore invertible modulo . Hence (3) also unambiguously defines over .
The multiplicities can be computed in time. Moreover, the number of pairs occurring in (3) is at most
Thus all coefficients of can be computed in time.
It remains to recover
We use the divide-and-conquer computation of the exponential formal power series of Jin and Wu [14, Lemma 2]; for completeness, we verify that adding the cardinality variable increases its running time by only a factor k.
▶ Proposition 30. Given a polynomial of degree at most , one can compute in time .
Proof. We write
for the polynomial , where every has degree at most k, and we write
where every is taken modulo . Since has zero -constant term, . Its coefficients , for , are computed in field operations using . The identity
implies, by comparing coefficients of , that for every ,
Since , the integer is invertible in for every , so (4), together with , uniquely determines .
We compute the recurrence (4) by divide and conquer on the index interval , exactly as in the univariate algorithm of Jin and Wu [14, Lemma 2]. We consider one recursive interval , and let
and we suppose that have already been computed. Their total contribution to the right-hand coefficients in (4) is obtained from the product
Indeed, for every , the coefficient of in (5) is
which is exactly the part of the right-hand side of (4) contributed by indices .
We next bound the time needed to compute (5). We suppose the length of the recursive interval is
Both factors in (5) have z-degree and y-degree at most k. Their product, truncated modulo , can be computed in field operations. To see this using only univariate polynomial multiplication, substitute
On the Largest Cardinality Subset Sum
Before truncation, the product of the two factors has -degree at most . Therefore different monomials , with , are mapped to different powers
Hence one multiplication of two univariate polynomials of degree suffices to compute (5), after which the coefficients of -degree larger than are discarded. Fast univariate polynomial multiplication takes time (cf. [14, Lemma 1]).
At every fixed depth of the divide-and-conquer recursion, the recursive intervals are disjoint, and their lengths sum to . Consequently, the total cost of all polynomial multiplications at one recursion depth is . There are recursion depths, and all other operations require at most the same amount of time. Thus
is computed in
time.
▶ Proposition 31. For prime , one can compute for all and in time time.
Proof. Firstly, we use Proposition 29 to compute for all and in time time, and then we use Proposition 30 to compute in time. And, over the rational formal power series, we have
This completes the proof.
It remains only to ensure that reduction modulo does not turn a positive coefficient in (1) into zero. We use the same random-prime argument as Jin and Wu [14, Lemma 3, Theorem 6], with a union bound over all pairs we have the following
▶ Corollary 32. Let where and be a uniform random prime from . Then
By sampling and using Miller-Rabin primality testing [8], we can pick a uniform random prime from interval in polylog( ) time with failure probability. Then the lemma immediately follows from Corollary 32 and Proposition 31.