Skip to main content

Integer Partition

Definition​

The Integer Partition Algorithm aims to find all possible ways to partition a given integer into a sum of positive integers. It's a fundamental problem in combinatorics and dynamic programming, often used in various fields like number theory and computer science

Practice​

integerPartition(n):
partitions = 2D array of size (n+1) x (n+1) filled with 0s
for i from 0 to n:
partitions[i][1] = 1
for i from 1 to n:
for j from 1 to n:
if j > i:
partitions[i][j] = partitions[i][i]
else:
partitions[i][j] = partitions[i][j-1] + partitions[i-j][j]
return partitions[n][n]