14

I was learning integer partition of a number n into k parts(with minimum 1 in each part) and came across this recurrence :

part(n,k) = part(n-1,k-1) + part(n-k,k)

But, I cannot understand the logic behind this recurrence. Can someone please help me visualize this recurrence?

  • 3
    Those partitions where at least one part has size exactly $1$ plus those partitions where each part has size strictly greater than $1$. – Nate Aug 30 '16 at 17:03
  • 3
    Following up on what @Nate said: If a partition of $n$ into $k$ parts has at least one part with size $1$, then this part can be dropped to give a partition of $n-1$ into $k-1$ parts. If all parts are at least size $2$, however, one can decrement each part by $1$ to get a partition of $n-k$ into $k$ parts. – Semiclassical Aug 30 '16 at 17:06
  • how does decrementing each part by 1 help? How is this recurrence able to count all unique combinations correctly? – rahulkhairwar Aug 30 '16 at 17:47
  • 1
    Hi! Just wanted to say that the relation is wrong. It should be (,)=(,−1)+(−,) – lotus57 Aug 27 '22 at 11:03

3 Answers3

18

$p(n,k)$ is the number of ways to partition $n$ into $k$ parts. It is the same as the number of different ways of placing $n$ objects into $k$ pots. Firstly put $1$ object in each pot. Total $k$ objects have been put and now we have to put remaining $n-k$ objects into $k$ pots. Hence, $$ p(n,k)=p(n-k,1)+p(n-k,2)+\cdots+p(n-k,k-1)+p(n-k,k)$$ Also observe that, $$ p(n-1,k-1)=p(n-k,1)+p(n-k,2)+\cdots+p(n-k,k-1)$$ From the above two equations, we conclude: $$p(n,k)=p(n-1,k-1)+p(n-k,k)$$

Jiri Kriz
  • 2,117
15

Let's consider an example: $n=8$ and $k=3$:

\begin{align*} \\ P(n,k)&=P(n-1,k-1)+P(n-k,k)&\\ \\ P(8,3)&=P(7,2)+P(5,3)&\\ \\ 5\quad&=\quad3\qquad+\quad2 \end{align*}

$$ $$

\begin{array}{rlrlrl} &P(8,3)\qquad=&& P(7,2)\qquad\qquad+&&P(5,3)\\ \hline\\ 8&=\color{red}{6+1}+1\qquad& 7&=6+1\\ &=\color{red}{5+2}+1\qquad&&=5+2\\ &=\color{red}{4+3}+1\qquad&&=4+3\\ &=\color{blue}{4+2+2}\qquad&&\qquad &\qquad5&=3+1+1\\ &=\color{blue}{3+3+2}\qquad&&\qquad&\qquad&=2+2+1 \end{array}

Note that the partitions of $P(8,3)$ that have smallest integer part equal to one correspond to the integer partitions of $P(7,2)$ whereas the partitions with smallest integer part $>1$ correspond to the partitions of $P(5,3)$: \begin{align*} 4+2+2=(3+1+1)+3\\ 3+3+2=(2+2+1)+3 \end{align*}

Markus Scheuer
  • 112,413
6

I like to think of it as 'counting partitions with a certain property'...

We split the partitions $p(n,k)$ into $2$ disjoint classes that together comprise $p(n,k)$. So if we can count each class, then we've counted $p(n,k)$.

Let class $A$ contains all the partitions of $n$ into $k$ parts where at least $1$ of the partition elements is a $1$. So these all look like $1 +$ stuff.

The rest, class $B$, don't have any $1$ elements. These partitions could look like almost anything, but you won't find a $1$ in there anywhere. There are still $k$ parts that add to $n$.

It should be clear that these two classes are disjoint and taken together comprise all the partitions of $n$ into $k$ parts.

So if we count class $A$ and class $B$ we've counted all the partitions and we'll have our answer $p(n,k)$, so let's do that ...

Look at class $A$. We already noticed every partition in class $A$ looks like $1 +$ stuff. Well, the sum of stuff is $n-1$. How many pieces are in stuff? They all have $k-1$ pieces. There are no other restrictions on stuff, but then stuff is just all the partitions of $n-1$ into $k-1$ parts. So the count of class $A$ is $p(n-1,k-1)$.

Now look at class $B$. The sum of the parts is still $n$. There are $k$ parts, but each part is $\geq 2$. That means we can subtract $1$ from each part, but then the sum is $n-k$. Each part is now $\geq 1$, but that's just the definition of the partition of $n-k$ into $k$ parts. So the count of class $B$ is $p(n-k,k)$.

That's it.

dave i.
  • 61