有些问题直接用recursion来implement会产生exponential time

来源: 2019-06-12 15:50:50 [博客] [旧帖] [给我悄悄话] 本文已被阅读:

complexity。一个很好的例子就是 Fibonacci sequence 的计算。

f(n) = f(n-1) + f(n-2)

f(0) = 0

f(1) = 1

直接 top-down 用 recursion 计算会产生 exponential time complexity。得要 bottom-up 往上堆积才会产生 linear time complexity。