Do iterative and recursive versions of an algorithm have the same time complexity?

后端 未结 5 1824
感情败类
感情败类 2020-12-05 20:06

Say, for example, the iterative and recursive versions of the Fibonacci series. Do they have the same time complexity?

5条回答
  •  抹茶落季
    2020-12-05 20:30

    Yes, every iterative algorithm can be transformed into recursive version and vice versa. One way by passing continuations and the other by implementing stack structure. This is done without increase in time complexity.

    If you can optimize tail-recursion then every iterative algorithm can be transformed to recursive one without increasing asymptotic memory complexity.

提交回复
热议问题