Introduction to Dynamic Programming
Introduction to Dynamic Programming
复制标题
DOI:
10.2307/1907500
复制
发表时间:
2022
期刊:
影响因子:
--
通讯作者:
Manel Baucells;Sasa Zorc
中科院分区:
文献类型:
--
作者:
Manel Baucells;Sasa Zorc
Already, fib(5) is being called and recomputed 3 different times. To speed up our naive solution, we can employ DP by computing fib() for each value up to n=10 and storing it for future use. One way we can implement this is to slightly modify our original recursive function to check a table to see if we’ve already computed that specific Fibonacci number. If we have, we use it, otherwise we compute and then store it. This is the top-down approach(also called memoization) because start from the overall problem and recurse down until we reach the smallest subproblems (the base cases).