Reducibility
Glossary Contents
← Ch XIX
Chapter XX Partition
Ch XXI →
  1. 58 — Two equal piles
  2. 59 — DP and Karmarkar–Karp in OCaml
  3. 60 — Load balancing across racks
Chapter XX

Partition

Split a multiset of integers into two subsets with equal sums. Knapsack's special case, surprisingly hard, surprisingly close to easy.

58

Two equal piles

Sum the lot, divide by two, find a subset that hits exactly that target.

Partition asks whether a multiset of positive integers can be split into two equal-sum halves:

∃S⊆{1,…,n} : i∈S∑​ai​=i∈/S∑​ai​.(1)

Equivalently, (1) holds iff some subset sums to exactly half the total. NP-complete (Karp); the standard subset-sum DP solves it in pseudo-polynomial time

O(n⋅Σ),Σ=i∑​ai​.(2)

Karmarkar-Karp's differencing heuristic gives strong approximate answers. On random inputs near the phase transition — the regime where instances are most often unsolvable — exact algorithms struggle while differencing usually finds optimal partitions. Partition is the textbook reduction source for many other NP-complete problems, including job sequencing, bin packing, and 3-partition.

Figures, in plain terms
(1)

∃ is the exists quantifier — read as "there exists" or "is there a." It asserts that at least one example satisfies what follows.

S ⊆ {1, ..., n} picks a subset of the n indices.

The colon : separates "what we're looking for" from "the property it must satisfy."

After the colon, the property: Σ over i ∈ S of a_i = Σ over i ∉ S of a_i. Two big-sums — one over indices in S, one over indices not in S (the ∉ is "is not in"). The equality demands these sums match.

Reassembled: is there a subset whose sum equals the sum of everything left over? Equivalently, both halves equal half the total.

(2)

Same shape as the knapsack runtime — pseudo-polynomial. n is the count of integers; Σ here stands in for the total sum (the script-Σ on the right of the comma).

So O(n · Σ) is fast when the sums fit comfortably in memory (e.g., total ~10⁶), and intractable when sums are astronomical (10¹⁸+).

The DP solving this just builds a length-(Σ/2 + 1) array of "is this exact sum reachable?" and walks each integer in turn.

In plain terms

Split a stack of coins into two piles of equal value. Sounds easy — but for arbitrary integer values, no fast algorithm is known.

Scan to come back to page 58

← 57 Avionics task scheduling
1/3 · 58/63
59 DP and Karmarkar–Karp in OCaml →