On this page, you will learn how to generalize the ice cream solution to list the subsets of any set.
Given a set of things, a subset contains zero or more of its elements, without duplicates. As was true for ice cream bowls, order doesn't matter.
For example, given the set {Apple, Orange, Banana} there are one-element subsets like {Banana} and two-element subsets like {Apple, Banana}. The original set {Apple, Orange, Banana} counts, and so does the empty set {} with zero elements.
subsets
block that takes a list as input and reports a list of lists in which each item is a subset of the original input list. The order in which the subsets appear in the output list doesn't matter, but each subset must appear exactly once. The result might look like this:If you're stuck after trying as many ideas as you can think of, click here for some help.
subsets
report in the base case? This is a hard part to get right!MF: Scrap. Fold into the Subsets OP at the end.
If we keep this image anywhere (the image behind the hint), it needs to be rebuilt. --MF, 4/22/22
Here is one solution for the subsets
block.
This solution for subsets
makes the same recursive call twice, an inefficiency that can be corrected.
count
variable to count how many recursive calls are made to find the 64 subsets of a six-element list.