Search

Search papers and lessons

Set Partition

Level 1 · 10 min read

A partition splits a set into nonempty groups that do not overlap and leave nothing out, so every element belongs to exactly one group.

On this page

  • Colour = topic mix
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A partition of a set cuts it into smaller sets, called blocks, so that every element lands in exactly one block and no block is empty. It is the exact version of the everyday idea of sorting things into groups with no leftovers and no doubles. Partitions appear wherever each item must belong to exactly one group, from clustering data to dividing voters into districts.

Builds on: Set Operations · Leads to: Mathematical Relation, K-Means Clustering

Where it's used

Hard clustering in machine learning. K-means clustering assigns each data point to exactly one of k clusters. Its output is therefore a partition of the data points: a point cannot sit in two clusters at once, and every point is placed somewhere. Hierarchical clustering produces a nested sequence of partitions, one for each cut of its tree of merges.

Electoral districts. In a country that elects one representative per district, each voter lives in exactly one constituency. The districts, taken together, form a partition of the electorate. A voter in two districts, or in none, would break the rule that every vote counts once.

Splitting numbers into equal halves. The partition problem asks whether a list of numbers can be split into two groups with equal sums. For the list 3, 1, 1, 2, 2, 1 the answer is yes: the groups 3 and 2 sum to 5, and 1, 1, 2, 1 also sum to 5. The problem is a standard hard task in computer science: no fast general method is known for it, and it is one of the problems shown to be NP-complete. Any solution is a partition of the list into two groups.

How it works

Take the set {1,2,3}\{1, 2, 3\} and list every way to split it into groups. Place the elements one at a time, and at each step either join an existing group or start a new one.

  1. Start with three items. The set is {1,2,3}\{1, 2, 3\}, and every final grouping must use each of the three exactly once. Check: there are three items to place.
  2. Place item 1. It has nowhere else to go, so it starts a group: [1][1]. Check: the group is not empty.
  3. Place item 2. There are two choices. It can join the group holding 1, giving [1 2][1\ 2], or start a new group [2][2]. Check: in both cases 2 sits in exactly one group.
  4. Place item 3. Each arrangement from step 3 offers the same choice. From [1 2][1\ 2], item 3 joins the group to give [1 2 3][1\ 2\ 3], or starts a new group to give [1 2] [3][1\ 2]\ [3]. From [1] [2][1]\ [2], item 3 joins the group of 1, joins the group of 2, or starts a new group, giving [1 3] [2][1\ 3]\ [2], [1] [2 3][1]\ [2\ 3] and [1] [2] [3][1]\ [2]\ [3]. Check: the tree below has five leaves.
  5. Read off the answer. The five arrangements are all the ways to split three items into nonempty, non-overlapping groups that leave nothing out. Check: no arrangement is repeated, because each one came from a different sequence of choices.
  6. Name the idea. Each arrangement is a set partition. A three-element set has five of them.
flowchart TD
  A["Place 1: group [1]"] --> B["Place 2 in [1]: group [1 2]"]
  A --> C["Place 2 new: groups [1] [2]"]
  B --> D["Place 3 in [1 2]: [1 2 3]"]
  B --> E["Place 3 new: [1 2] [3]"]
  C --> F["Place 3 with 1: [1 3] [2]"]
  C --> G["Place 3 with 2: [1] [2 3]"]
  C --> H["Place 3 new: [1] [2] [3]"]

The math

Definition: Set partition

A partition of a set SS is a collection of sets B1,…,BkB_1, \dots, B_k, called blocks, such that every block is nonempty, the blocks cover SS, and no element lies in two blocks.

Here SS is the set being split, and BiB_i is the block with number ii. The symbols come from set operations: ∪\cup means union (everything in either set), ∩\cap means intersection (what two sets share), and ∅\emptyset is the empty set, with nothing in it.

Step 2 in symbols: a block is nonempty

Placing item 1 gives the block B1={1}B_1 = \{1\}. It is a valid block because {1}≠∅\{1\} \neq \emptyset.

Step 5 in symbols: cover and disjoint

Take the arrangement B1={1,2}B_1 = \{1, 2\} and B2={3}B_2 = \{3\}. It is a partition of S={1,2,3}S = \{1, 2, 3\} for two reasons.

  • Cover: the union is {1,2}∪{3}={1,2,3}=S\{1, 2\} \cup \{3\} = \{1, 2, 3\} = S, so every element is in some block.
  • Disjoint: the intersection is {1,2}∩{3}=∅\{1, 2\} \cap \{3\} = \emptyset, so no element is in two blocks.

The arrangement {1,2}\{1, 2\} and {2,3}\{2, 3\} fails the second test. Its intersection is {2}\{2\}, which is not empty, so element 2 is in two blocks.

Step 6 in symbols: counting partitions

Write Bell⁡(n)\operatorname{Bell}(n) for the number of partitions of a set with nn elements; these are the Bell numbers. The walkthrough shows Bell⁡(3)=5\operatorname{Bell}(3) = 5.

Worked examples

Example
1. Tiny: a two-element set
  1. Take S={a,b}S = \{a, b\}.
  2. One block: {a,b}\{a, b\}. The block is nonempty and covers SS. Valid.
  3. Two blocks: {a}\{a\} and {b}\{b\}. They are nonempty, cover SS, and do not overlap. Valid.
  4. No other arrangement works, since any split must use one block or two.
  5. Check: Bell⁡(2)=2\operatorname{Bell}(2) = 2, matching the two partitions found.

Interpretation: a two-element set has exactly two partitions, one that keeps everything together and one that separates the elements.

Example
2. Standard: all partitions of a four-element set

