Dynamic Programming Fibonacci algorithm

后端 未结 3 877
孤街浪徒
孤街浪徒 2021-01-25 02:40

I\'m working on an algorithm to calculate a Fibonacci number and got the pseudo code for it but I can\'t figure out how much time it takes to run. I think it runs at O(n) but no

3条回答
  •  佛祖请我去吃肉
    2021-01-25 03:02

    Yep. The big giveaway is that you have a constant number of operations per loop and the size of your loop is linear against the size of n.

    A more space-efficient solution exists, however, since you don't particularly care about any numbers other than the last two. Try that next!

提交回复
热议问题