HOME

TheInfoList



OR:

In number theory and computer science, the partition problem, or number partitioning, is the task of deciding whether a given
multiset In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that, unlike a set, allows for multiple instances for each of its elements. The number of instances given for each element is called the multiplicity of that ...
''S'' of positive integers can be partitioned into two subsets ''S''1 and ''S''2 such that the sum of the numbers in ''S''1 equals the sum of the numbers in ''S''2. Although the partition problem is NP-complete, there is a
pseudo-polynomial time In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is a polynomial in the ''numeric value'' of the input (the largest integer present in the input)—but not necessarily in the ''length'' of th ...
dynamic programming Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. ...
solution, and there are
heuristics A heuristic (; ), or heuristic technique, is any approach to problem solving or self-discovery that employs a practical method that is not guaranteed to be optimal, perfect, or rational, but is nevertheless sufficient for reaching an immediate, ...
that solve the problem in many instances, either optimally or approximately. For this reason, it has been called "the easiest hard problem". There is an optimization version of the partition problem, which is to partition the multiset ''S'' into two subsets ''S''1, ''S''2 such that the difference between the sum of elements in ''S''1 and the sum of elements in ''S''2 is minimized. The optimization version is NP-hard, but can be solved efficiently in practice. The partition problem is a special case of two related problems: * In the
subset sum problem The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S of integers and a target-sum T, and the question is to decide whether any subset of the integers sum to precisely T''.'' T ...
, the goal is to find a subset of ''S'' whose sum is a certain target number ''T'' given as input (the partition problem is the special case in which ''T'' is half the sum of ''S''). * In
multiway number partitioning In computer science, multiway number partitioning is the problem of partitioning a multiset of numbers into a fixed number of subsets, such that the sums of the subsets are as similar as possible. It was first presented by Ronald Graham in 1969 in t ...
, there is an integer parameter ''k'', and the goal is to decide whether ''S'' can be partitioned into ''k'' subsets of equal sum (the partition problem is the special case in which ''k'' = 2). *However, it is quite different than the 3-partition problem: in that problem, the number of subsets is not fixed in advance – it should be , ''S'', /3, where each subset must have exactly 3 elements. 3-partition is much harder than partition – it has no pseudo-polynomial time algorithm unless
P = NP The P versus NP problem is a major unsolved problem in theoretical computer science. In informal terms, it asks whether every problem whose solution can be quickly verified can also be quickly solved. The informal term ''quickly'', used abov ...
.


Examples

Given ''S'' = , a valid solution to the partition problem is the two sets ''S''1 = and ''S''2 = . Both sets sum to 5, and they partition ''S''. Note that this solution is not unique. ''S''1 = and ''S''2 = is another solution. Not every
multiset In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that, unlike a set, allows for multiple instances for each of its elements. The number of instances given for each element is called the multiplicity of that ...
of positive integers has a partition into two subsets with equal sum. An example of such a set is ''S'' = .


Computational hardness

The partition problem is NP hard. This can be proved by reduction from the
subset sum problem The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S of integers and a target-sum T, and the question is to decide whether any subset of the integers sum to precisely T''.'' T ...
. An instance of SubsetSum consists of a set ''S'' of positive integers and a target sum ''T''; the goal is to decide if there is a subset of ''S'' with sum exactly ''T''. Given such an instance, construct an instance of Partition in which the input set contains the original set plus two elements: ''z''1 and ''z''2, with ''z''1 = sum(S) and ''z''2 = 2''T''. The sum of this input set is sum(''S'') + ''z''1 + ''z''2 = 2 sum(''S'') + 2''T'', so the target sum for Partition is sum(''S'') + ''T''. * Suppose there exists a solution ''S''′ to the SubsetSum instance. Then sum(''S''′) = ''T'', so sum(''S''′ ''u'' ) = sum(''S'') + ''T'', so ''S''′ ''u''  is a solution to the Partition instance. * Conversely, suppose there exists a solution ''S''′′ to the Partition instance. Then, ''S''′′ must contain either ''z''1 or ''z''2, but not both, since their sum is more than sum(''S'') + ''T''. If S'' contains ''z''1, then it must contain elements from S with a sum of exactly ''T'', so S'' minus ''z''1 is a solution to the SubsetSum instance. If S'' contains ''z''2, then it must contain elements from S with a sum of exactly sum(''S'') − ''T'', so the other objects in ''S'' are a solution to the SubsetSum instance.


Approximation algorithms

