Do iterative and recursive versions of an algorithm have the same time complexity?
问题 Say, for example, the iterative and recursive versions of the Fibonacci series. Do they have the same time complexity? 回答1: The answer depends strongly on your implementation. For the example you gave there are several possible solutions and I would say that the naive way to implement a solution has better complexity when implemented iterative. Here are the two implementations: int iterative_fib(int n) { if (n <= 2) { return 1; } int a = 1, b = 1, c; for (int i = 0; i < n - 2; ++i) { c = a +