For a DP problem, I am using typical memoization using python dictionaries. In the below code, why is memo assuming values when nothing is passed?
Passing by reference understates only the memo is passed by address and not value, but what if there's no 'passing', shouldn't the default override?
my simplified code:
## simple recursive function that adds y recursively
def recurFunc(x,y, memo = {}):
print('Called with x: {}, memo: {}'.format(x,memo))
if x == 1: return y
if x in memo: return memo[x]
memo[x] = y+ recurFunc(x-1,y, memo)
return memo[x]
print(recurFunc(5,1))
#above statement returns 5 as expected
print(recurFunc(6,2))
#above statement returns 7 instead of 12; this is because the memo has older values
A workaround to solve this problem is simple; but want to know what's happening under the hood.