As mentioned above, the partition problem is a special case of multiway-partitioning and of subset-sum. Therefore, it can be solved by algorithms developed for each of these problems. Algorithms developed for
multiway number partitioning In computer science, multiway number partitioning is the problem of partitioning a multiset of numbers into a fixed number of subsets, such that the sums of the subsets are as similar as possible. It was first presented by Ronald Graham in 1969 in t ...
include: *
Greedy number partitioning In computer science, greedy number partitioning is a class of greedy algorithms for multiway number partitioning. The input to the algorithm is a set ''S'' of numbers, and a parameter ''k''. The required output is a partition of ''S'' into ''k'' su ...
– loops over the numbers, and puts each number in the set whose current sum is smallest. If the numbers are not sorted, then the runtime is O(''n'') and the approximation ratio is at most 3/2 ("approximation ratio" means the larger sum in the algorithm output, divided by the larger sum in an optimal partition). Sorting the numbers increases the runtime to O(''n'' log ''n'') and improves the approximation ratio to 7/6. If the numbers are distributed uniformly in ,1 then the approximation ratio is at most 1 + O\left(\frac\right)
almost surely In probability theory, an event is said to happen almost surely (sometimes abbreviated as a.s.) if it happens with probability 1 (or Lebesgue measure 1). In other words, the set of possible exceptions may be non-empty, but it has probability 0. ...
, and 1 + O\left(\frac\right) in expectation. * Largest Differencing Method (also called the Karmarkar–Karp algorithm) sorts the numbers in descending order and repeatedly replaces numbers by their differences. The runtime complexity is O(''n'' log ''n''). In the worst case, its approximation ratio is similar – at most 7/6. However, in the average case it performs much better than the greedy algorithm: when numbers are distributed uniformly in ,1 its approximation ratio is at most 1 + 1/n^ in expectation. It also performs better in simulation experiments. * The Multifit algorithm uses binary search combined with an algorithm for
bin packing The bin packing problem is an optimization problem, in which items of different sizes must be packed into a finite number of bins or containers, each of a fixed given capacity, in a way that minimizes the number of bins used. The problem has ma ...
. In the worst case, its approximation ratio is 8/7. *The
subset sum problem The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S of integers and a target-sum T, and the question is to decide whether any subset of the integers sum to precisely T''.'' T ...
has an FPTAS which can be used for the partition problem as well, by setting the target sum to sum(''S'')/2.


Exact algorithms

There are exact algorithms, that always find the optimal partition. Since the problem is NP-hard, such algorithms might take exponential time in general, but may be practically usable in certain cases. Algorithms developed for
multiway number partitioning In computer science, multiway number partitioning is the problem of partitioning a multiset of numbers into a fixed number of subsets, such that the sums of the subsets are as similar as possible. It was first presented by Ronald Graham in 1969 in t ...
include: * The
pseudopolynomial time number partitioning In computer science, pseudopolynomial time number partitioning is a pseudopolynomial time algorithm for solving the partition problem. The problem can be solved using dynamic programming when the size of the set and the size of the sum of the inte ...
takes O(n m) memory, where is the largest number in the input. * The Complete Greedy Algorithm (CGA) considers all partitions by constructing a
binary tree In computer science, a binary tree is a k-ary k = 2 tree data structure in which each node has at most two children, which are referred to as the ' and the '. A recursive definition using just set theory notions is that a (non-empty) binary tr ...
. Each level in the tree corresponds to an input number, where the root corresponds to the largest number, the level below to the next-largest number, etc. Each branch corresponds to a different set in which the current number can be put. Traversing the tree in
depth-first Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible alon ...
order requires only O(n) space, but might take O(2^n) time. The runtime can be improved by using a greedy heuristic: in each level, develop first the branch in which the current number is put in the set with the smallest sum. This algorithm finds first the solution found by
greedy number partitioning In computer science, greedy number partitioning is a class of greedy algorithms for multiway number partitioning. The input to the algorithm is a set ''S'' of numbers, and a parameter ''k''. The required output is a partition of ''S'' into ''k'' su ...
, but then proceeds to look for better solutions. Some variations of this idea ''are'' fully polynomial-time approximation schemes for the subset-sum problem, and hence for the partition problem as well. * The Complete Karmarkar-Karp algorithm (CKK) considers all partitions by constructing a binary tree. Each level corresponds to a pair of numbers. The left branch corresponds to putting them in different subsets (i.e., replacing them by their difference), and the right branch corresponds to putting them in the same subset (i.e., replacing them by their sum). This algorithm finds first the solution found by the
largest differencing method In computer science, the largest differencing method is an algorithm for solving the partition problem and the multiway number partitioning. It is also called the Karmarkar–Karp algorithm after its inventors, Narendra Karmarkar and Richard M. Kar ...
, but then proceeds to find better solutions. It runs substantially faster than CGA on random instances. Its advantage is much larger when an equal partition exists, and can be of several orders of magnitude. In practice, problems of arbitrary size can be solved by CKK if the numbers have at most 12
significant digits Significant figures (also known as the significant digits, ''precision'' or ''resolution'') of a number in positional notation are digits in the number that are reliable and necessary to indicate the quantity of something. If a number expres ...
. CKK can also run as an
anytime algorithm In computer science, an anytime algorithm is an algorithm that can return a valid solution to a problem even if it is interrupted before it ends. The algorithm is expected to find better and better solutions the longer it keeps running. Most algo ...
: it finds the KK solution first, and then finds progressively better solutions as time allows (possibly requiring exponential time to reach optimality, for the worst instances). It requires O(n) space, but in the worst case might take O(2^n) time. Algorithms developed for
subset sum The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S of integers and a target-sum T, and the question is to decide whether any subset of the integers sum to precisely T''.'' ...
include: * Horowitz and Sanhi – runs in time O( 2^\cdot (n/2)), but requires O( 2^) space. * Schroeppel and Shamir – runs in time O( 2^\cdot (n/4)), and requires much less space – O(2^). * Howgrave-Graham and Joux – runs in time O(2^), but it is a randomized algorithm that only solves the decision problem (not the optimization problem).


