int f(int n) { if (n <= 1) { return 1; } return f(n - 1) + f(n - 1); }
我知道时间的复杂性是O(2^n),我理解为什么.
O(2^n)
但我不明白为什么空间复杂性O(n).我被告知这是因为在任何给定时间只有n节点,但它对我没有意义.
O(n)
n
c algorithm
algorithm ×1
c ×1