Lecture 16 Finger Exercise
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.
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 Implement a function [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}.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"].
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: 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.[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:
[{3, 6, ...}, {3, 2, ...}, ...]