Hard instances and phase-transition

Sets with only one, or no partitions tend to be hardest (or most expensive) to solve compared to their input sizes. When the values are small compared to the size of the set, perfect partitions are more likely. The problem is known to undergo a " phase transition"; being likely for some sets and unlikely for others. If m is the number of bits needed to express any number in the set and n is the size of the set then m/n < 1 tends to have many solutions and m/n > 1 tends to have few or no solutions. As n and m get larger, the probability of a perfect partition goes to 1 or 0 respectively. This was originally argued based on empirical evidence by Gent and Walsh, then using methods from statistical physics by Mertens, and later proved by Borgs, Chayes, and Pittel.


Probabilistic version

A related problem, somewhat similar to the
Birthday paradox In probability theory, the birthday problem asks for the probability that, in a set of randomly chosen people, at least two will share a birthday. The birthday paradox is that, counterintuitively, the probability of a shared birthday exceeds ...
, is that of determining the size of the input set so that we have a probability of one half that there is a solution, under the assumption that each element in the set is randomly selected with uniform distribution between 1 and some given value. The solution to this problem can be counter-intuitive, like the birthday paradox.


Variants and generalizations

Equal-cardinality partition is a variant in which both parts should have an equal number of items, in addition to having an equal sum. This variant is NP-hard too. ''Proof''. Given a standard Partition instance with some ''n'' numbers, construct an Equal-Cardinality-Partition instance by adding ''n'' zeros. Clearly, the new instance has an equal-cardinality equal-sum partition iff the original instance has an equal-sum partition. See also Balanced number partitioning. Distinct partition is a variant in which all input integers are distinct. This variant is NP-hard too. Product partition is the problem of partitioning a set of integers into two sets with the same ''product'' (rather than the same sum). This problem is strongly NP-hard. Kovalyov and Pesch discuss a generic approach to proving NP-hardness of partition-type problems.


Applications

One application of the partition problem is for manipulation of
elections An election is a formal group decision-making process by which a population chooses an individual or multiple individuals to hold public office. Elections have been the usual mechanism by which modern representative democracy has operated ...
. Suppose there are three candidates (A, B and C). A single candidate should be elected using a voting rule based on scoring, e.g. the veto rule (each voter vetoes a single candidate and the candidate with the fewest vetoes wins). If a coalition wants to ensure that C is elected, they should partition their votes among A and B so as to maximize the smallest number of vetoes each of them gets. If the votes are weighted, then the problem can be reduced to the partition problem, and thus it can be solved efficiently using CKK. The same is true for any other voting rule that is based on scoring.


Notes


References

* * * * * * * *{{cite arXiv , last = Mertens , first = Stephan , title = A complete anytime algorithm for balanced number partitioning, pages = , year = 1999 , eprint = cs/9903011 , mode = cs2 Number partitioning Weakly NP-complete problems