+ 1
What is the best algorithm for getting all subsets of a given set of elements ?
S = {1,2,4,6} ans: {} {1,4} {2,4,6} etcâŠ
1 Answer
+ 1
Heap's or SteinhausâJohnsonâTrotter are the normal ones. Heap's has the most examples floating around. Memoizing will allow speedup. if you can do it in parallel as well (likely in combination with some in-memory storage table) that'll speed it up again. Note the very nature of the problem means the size extrapolates, it gets huge very quickly with longer starting lists.