Why is my recursive function so slow in R?

前端 未结 7 2041
栀梦
栀梦 2020-12-02 23:51

The following takes about 30 seconds to run whereas I would expect it to be nearly instant. Is there a problem with my code?

x <- fibonacci(35);

fibonac         


        
7条回答
  •  不知归路
    2020-12-03 00:16

    Because you are using one of the worst algorithms in the world!

    Complexity of which is O(fibonacci(n)) = O((golden ratio)^n) and golden ratio is 1.6180339887498948482…

提交回复
热议问题