0

The Bell numbers count the number of partitions of a set. I want to generate all possible partitions of my integer array.

For example, I have the following integer array: {1, 2, 3, 4}. Then there are 15 partitions.

all partitions

Is there any simple way to complete my task? Or what is common algorithm?

Denis
  • 3,595
  • 12
  • 52
  • 86
  • Do you want the number of partitionings or the partitionings themselves? – 5gon12eder Dec 05 '14 at 22:00
  • @5gon12eder, I know number of partitionings. This is a table data. I want to get partitionings themselves. – Denis Dec 05 '14 at 22:02
  • Do you maybe know how to generate all possible (single) subsets, eg. in a recursive function? If you have that, make another level of recursiveness... Subsets and Partitions of the set without the current subset... – deviantfan Dec 05 '14 at 22:03
  • The issue with recursion is that you will get redundant values in your result set. I guess you need to use `std::set` and check at each level of recursion if you already found the partition you're at. – didierc Dec 05 '14 at 22:13
  • https://upload.wikimedia.org/wikipedia/commons/b/b2/Lattice_of_partitions_of_an_order_4_set.svg – didierc Dec 05 '14 at 22:14

0 Answers0