- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I am looking at the following example of Memoized Dynamic Programming algorithm.
Could you explain me why we check if $n$ is in memo although memo is a set that contains the values of $F[n]$ and not of $n$? (Thinking)
I am looking at the following example of Memoized Dynamic Programming algorithm.
Code:
memo={}
Fib(n):
if n in memo return memo[n]
if n<=2 F[n]=1
else F[n]=F[n-1]+F[n-2]
memo[n]=F[n]
return F[n]
Could you explain me why we check if $n$ is in memo although memo is a set that contains the values of $F[n]$ and not of $n$? (Thinking)