Count the partitions of {1,2,3,4}\{1, 2, 3, 4\} by the sizes of their blocks, using the tools from Counting Principles.

  1. One block of size 4: {1,2,3,4}\{1, 2, 3, 4\}. That is 1 partition.
  2. Blocks of sizes 3 and 1: choose which element stands alone, 4 ways. That is 4 partitions.
  3. Blocks of sizes 2 and 2: pair element 1 with one of the other three, 3 ways. The remaining two form the other block. That is 3 partitions, for example {1,3}\{1, 3\} with {2,4}\{2, 4\}.
  4. Blocks of sizes 2, 1 and 1: choose the pair, (42)=6\binom{4}{2} = 6 ways. That is 6 partitions.
  5. Four blocks of size 1: {1},{2},{3},{4}\{1\}, \{2\}, \{3\}, \{4\}. That is 1 partition.
  6. Add the counts: 1+4+3+6+1=151 + 4 + 3 + 6 + 1 = 15.
  7. Check: Bell⁡(4)=15\operatorname{Bell}(4) = 15, the same total.

Interpretation: sorting by the shape of the blocks gives a complete count with no double counting, because each partition has exactly one shape.

Example
3. Realistic: checking a clustering

A clustering algorithm such as k-means groups six data points, p1p_1 to p6p_6, into two clusters. Its first output is A={p1,p2,p4}A = \{p_1, p_2, p_4\} and B={p3,p5,p6}B = \{p_3, p_5, p_6\}.

  1. Check that every point is covered: p1,p2,p4p_1, p_2, p_4 are in AA, and p3,p5,p6p_3, p_5, p_6 are in BB. All six appear.
  2. Check that no point is in both clusters: A∩B=∅A \cap B = \emptyset.
  3. Check that neither cluster is empty.
  4. Conclusion: the output is a partition of the six points.

Now a buggy output: A={p1,p2,p4}A = \{p_1, p_2, p_4\} and B={p3,p4,p5,p6}B = \{p_3, p_4, p_5, p_6\}. Point p4p_4 was assigned twice. Its intersection A∩B={p4}A \cap B = \{p_4\} is not empty, so this is not a partition.

Interpretation: a clustering that assigns points to one cluster each is a partition, so a double assignment is a bug that the disjointness test catches.

Try it: is {p1,p2}\{p_1, p_2\}, {p3}\{p_3\}, {p4,p5}\{p_4, p_5\} a partition of the six points? Answer: No. Point p6p_6 is in no block, so the blocks do not cover the set, even though they are nonempty and do not overlap.

Common mistakes and tradeoffs

It is tempting to think a partition is any collection of subsets. In fact the blocks must be nonempty, must cover the whole set, and must not overlap. The collection {1,2}\{1, 2\}, {2,3}\{2, 3\} is not a partition of {1,2,3}\{1, 2, 3\}, because element 2 sits in two blocks.

It is tempting to think the order of the blocks matters. In fact a partition is an unordered collection. The listings {1,2},{3}\{1, 2\}, \{3\} and {3},{1,2}\{3\}, \{1, 2\} describe the same partition.

It is tempting to think a partition is just a kind of subset. In fact subsets may overlap or leave elements out, while a partition may do neither. A four-element set has 16 subsets, including the empty one, but only 15 partitions. The Power Set is the family of all subsets; partitions are a stricter family.

StructureOverlap allowed?Leftovers allowed?Empty group allowed?
Partitionnonono
Coveryesnono
Any subset collectionyesyesyes

When to use a partition: when each item must belong to exactly one group, as in hard clustering or district maps. When not to use it: when items may belong to several groups, as with topic tags, where a cover or a soft assignment fits better. Alternatives: a cover allows overlap. A labelling is a Function from items to group names, and the items sharing a name form a block; requiring every name to be used is the same as requiring the labelling to be surjective, which is the nonempty-block condition.

History

Set theory, which gives partitions their notation, was developed by Georg Cantor in the 1870s and 1880s. Counting partitions came later: the Bell numbers are named after Eric Temple Bell, who studied them in the 1930s. In 1972 Richard Karp showed that the partition problem is NP-complete, which made it a standard example of a hard problem in computer science.

Recap

  • A partition splits a set into nonempty blocks that do not overlap and leave nothing out.
  • Build the partitions of a set by placing its elements one at a time, either joining an existing block or starting a new one.
  • The number of partitions of a three-element set is 5, and of a four-element set is 15.
  • Overlap, leftovers, or an empty block each rule a collection out as a partition.
  • Read next: Mathematical Relation, where an equivalence relation is a relation whose groups form a partition, and Counting Principles for the counting tools used above.

Check yourself

QuestionRecall: what three conditions must a collection of sets meet to be a partition of a set S?Show answer
Every block is nonempty, the blocks cover S so that every element is in some block, and the blocks are disjoint so that no element is in two blocks.
QuestionComputation: how many ways are there to split {1,2,3,4}\{1, 2, 3, 4\} into one block of size 3 and one block of size 1?Show answer
There are 4 ways. Choose the element that stands alone; each of the four choices gives a different partition, and the block of size 3 is then fixed.
QuestionWhy: why does the order in which the blocks are listed not change the partition?Show answer
A partition is defined by which elements share a block, not by any order among the blocks. A collection of sets has no order, so {1,2},{3}\{1, 2\}, \{3\} and {3},{1,2}\{3\}, \{1, 2\} are the same partition.
QuestionApplied: a school assigns each student to a homeroom, and each homeroom must have at least one student. When is the set of homerooms a partition of the students, and how could it fail?Show answer
It is a partition when every student is in exactly one homeroom and no homeroom is empty. It fails if a student is in no homeroom, which breaks the cover condition, if a student is in two homerooms, which breaks disjointness, or if a homeroom is empty, which breaks the nonempty condition.

Sources