In this paper we give a simple algorithm to generate all partitions of {1,2, ···,n} into k non-empty subsets. The number of such partitions is known as the Stirling number of the second kind. The algorithm generates each partition in constant time without repetition. By choosing k = 1,2, ···, n we can also generate all partitions of {1,2, ···, n} into subsets. The number of such partitions is known as the Bell number.
展开▼
机译:在本文中,我们给出了一个简单的算法,将 {1,2, ····,n} 的所有分区生成为 k 个非空子集。这种分区的数量称为第二种斯特林数。该算法在恒定的时间内生成每个分区,而不会重复。通过选择 k = 1,2, ····, n,我们还可以将 {1,2, ····, n} 的所有分区生成为子集。此类分区的数量称为贝尔数。
展开▼