Lecture 15 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.
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.
We use DFS for exhaustive enumeration. At each node in the decision tree, we branch by: 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, 6, 8, 1] that have a sum between 9 and 10 (inclusive).
[[3, 2, ...], [3, 6, ...]]