Power Set

8.4 Power Set: Write a method to return all subsets of a set.

  • The power set intuitively represents all the possible subcombinations you can have in given set. In other words, the power set represents all possible combinations for k = 0...n, where n is the length of the set.

  • The power set gross at pow(2, k), where k is the length of the set.

ex.

case 1: {}                            = P(0) (empty set);       2^0 = 1
case 2: {}, {a}                    = P('a');                2^1 = 2
case n: {}, {a}, {b}, {ab}         = P('ab');               2^2 = 4
' ' a 
' ' a b ab 
' ' a b ab c ac bc abc 
' ' a b ab c ac bc abc d ad bd abd cd acd bcd abcd
  • Pascals triangle provides us the amount of combinations per level, for any 'choose'. The growth is exponential.

  • Every additional case feeds on the previous cases by appending a additional unique element to the end of the string.

Last updated

Was this helpful?