Lecture 16 Finger Exercise

The questions below are due on Friday May 08, 2026; 11:59:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

Question 1. In class, we had examined how to generate all possible combinations out of a collection of n items. Our output was a list of sets – in particular, 2^n sets – which formed the power set of the original collection.

An alternate way to represent a combination of items is to use a binary string of 0's and 1's. For instance, if we have four items [1, 2, 3, 4] in that order, then the binary string "0110" corresponds to selecting 2 and 3 but not 1 and 4, hence the subset {2, 3}.

Implement a function powerset_binary_str(n) that returns a list of binary strings representing all possible subsets of a set of size n. The strings should be listed in lexicographical order. For example, when n = 2, the output should be ["00", "01", "10", "11"].

Question 2. Suppose we are searching for all subsets of [3, 2, 6, 8, 1] whose elements sum to either 9 or 10. Consider the decision tree structure we demonstrated in lecture for exhaustive enumeration. At each node in the decision tree, our options are to:
  1. exclude the current number (left branch),
  2. include the current number (right branch).

Trace through by hand the DFS-style traversal of the decision tree, and list the subsets that reach the target sums of 9 or 10 in the order they would be discovered. Assume we always travel down the left path first.

Specify your answer as a list of sets, where each inner set is a valid subset of the original list. Example format:

[{3, 6, ...}, {3, 2, ...}, ...]

Note: You may choose to perform pruning as we did in lecture. However, pruning should not affect the order in which you discover valid solutions.