Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
Monday, December 5, 2011
Generate all the subsets of a given set
This could be tricky unless you realize that given an set of size n there are 2^n subsets. An element can be in or out, so 0/1 and this means that you just need to generate all the binary numbers from 0 to n. The binary representation of each number will tell you whether or not you need to include the element (bit i = 1 means element in).