Skip to content

Commit

Permalink
Update 01.Memoization.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed May 14, 2024
1 parent 87d96c7 commit 512ea89
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

举个例子,比如「斐波那契数列」的定义是:$f(0) = 0, f(1) = 1, f(n) = f(n - 1) + f(n - 2)$。如果我们使用递归算法求解第 $n$ 个斐波那契数,则对应的递推过程如下:

![](https://qcdn.itcharge.cn/images/20230308105357.png)
![记忆化搜索](https://qcdn.itcharge.cn/images/20240514110503.png)

从图中可以看出:如果使用普通递归算法,想要计算 $f(5)$,需要先计算 $f(3)$ 和 $f(4)$,而在计算 $f(4)$ 时还需要计算 $f(3)$。这样 $f(3)$ 就进行了多次计算,同理 $f(0)$、$f(1)$、$f(2)$ 都进行了多次计算,从而导致了重复计算问题。

Expand Down

0 comments on commit 512ea89

Please sign in to comment.