Lecture 15 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. A decision tree for n binary choices has 2^n leaves. We can represent the path to each leaf as a string of 1's (True choice) and 0's (False choice).

Write a recursive function generate_paths(n) that returns a list of strings representing all possible paths in a tree of depth n. The paths should be generated in lexicographical order. For example, for n=2, the output should be ['00', '01', '10', '11']. Do not use additional imports.

Question 2. Suppose we are searching for all subsets of [3, 2, 6, 8, 1] that have a sum between 9 and 10 (inclusive).

We use DFS for exhaustive enumeration. At each node in the decision tree, we branch by:

  1. Including the current number (Left branch)
  2. Excluding the current number (Right branch)

Pruning Rule: If the sum of the numbers currently included exceeds 10, we prune that branch and stop exploring that path immediately.

Identify the successful subsets that reach the target sum of 10 in the order they are discovered by the DFS traversal. Assume we always travel down the left path first. Format your answer as a list of lists, where each inner list contains the numbers included in that specific solution.

Example format: [[3, 2, ...], [3, 6, ...]]