0

Consider a given list of integers and a given target value. By looping over this list, the function tests whether the sum of any subset of the list is equal to the given target value.

Input: 
IntegerList = [1, 3, 4, 6, 11, 33, 12]
TargetValue = 13

Output: 
[3, 4, 6] 

In this case, the function's output reads [3, 4, 6], as these are the values which equal 13.

Many solutions exist to what is called the change-making problem, using Python. See examples here, here, and here. However, these solutions cannot handle my present list, which is roughly 8,000 lines long. It returns the following error:

RecursionError: maximum recursion depth exceeded in comparison

My current recursion depth is 3,000. I attempted to increase the recursion depth and crashed the kernel--folks elsewhere suggested that this was ill-advised anyway.

How can I maximize performance in my code to handle larger lists, such as 8,000 or even 80,000 lines?

martineau
  • 119,623
  • 25
  • 170
  • 301
Dylan Moore
  • 149
  • 9

0 Answers0