Normally, when dealing with combinations, the Big-O complexity seems to be O(n choose k). In this algorithm, I am generating all the combinations within the array that match the target sum:
def combos(candidates,start, target):
if target == 0:
return [[]]
res = []
for i in range(start,len(candidates)):
for c in combos(candidates, i+1, target-candidates[i]):
res.append([candidates[i]]+ c)
return res
print combos([2,1,10,5,6,4], 10)
# [[1, 5, 4], [10], [6, 4]]
I am having a hard time determining Big-O here, is this a O(n choose t)
algorithm? If not, what is it and why?